Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cae5948

Browse files
author
Dave Rochwerger
committed
Merge branch 'draft-20'
Conflicts: lib/OAuth2.php
2 parents 93d93cc + dc12dfb commit cae5948

23 files changed

+1536
-814
lines changed

lib/IOAuth2GrantClient.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Storage engines that support the "Client Credentials"
4+
* grant type should implement this interface
5+
*
6+
* @author Dave Rochwerger <[email protected]>
7+
* @see http://tools.ietf.org/html/draft-ietf-oauth-v2-20#section-4.4
8+
*/
9+
interface IOAuth2GrantClient extends IOAuth2Storage {
10+
11+
/**
12+
* Required for OAuth2::GRANT_TYPE_CLIENT_CREDENTIALS.
13+
*
14+
* @param $client_id
15+
* Client identifier to be check with.
16+
* @param $client_secret
17+
* (optional) If a secret is required, check that they've given the right one.
18+
*
19+
* @return
20+
* TRUE if the client credentials are valid, and MUST return FALSE if it isn't.
21+
* When using "client credentials" grant mechanism and you want to
22+
* verify the scope of a user's access, return an associative array
23+
* with the scope values as below. We'll check the scope you provide
24+
* against the requested scope before providing an access token:
25+
* @code
26+
* return array(
27+
* 'scope' => <stored scope values (space-separated string)>,
28+
* );
29+
* @endcode
30+
*
31+
* @see http://tools.ietf.org/html/draft-ietf-oauth-v2-20#section-4.4.2
32+
*
33+
* @ingroup oauth2_section_4
34+
*/
35+
public function checkClientCredentialsGrant($client_id, $client_secret);
36+
}

lib/IOAuth2GrantCode.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* Storage engines that support the "Authorization Code"
4+
* grant type should implement this interface
5+
*
6+
* @author Dave Rochwerger <[email protected]>
7+
* @see http://tools.ietf.org/html/draft-ietf-oauth-v2-20#section-4.1
8+
*/
9+
interface IOAuth2GrantCode extends IOAuth2Storage {
10+
11+
/**
12+
* The Authorization Code grant type supports a response type of "code".
13+
*
14+
* @var string
15+
* @see http://tools.ietf.org/html/draft-ietf-oauth-v2-20#section-1.4.1
16+
* @see http://tools.ietf.org/html/draft-ietf-oauth-v2-20#section-4.2
17+
*/
18+
const RESPONSE_TYPE_CODE = OAuth2::RESPONSE_TYPE_AUTH_CODE;
19+
20+
/**
21+
* Fetch authorization code data (probably the most common grant type).
22+
*
23+
* Retrieve the stored data for the given authorization code.
24+
*
25+
* Required for OAuth2::GRANT_TYPE_AUTH_CODE.
26+
*
27+
* @param $code
28+
* Authorization code to be check with.
29+
*
30+
* @return
31+
* An associative array as below, and NULL if the code is invalid:
32+
* - client_id: Stored client identifier.
33+
* - redirect_uri: Stored redirect URI.
34+
* - expires: Stored expiration in unix timestamp.
35+
* - scope: (optional) Stored scope values in space-separated string.
36+
*
37+
* @see http://tools.ietf.org/html/draft-ietf-oauth-v2-20#section-4.1
38+
*
39+
* @ingroup oauth2_section_4
40+
*/
41+
public function getAuthCode($code);
42+
43+
/**
44+
* Take the provided authorization code values and store them somewhere.
45+
*
46+
* This function should be the storage counterpart to getAuthCode().
47+
*
48+
* If storage fails for some reason, we're not currently checking for
49+
* any sort of success/failure, so you should bail out of the script
50+
* and provide a descriptive fail message.
51+
*
52+
* Required for OAuth2::GRANT_TYPE_AUTH_CODE.
53+
*
54+
* @param $code
55+
* Authorization code to be stored.
56+
* @param $client_id
57+
* Client identifier to be stored.
58+
* @param $user_id
59+
* User identifier to be stored.
60+
* @param $redirect_uri
61+
* Redirect URI to be stored.
62+
* @param $expires
63+
* Expiration to be stored.
64+
* @param $scope
65+
* (optional) Scopes to be stored in space-separated string.
66+
*
67+
* @ingroup oauth2_section_4
68+
*/
69+
public function setAuthCode($code, $client_id, $user_id, $redirect_uri, $expires, $scope = NULL);
70+
71+
}

lib/IOAuth2GrantExtension.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Storage engines that support the "Extensible"
4+
* grant types should implement this interface
5+
*
6+
* @author Dave Rochwerger <[email protected]>
7+
* @see http://tools.ietf.org/html/draft-ietf-oauth-v2-20#section-4.5
8+
*/
9+
interface IOAuth2GrantExtension extends IOAuth2Storage {
10+
11+
/**
12+
* Check any extended grant types.
13+
*
14+
* @param string $uri
15+
* URI of the grant type definition
16+
* @param array $inputData
17+
* Unfiltered input data. The source is *not* guaranteed to be POST (but
18+
* is likely to be).
19+
* @param array $authHeaders
20+
* Authorization headers
21+
* @return
22+
* FALSE if the authorization is rejected or not support.
23+
* TRUE or an associative array if you wantto verify the scope:
24+
* @code
25+
* return array(
26+
* 'scope' => <stored scope values (space-separated string)>,
27+
* );
28+
* @endcode
29+
*
30+
* @see http://tools.ietf.org/html/draft-ietf-oauth-v2-20#section-1.4.5
31+
* @see http://tools.ietf.org/html/draft-ietf-oauth-v2-20#section-4.2
32+
*/
33+
public function checkGrantExtension($uri, array $inputData, array $authHeaders);
34+
}

