Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simplesamlphp
Manage
Activity
Members
Labels
Plan
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Perun
Perun ProxyIdP
v1
simplesamlphp
Commits
aa8fa58f
Unverified
Commit
aa8fa58f
authored
May 11, 2018
by
Tim van Dijen
Committed by
GitHub
May 11, 2018
Browse files
Options
Downloads
Patches
Plain Diff
PSR-2
; no functional changes
parent
4dc98dfb
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/oauth/lib/OAuthStore.php
+163
-142
163 additions, 142 deletions
modules/oauth/lib/OAuthStore.php
with
163 additions
and
142 deletions
modules/oauth/lib/OAuthStore.php
+
163
−
142
View file @
aa8fa58f
...
...
@@ -11,8 +11,8 @@ require_once(dirname(dirname(__FILE__)) . '/libextinc/OAuth.php');
* @author Mark Dobrinic, <mdobrinic@cozmanova.com>, Cozmanova bv
* @package SimpleSAMLphp
*/
class
sspmod_oauth_OAuthStore
extends
OAuthDataStore
{
class
sspmod_oauth_OAuthStore
extends
OAuthDataStore
{
private
$store
;
private
$config
;
private
$defaultversion
=
'1.0'
;
...
...
@@ -26,7 +26,8 @@ class sspmod_oauth_OAuthStore extends OAuthDataStore {
'request'
=>
'requestToken.key+consumerKey = requesttoken'
,
);
function
__construct
()
{
public
function
__construct
()
{
$this
->
store
=
new
sspmod_core_Storage_SQLPermanentStorage
(
'oauth'
);
$this
->
config
=
SimpleSAML_Configuration
::
getOptionalConfig
(
'module_oauth.php'
);
}
...
...
@@ -38,11 +39,13 @@ class sspmod_oauth_OAuthStore extends OAuthDataStore {
* @param $data Data that is authorized and to be attached to the requestToken
* @return array(string:url, string:verifier) ; empty verifier for 1.0-response
*/
public
function
authorize
(
$requestTokenKey
,
$data
)
{
public
function
authorize
(
$requestTokenKey
,
$data
)
{
$url
=
null
;
// See whether to remember values from the original requestToken request:
$request_attributes
=
$this
->
store
->
get
(
'requesttorequest'
,
$requestTokenKey
,
''
);
// must be there ..
$request_attributes
=
$this
->
store
->
get
(
'requesttorequest'
,
$requestTokenKey
,
''
);
// must be there ..
if
(
$request_attributes
[
'value'
])
{
// establish callback to use
if
(
$request_attributes
[
'value'
][
'callback'
])
{
...
...
@@ -54,7 +57,9 @@ class sspmod_oauth_OAuthStore extends OAuthDataStore {
// Is there a callback registered? This is leading, even over a supplied oauth_callback-parameter
$oConsumer
=
$this
->
lookup_consumer
(
$request_attributes
[
'value'
][
'consumerKey'
]);
if
(
$oConsumer
&&
(
$oConsumer
->
callback_url
))
$url
=
$oConsumer
->
callback_url
;
if
(
$oConsumer
&&
(
$oConsumer
->
callback_url
))
{
$url
=
$oConsumer
->
callback_url
;
}
$verifier
=
SimpleSAML\Utils\Random
::
generateID
();
$url
=
\SimpleSAML\Utils\HTTP
::
addURLParameters
(
$url
,
array
(
"oauth_verifier"
=>
$verifier
));
...
...
@@ -72,18 +77,21 @@ class sspmod_oauth_OAuthStore extends OAuthDataStore {
* @param $verifier
* @return unknown_type
*/
public
function
isAuthorized
(
$requestToken
,
$verifier
=
''
)
{
public
function
isAuthorized
(
$requestToken
,
$verifier
=
''
)
{
SimpleSAML\Logger
::
info
(
'OAuth isAuthorized('
.
$requestToken
.
')'
);
return
$this
->
store
->
exists
(
'authorized'
,
$requestToken
,
$verifier
);
}
public
function
getAuthorizedData
(
$token
,
$verifier
=
''
)
{
public
function
getAuthorizedData
(
$token
,
$verifier
=
''
)
{
SimpleSAML\Logger
::
info
(
'OAuth getAuthorizedData('
.
$token
.
')'
);
$data
=
$this
->
store
->
get
(
'authorized'
,
$token
,
$verifier
);
return
$data
[
'value'
];
}
public
function
moveAuthorizedData
(
$requestToken
,
$verifier
,
$accessTokenKey
)
{
public
function
moveAuthorizedData
(
$requestToken
,
$verifier
,
$accessTokenKey
)
{
SimpleSAML\Logger
::
info
(
'OAuth moveAuthorizedData('
.
$requestToken
.
', '
.
$accessTokenKey
.
')'
);
// Retrieve authorizedData from authorized.requestToken (with provider verifier)
...
...
@@ -97,13 +105,18 @@ class sspmod_oauth_OAuthStore extends OAuthDataStore {
$this
->
store
->
set
(
'authorized'
,
$accessTokenKey
,
''
,
$authorizedData
,
$this
->
config
->
getValue
(
'accessTokenDuration'
,
60
*
60
*
24
));
}
public
function
lookup_consumer
(
$consumer_key
)
{
public
function
lookup_consumer
(
$consumer_key
)
{
SimpleSAML\Logger
::
info
(
'OAuth lookup_consumer('
.
$consumer_key
.
')'
);
if
(
!
$this
->
store
->
exists
(
'consumers'
,
$consumer_key
,
''
))
return
NULL
;
if
(
!
$this
->
store
->
exists
(
'consumers'
,
$consumer_key
,
''
))
{
return
null
;
}
$consumer
=
$this
->
store
->
get
(
'consumers'
,
$consumer_key
,
''
);
$callback
=
NULL
;
if
(
$consumer
[
'value'
][
'callback_url'
])
$callback
=
$consumer
[
'value'
][
'callback_url'
];
$callback
=
null
;
if
(
$consumer
[
'value'
][
'callback_url'
])
{
$callback
=
$consumer
[
'value'
][
'callback_url'
];
}
if
(
$consumer
[
'value'
][
'RSAcertificate'
])
{
return
new
OAuthConsumer
(
$consumer
[
'value'
][
'key'
],
$consumer
[
'value'
][
'RSAcertificate'
],
$callback
);
...
...
@@ -112,21 +125,28 @@ class sspmod_oauth_OAuthStore extends OAuthDataStore {
}
}
function
lookup_token
(
$consumer
,
$tokenType
=
'default'
,
$token
)
{
function
lookup_token
(
$consumer
,
$tokenType
=
'default'
,
$token
)
{
SimpleSAML\Logger
::
info
(
'OAuth lookup_token('
.
$consumer
->
key
.
', '
.
$tokenType
.
','
.
$token
.
')'
);
$data
=
$this
->
store
->
get
(
$tokenType
,
$token
,
$consumer
->
key
);
if
(
$data
==
NULL
)
throw
new
Exception
(
'Could not find token'
);
if
(
$data
==
null
)
{
throw
new
Exception
(
'Could not find token'
);
}
return
$data
[
'value'
];
}
function
lookup_nonce
(
$consumer
,
$token
,
$nonce
,
$timestamp
)
{
function
lookup_nonce
(
$consumer
,
$token
,
$nonce
,
$timestamp
)
{
SimpleSAML\Logger
::
info
(
'OAuth lookup_nonce('
.
$consumer
.
', '
.
$token
.
','
.
$nonce
.
')'
);
if
(
$this
->
store
->
exists
(
'nonce'
,
$nonce
,
$consumer
->
key
))
return
TRUE
;
if
(
$this
->
store
->
exists
(
'nonce'
,
$nonce
,
$consumer
->
key
))
{
return
true
;
}
$this
->
store
->
set
(
'nonce'
,
$nonce
,
$consumer
->
key
,
TRUE
,
$this
->
config
->
getValue
(
'nonceCache'
,
60
*
60
*
24
*
14
));
return
FALSE
;
return
false
;
}
function
new_request_token
(
$consumer
,
$callback
=
null
,
$version
=
null
)
{
function
new_request_token
(
$consumer
,
$callback
=
null
,
$version
=
null
)
{
SimpleSAML\Logger
::
info
(
'OAuth new_request_token('
.
$consumer
.
')'
);
$lifetime
=
$this
->
config
->
getValue
(
'requestTokenDuration'
,
60
*
30
);
...
...
@@ -149,7 +169,8 @@ class sspmod_oauth_OAuthStore extends OAuthDataStore {
return
$token
;
}
function
new_access_token
(
$requestToken
,
$consumer
,
$verifier
=
null
)
{
function
new_access_token
(
$requestToken
,
$consumer
,
$verifier
=
null
)
{
SimpleSAML\Logger
::
info
(
'OAuth new_access_token('
.
$requestToken
.
','
.
$consumer
.
')'
);
$accesstoken
=
new
OAuthToken
(
SimpleSAML\Utils\Random
::
generateID
(),
SimpleSAML\Utils\Random
::
generateID
());
$this
->
store
->
set
(
'access'
,
$accesstoken
->
key
,
$consumer
->
key
,
$accesstoken
,
$this
->
config
->
getValue
(
'accessTokenDuration'
,
60
*
60
*
24
)
);
...
...
@@ -161,20 +182,20 @@ class sspmod_oauth_OAuthStore extends OAuthDataStore {
* @param $requestTokenKey
* @return unknown_type
*/
public
function
lookup_consumer_by_requestToken
(
$requestTokenKey
)
{
public
function
lookup_consumer_by_requestToken
(
$requestTokenKey
)
{
SimpleSAML\Logger
::
info
(
'OAuth lookup_consumer_by_requestToken('
.
$requestTokenKey
.
')'
);
if
(
!
$this
->
store
->
exists
(
'requesttorequest'
,
$requestTokenKey
,
''
))
return
NULL
;
if
(
!
$this
->
store
->
exists
(
'requesttorequest'
,
$requestTokenKey
,
''
))
{
return
null
;
}
$request
=
$this
->
store
->
get
(
'requesttorequest'
,
$requestTokenKey
,
''
);
$consumerKey
=
$request
[
'value'
][
'consumerKey'
];
if
(
!
$consumerKey
)
{
return
NULL
;
return
null
;
}
$consumer
=
$this
->
store
->
get
(
'consumers'
,
$consumerKey
[
'value'
],
''
);
return
$consumer
[
'value'
];
}
}
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