Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nextcloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Nextcloud
Commits
a8c82440
Commit
a8c82440
authored
12 years ago
by
Tom Needham
Browse files
Options
Downloads
Patches
Plain Diff
API: Use http authentication, check the auth level required
parent
8b409dfe
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/api.php
+22
-19
22 additions, 19 deletions
lib/api.php
with
22 additions
and
19 deletions
lib/api.php
+
22
−
19
View file @
a8c82440
...
@@ -86,7 +86,7 @@ class OC_API {
...
@@ -86,7 +86,7 @@ class OC_API {
foreach
(
self
::
$actions
[
$name
]
as
$action
){
foreach
(
self
::
$actions
[
$name
]
as
$action
){
$app
=
$action
[
'app'
];
$app
=
$action
[
'app'
];
// Authorsie this call
// Authorsie this call
if
(
$this
->
isAuthorised
(
$action
)){
if
(
self
::
isAuthorised
(
$action
)){
if
(
is_callable
(
$action
[
'action'
])){
if
(
is_callable
(
$action
[
'action'
])){
$responses
[]
=
array
(
'app'
=>
$app
,
'response'
=>
call_user_func
(
$action
[
'action'
],
$parameters
));
$responses
[]
=
array
(
'app'
=>
$app
,
'response'
=>
call_user_func
(
$action
[
'action'
],
$parameters
));
}
else
{
}
else
{
...
@@ -105,7 +105,7 @@ class OC_API {
...
@@ -105,7 +105,7 @@ class OC_API {
}
else
{
}
else
{
self
::
respond
(
$response
);
self
::
respond
(
$response
);
}
}
// logout the user to be stateles
// logout the user to be stateles
s
OC_User
::
logout
();
OC_User
::
logout
();
}
}
...
@@ -114,7 +114,7 @@ class OC_API {
...
@@ -114,7 +114,7 @@ class OC_API {
* @param array $action the action details as supplied to OC_API::register()
* @param array $action the action details as supplied to OC_API::register()
* @return bool
* @return bool
*/
*/
private
function
isAuthorised
(
$action
){
private
static
function
isAuthorised
(
$action
){
$level
=
$action
[
'authlevel'
];
$level
=
$action
[
'authlevel'
];
switch
(
$level
){
switch
(
$level
){
case
OC_API
::
GUEST_AUTH
:
case
OC_API
::
GUEST_AUTH
:
...
@@ -123,13 +123,25 @@ class OC_API {
...
@@ -123,13 +123,25 @@ class OC_API {
break
;
break
;
case
OC_API
::
USER_AUTH
:
case
OC_API
::
USER_AUTH
:
// User required
// User required
// Check url for username and password
return
self
::
loginUser
();
break
;
break
;
case
OC_API
::
SUBADMIN_AUTH
:
case
OC_API
::
SUBADMIN_AUTH
:
// Check for subadmin
// Check for subadmin
$user
=
self
::
loginUser
();
if
(
!
$user
){
return
false
;
}
else
{
return
OC_SubAdmin
::
isSubAdmin
(
$user
);
}
break
;
break
;
case
OC_API
::
ADMIN_AUTH
:
case
OC_API
::
ADMIN_AUTH
:
// Check for admin
// Check for admin
$user
=
self
::
loginUser
();
if
(
!
$user
){
return
false
;
}
else
{
return
OC_Group
::
inGroup
(
$user
,
'admin'
);
}
break
;
break
;
default
:
default
:
// oops looks like invalid level supplied
// oops looks like invalid level supplied
...
@@ -139,11 +151,13 @@ class OC_API {
...
@@ -139,11 +151,13 @@ class OC_API {
}
}
/**
/**
*
gets login details from url and logs in the user
*
http basic auth
* @return
bool
* @return
string|false (username, or false on failure)
*/
*/
public
function
loginUser
(){
private
static
function
loginUser
(){
// Todo
$authuser
=
isset
(
$_SERVER
[
'PHP_AUTH_USER'
])
?
$_SERVER
[
'PHP_AUTH_USER'
]
:
''
;
$authpw
=
isset
(
$_SERVER
[
'PHP_AUTH_PW'
])
?
$_SERVER
[
'PHP_AUTH_PW'
]
:
''
;
return
OC_User
::
login
(
$authuser
,
$authpw
)
?
$authuser
:
false
;
}
}
/**
/**
...
@@ -222,17 +236,6 @@ class OC_API {
...
@@ -222,17 +236,6 @@ class OC_API {
$writer
->
writeElement
(
$k
,
$v
);
$writer
->
writeElement
(
$k
,
$v
);
}
}
}
}
}
/**
* check if the user is authenticated
*/
public
static
function
checkLoggedIn
(){
// Check OAuth
if
(
!
OC_OAuth_Server
::
isAuthorised
()){
OC_Response
::
setStatus
(
401
);
die
();
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment