Toggle navigation
Toggle navigation
This project
Loading...
Sign in
UT
/
oauth_2-0_client_php
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Vyacheslav Slinko
2011-09-02 12:41:42 +0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4da0b508101562917731daf8df4247db27c725de
4da0b508
1 parent
1016186f
Some oauth2 servers doesn't recognize Authorization header
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
22 deletions
oauth2.php
oauth2.php
View file @
4da0b50
...
...
@@ -27,6 +27,9 @@
class
OAuth2_Service_Configuration
{
const
AUTHORIZATION_METHOD_HEADER
=
1
;
const
AUTHORIZATION_METHOD_ALTERNATIVE
=
2
;
/**
* @var string
*/
...
...
@@ -40,7 +43,7 @@ class OAuth2_Service_Configuration
/**
* @var string
*/
private
$_
useOnlyAuthorizationHeader
=
true
;
private
$_
authorizationMethod
=
self
::
AUTHORIZATION_METHOD_HEADER
;
/**
* @param string $authorizeEndpoint
...
...
@@ -68,15 +71,15 @@ class OAuth2_Service_Configuration
/**
* @return string
*/
public
function
set
UseOnlyAuthorizationHeader
(
$useOnlyAuthorizationHeader
)
{
$this
->
_
useOnlyAuthorizationHeader
=
$useOnlyAuthorizationHeader
;
public
function
set
AuthorizationMethod
(
$authorizationMethod
)
{
$this
->
_
authorizationMethod
=
$authorizationMethod
;
}
/**
* @return string
*/
public
function
get
UseOnlyAuthorizationHeader
()
{
return
$this
->
_
useOnlyAuthorizationHeader
;
public
function
get
AuthorizationMethod
()
{
return
$this
->
_
authorizationMethod
;
}
}
...
...
@@ -267,23 +270,26 @@ class OAuth2_Service
$parameters
=
null
;
if
(
!
$this
->
_configuration
->
getUseOnlyAuthorizationHeader
()){
/*
http://tools.ietf.org/html/draft-ietf-oauth-v2-10#section-5.1
Clients SHOULD only use the request URI or body when the
"Authorization" request header field is not available, and MUST NOT
use more than one method in each request.only one method should be used as per the Draft.
Allow to override correct behavior for misimplemented servers
*/
if
(
$method
!==
'GET'
)
{
if
(
is_array
(
$postBody
))
{
$postBody
[
'oauth_token'
]
=
$token
->
getAccessToken
();
$authorizationMethod
=
$this
->
_configuration
->
getAuthorizationMethod
();
switch
(
$authorizationMethod
)
{
case
OAuth2_Service_Configuration
::
AUTHORIZATION_METHOD_HEADER
:
$additionalHeaders
=
array_merge
(
array
(
'Authorization: OAuth '
.
$token
->
getAccessToken
()),
$additionalHeaders
);
break
;
case
OAuth2_Service_Configuration
::
AUTHORIZATION_METHOD_ALTERNATIVE
:
if
(
$method
!==
'GET'
)
{
if
(
is_array
(
$postBody
))
{
$postBody
[
'oauth_token'
]
=
$token
->
getAccessToken
();
}
else
{
$postBody
.=
'&oauth_token='
.
urlencode
(
$token
->
getAccessToken
());
}
}
else
{
$
postBody
.=
'&oauth_token='
.
urlencode
(
$token
->
getAccessToken
()
);
$
uriParameters
[
'oauth_token'
]
=
$token
->
getAccessToken
(
);
}
}
else
{
$uriParameters
[
'oauth_token'
]
=
$token
->
getAccessToken
();
}
break
;
default
:
throw
new
OAuth2_Exception
(
"Invalid authorization method specified"
);
break
;
}
if
(
$method
!==
'GET'
)
{
...
...
@@ -298,9 +304,8 @@ class OAuth2_Service
$endpoint
.=
(
strpos
(
$endpoint
,
'?'
)
!==
false
?
'&'
:
'?'
)
.
http_build_query
(
$uriParameters
);
}
$headers
=
array_merge
(
array
(
'Authorization: OAuth '
.
$token
->
getAccessToken
()),
$additionalHeaders
);
$http
=
new
OAuth2_HttpClient
(
$endpoint
,
$method
,
$parameters
,
$
h
eaders
);
$http
=
new
OAuth2_HttpClient
(
$endpoint
,
$method
,
$parameters
,
$
additionalH
eaders
);
$http
->
execute
();
return
$http
->
getResponse
();
...
...
Please
register
or
login
to post a comment