Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

oauth_token.php
Go to the documentation of this file.
1 <?php
18 class ezpRestOauthTokenController extends ezcMvcController
19 {
27 public function doHandleRequest()
28 {
29 // Check that the correct params are present
30 // Params for token endpoint per section 4
31 // REQUIRED: grant_type, client_id, client_secret
32 // OPTIONAL: scope
33 //
34 // Supported grant types are: authorization_code and refresh_token
35 //
36 // Additional params for 'authorization_code', Section 4.1.1
37 // REQUIRED: code, redirect_uri
38 //
39 // Additional param for 'refresh_token", Section 4.1.4
40 // REQUIRED: refresh_token
41
42 // Defining the required params for each stage of operation
43 $initialRequiredParams = array( 'grant_type', 'client_id', 'client_secret' );
44
45 // params for grant_type=authorization_code
46 $codeRequiredParams = array( 'code', 'redirect_uri' );
47
48 // params for grant_type=refresh_token
49 $refreshRequiredParams = array( 'refresh_token' );
50
51 $this->checkParams( $initialRequiredParams );
52
53 // We can get the first set of required params
54 $grant_type = $this->request->post['grant_type'];
55 $client_id = $this->request->post['client_id'];
56 $client_secret = $this->request->post['client_secret'];
57 $tokenTTL = (int)eZINI::instance( 'rest.ini' )->variable( 'OAuthSettings', 'TokenTTL' );
58
59 if ( !$this->validateGrantType( $grant_type ) )
60 {
61 throw new ezpOauthInvalidRequestException( ezpOauthTokenEndpointErrorType::UNSUPPORTED_GRANT_TYPE );
62 }
63
64 $result = new ezcMvcResult();
65 $newToken = null;
66
67 switch ( $grant_type )
68 {
69 case 'authorization_code':
70 $this->checkParams( $codeRequiredParams );
71 $newToken = ezpOauthUtility::doRefreshTokenWithAuthorizationCode( $client_id, $client_secret, $this->request->post['code'], $this->request->post['redirect_uri']);
72 break;
73
74 case 'refresh_token':
75 $this->checkParams( $refreshRequiredParams );
76 $newToken = ezpOauthUtility::doRefreshToken( $client_id, $client_secret, $this->request->post['refresh_token'] );
77 break;
78 }
79
80 if ( !$newToken instanceof ezpRestToken )
81 {
82 throw new ezpOauthInvalidTokenException( ezpOauthTokenEndpointErrorType::INVALID_REQUEST );
83 }
84
85 $result->variables['access_token'] = $newToken->id;
86 $result->variables['refresh_token'] = $newToken->refresh_token;
87 $result->variables['expires_in'] = $tokenTTL;
88 return $result;
89 }
90
91 protected function validateClient( $client_id, $client_secret )
92 {
93
94 }
95
96 protected function checkParams( $paramsToCheck )
97 {
98 foreach( $paramsToCheck as $param )
99 {
100 $missingParams = array();
101 if ( !isset( $this->request->post[$param] ) )
102 {
103 $missingParams[] = $param;
104 }
105 }
106 // For now bail out on first missing param, as spec does not yet specify
107 // how to specify multiple missing params simultaneously.
108
109 if ( !empty( $missingParams ))
110 {
111 $error = array_pop( $missingParams );
112
113 throw new ezpOauthInvalidRequestException( "Missing {$error} parameter." );
114 }
115
116 }
117
118 protected function validateGrantType( $grant )
119 {
120 $allowedGrantTypes = array( 'authorization_code',
121 'refresh_token',
122 );
123
124
125 return in_array( $grant, $allowedGrantTypes );
126 }
127 }
$tokenTTL
if(! $application->isAuthorizedByUser( $pScope, eZUser::currentUser())) $tokenTTL
Definition: authorize.php:137
ezpOauthInvalidRequestException
Definition: invalid_request.php:22
ezpOauthInvalidTokenException
Definition: invalid_token.php:20
ezpOauthTokenEndpointErrorType\UNSUPPORTED_GRANT_TYPE
const UNSUPPORTED_GRANT_TYPE
Definition: oauth_token_endpoint_error.php:18
ezpOauthTokenEndpointErrorType\INVALID_REQUEST
const INVALID_REQUEST
Definition: oauth_token_endpoint_error.php:14
ezpOauthUtility\doRefreshToken
static doRefreshToken( $clientId, $clientSecret, $refreshToken)
Definition: utility.php:170
ezpOauthUtility\doRefreshTokenWithAuthorizationCode
static doRefreshTokenWithAuthorizationCode( $clientId, $clientSecret, $authCode, $redirectUri)
Definition: utility.php:230
ezpRestOauthTokenController
Definition: oauth_token.php:19
ezpRestOauthTokenController\checkParams
checkParams( $paramsToCheck)
Definition: oauth_token.php:96
ezpRestOauthTokenController\doHandleRequest
doHandleRequest()
Definition: oauth_token.php:27
ezpRestOauthTokenController\validateGrantType
validateGrantType( $grant)
Definition: oauth_token.php:118
ezpRestOauthTokenController\validateClient
validateClient( $client_id, $client_secret)
Definition: oauth_token.php:91
ezpRestToken
Definition: ezprest_token.php:17
$result
$result
Definition: companysearch.php:94
$error
$error
Definition: ezarticle/admin/categoryedit.php:51
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.