Conditions | 20 |
Paths | 733 |
Total Lines | 97 |
Code Lines | 50 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
85 | public function handleRequest(ServerRequestInterface $request): ResponseInterface |
||
86 | { |
||
87 | if ($request->getMethod() === 'GET') { |
||
88 | $requestData = $request->getQueryParams(); |
||
89 | } else if ($request->getMethod() === 'POST') { |
||
90 | $requestData = is_array($request->getParsedBody()) ? $request->getParsedBody() : []; |
||
91 | } else { |
||
92 | return new Response(404); |
||
93 | } |
||
94 | |||
95 | // Authentication Request Validation |
||
96 | // The Authorization Server MUST validate all the OAuth 2.0 parameters according to the OAuth 2.0 specification. |
||
97 | try { |
||
98 | $this->verifyClient($requestData['client_id'] ?? null); |
||
99 | $this->verifyRedirectUri($requestData['redirect_uri'] ?? null); |
||
100 | } catch (OAuthException $e) { |
||
101 | /** |
||
102 | * If the Authorization Server encounters any error, it MUST return an error response, per Section 3.1.2.6. |
||
103 | */ |
||
104 | |||
105 | return new Response(400, ['content-type' => 'application/json'], $e->jsonSerialize()); |
||
106 | } |
||
107 | |||
108 | try { |
||
109 | parent::verifyRequestData($requestData); |
||
110 | |||
111 | if (in_array('openid', $this->getScopes())) { |
||
112 | $this->verifyRequestData($requestData); |
||
113 | } |
||
114 | |||
115 | $this->getResponseType()->verifyAuthorizationRequest($this, $requestData); |
||
116 | |||
117 | // Authorization Server Authenticates End-User |
||
118 | if (!$this->resourceOwner->isAuthenticated(self::PROMPT_LOGIN)) { |
||
|
|||
119 | if ($this->prompt == self::PROMPT_NONE) { |
||
120 | throw new OAuthException('login_required'); |
||
121 | } |
||
122 | |||
123 | // may throw interaction_required |
||
124 | return $this->resourceOwner->authenticate($this->prompt == self::PROMPT_SELECT_ACCOUNT, $this->loginHint); |
||
125 | } |
||
126 | |||
127 | if($this->idTokenHint) { |
||
128 | //check if user associated to this id token is the current user. |
||
129 | var_dump($this->idTokenHint['sub']);die; |
||
130 | if($this->idTokenHint['sub'] !== $this->resourceOwner->getIdentifier()) { |
||
131 | if($this->prompt == self::PROMPT_NONE) { |
||
132 | throw new OAuthException('invalid_request'); |
||
133 | } |
||
134 | else { |
||
135 | throw new OAuthException('login_required'); |
||
136 | } |
||
137 | } |
||
138 | } |
||
139 | |||
140 | if ($this->prompt == self::PROMPT_NONE && |
||
141 | $this->resourceOwner->isInteractionRequiredForConsent($this)) { |
||
142 | throw new OAuthException('interaction_required'); |
||
143 | } |
||
144 | |||
145 | $consentGiven = $this->resourceOwner->hasGivenConsent($this->getClient(), $this->getScopes(), |
||
146 | $this->prompt == self::PROMPT_CONSENT); |
||
147 | |||
148 | if (is_null($consentGiven)) { |
||
149 | if ($this->prompt == self::PROMPT_NONE) { |
||
150 | throw new OAuthException('consent_required'); |
||
151 | } |
||
152 | |||
153 | return $this->resourceOwner->obtainConsent($this->getClient(), $this->getScopes()); |
||
154 | } |
||
155 | |||
156 | if (empty($consentGiven)) { |
||
157 | throw new OAuthException('access_denied', 'The resource owner denied the request.', |
||
158 | 'https://tools.ietf.org/html/rfc6749#section-4.1'); |
||
159 | } |
||
160 | |||
161 | $responseData = $this->getResponseType()->handleAuthorizationRequest($this, $requestData); |
||
162 | } catch (OAuthException $e) { |
||
163 | /** |
||
164 | * If the Authorization Server encounters any error, it MUST return an error response, per Section 3.1.2.6. |
||
165 | */ |
||
166 | $responseData = [ |
||
167 | 'error' => $e->getError() |
||
168 | ]; |
||
169 | if ($e->getErrorDescription()) { |
||
170 | $responseData['error_description'] = $e->getErrorDescription(); |
||
171 | } |
||
172 | if ($e->getErrorUri()) { |
||
173 | $responseData['error_uri'] = $e->getErrorUri(); |
||
174 | } |
||
175 | } |
||
176 | |||
177 | if (!empty($this->getState())) { |
||
178 | $responseData['state'] = $this->getState(); |
||
179 | } |
||
180 | |||
181 | return $this->getResponseMode()->buildResponse($this, $requestData, $responseData); |
||
182 | } |
||
272 | } |