lib/IOAuth2GrantImplicit.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* Storage engines that support the "Implicit"
4+
* grant type should implement this interface
5+
*
6+
* @author Dave Rochwerger <[email protected]>
7+
* @see http://tools.ietf.org/html/draft-ietf-oauth-v2-20#section-4.2
8+
*/
9+
interface IOAuth2GrantImplicit extends IOAuth2Storage {
10+
11+
/**
12+
* The Implicit grant type supports a response type of "token".
13+
*
14+
* @var string
15+
* @see http://tools.ietf.org/html/draft-ietf-oauth-v2-20#section-1.4.2
16+
* @see http://tools.ietf.org/html/draft-ietf-oauth-v2-20#section-4.2
17+
*/
18+
const RESPONSE_TYPE_TOKEN = OAuth2::RESPONSE_TYPE_ACCESS_TOKEN;
19+
}

lib/IOAuth2GrantUser.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Storage engines that support the "Resource Owner Password Credentials"
4+
* grant type should implement this interface
5+
*
6+
* @author Dave Rochwerger <[email protected]>
7+
* @see http://tools.ietf.org/html/draft-ietf-oauth-v2-20#section-4.3
8+
*/
9+
interface IOAuth2GrantUser extends IOAuth2Storage {
10+
11+
/**
12+
* Grant access tokens for basic user credentials.
13+
*
14+
* Check the supplied username and password for validity.
15+
*
16+
* You can also use the $client_id param to do any checks required based
17+
* on a client, if you need that.
18+
*
19+
* Required for OAuth2::GRANT_TYPE_USER_CREDENTIALS.
20+
*
21+
* @param $client_id
22+
* Client identifier to be check with.
23+
* @param $username
24+
* Username to be check with.
25+
* @param $password
26+
* Password to be check with.
27+
*
28+
* @return
29+
* TRUE if the username and password are valid, and FALSE if it isn't.
30+
* Moreover, if the username and password are valid, and you want to
31+
* verify the scope of a user's access, return an associative array
32+
* with the scope values as below. We'll check the scope you provide
33+
* against the requested scope before providing an access token:
34+
* @code
35+
* return array(
36+
* 'scope' => <stored scope values (space-separated string)>,
37+
* );
38+
* @endcode
39+
*
40+
* @see http://tools.ietf.org/html/draft-ietf-oauth-v2-20#section-4.3
41+
*
42+
* @ingroup oauth2_section_4
43+
*/
44+
public function checkUserCredentials($client_id, $username, $password);
45+
}

lib/IOAuth2RefreshTokens.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* Storage engines that want to support refresh tokens should
4+
* implement this interface.
5+
*
6+
* @author Dave Rochwerger <[email protected]>
7+
* @see http://tools.ietf.org/html/draft-ietf-oauth-v2-20#section-6
8+
* @see http://tools.ietf.org/html/draft-ietf-oauth-v2-20#section-1.5
9+
*/
10+
interface IOAuth2RefreshTokens extends IOAuth2Storage {
11+
12+
/**
13+
* Grant refresh access tokens.
14+
*
15+
* Retrieve the stored data for the given refresh token.
16+
*
17+
* Required for OAuth2::GRANT_TYPE_REFRESH_TOKEN.
18+
*
19+
* @param $refresh_token
20+
* Refresh token to be check with.
21+
*
22+
* @return
23+
* An associative array as below, and NULL if the refresh_token is
24+
* invalid:
25+
* - client_id: Stored client identifier.
26+
* - expires: Stored expiration unix timestamp.
27+
* - scope: (optional) Stored scope values in space-separated string.
28+
*
29+
* @see http://tools.ietf.org/html/draft-ietf-oauth-v2-20#section-6
30+
*
31+
* @ingroup oauth2_section_6
32+
*/
33+
public function getRefreshToken($refresh_token);
34+
35+
/**
36+
* Take the provided refresh token values and store them somewhere.
37+
*
38+
* This function should be the storage counterpart to getRefreshToken().
39+
*
40+
* If storage fails for some reason, we're not currently checking for
41+
* any sort of success/failure, so you should bail out of the script
42+
* and provide a descriptive fail message.
43+
*
44+
* Required for OAuth2::GRANT_TYPE_REFRESH_TOKEN.
45+
*
46+
* @param $refresh_token
47+
* Refresh token to be stored.
48+
* @param $client_id
49+
* Client identifier to be stored.
50+
* @param $expires
51+
* expires to be stored.
52+
* @param $scope
53+
* (optional) Scopes to be stored in space-separated string.
54+
*
55+
* @ingroup oauth2_section_6
56+
*/
57+
public function setRefreshToken($refresh_token, $client_id, $user_id, $expires, $scope = NULL);
58+
59+
/**
60+
* Expire a used refresh token.
61+
*
62+
* This is not explicitly required in the spec, but is almost implied.
63+
* After granting a new refresh token, the old one is no longer useful and
64+
* so should be forcibly expired in the data store so it can't be used again.
65+
*
66+
* If storage fails for some reason, we're not currently checking for
67+
* any sort of success/failure, so you should bail out of the script
68+
* and provide a descriptive fail message.
69+
*
70+
* @param $refresh_token
71+
* Refresh token to be expirse.
72+
*
73+
* @ingroup oauth2_section_6
74+
*/
75+
public function unsetRefreshToken($refresh_token);
76+
}

0 commit comments

Comments
 (0)