Conditions | 17 |
Paths | 562 |
Total Lines | 80 |
Code Lines | 40 |
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 |
||
78 | public function handleRequest(ServerRequestInterface $request): ResponseInterface |
||
79 | { |
||
80 | if ($request->getMethod() === 'GET') { |
||
81 | $requestData = $request->getQueryParams(); |
||
82 | } else if ($request->getMethod() === 'POST') { |
||
83 | $requestData = is_array($request->getParsedBody()) ? $request->getParsedBody() : []; |
||
84 | } else { |
||
85 | return new Response(404); |
||
86 | } |
||
87 | |||
88 | try { |
||
89 | // Authentication Request Validation |
||
90 | // The Authorization Server MUST validate all the OAuth 2.0 parameters according to the OAuth 2.0 specification. |
||
91 | parent::verifyRequestData($requestData); |
||
92 | |||
93 | if (in_array('openid', $this->getScopes())) { |
||
94 | $this->verifyRequestData($requestData); |
||
95 | } |
||
96 | |||
97 | } catch (OAuthException $e) { |
||
98 | /** |
||
99 | * If the Authorization Server encounters any error, it MUST return an error response, per Section 3.1.2.6. |
||
100 | */ |
||
101 | |||
102 | return new Response(400, ['content-type' => 'application/json'], $e->jsonSerialize()); |
||
103 | } |
||
104 | |||
105 | try { |
||
106 | // Authorization Server Authenticates End-User |
||
107 | if (!$this->resourceOwner->isAuthenticated(self::PROMPT_LOGIN)) { |
||
|
|||
108 | if ($this->prompt == self::PROMPT_NONE) { |
||
109 | throw new OAuthException('login_required'); |
||
110 | } |
||
111 | |||
112 | // may throw interaction_required |
||
113 | return $this->resourceOwner->authenticate($this->prompt == self::PROMPT_SELECT_ACCOUNT); |
||
114 | } |
||
115 | |||
116 | if ($this->prompt == self::PROMPT_NONE && |
||
117 | $this->resourceOwner->isInteractionRequiredForConsent($this)) { |
||
118 | throw new OAuthException('interaction_required'); |
||
119 | } |
||
120 | |||
121 | $consentGiven = $this->resourceOwner->hasGivenConsent($this->getClient(), $this->getScopes(), |
||
122 | $this->prompt == self::PROMPT_CONSENT); |
||
123 | |||
124 | if (is_null($consentGiven)) { |
||
125 | if ($this->prompt == self::PROMPT_NONE) { |
||
126 | throw new OAuthException('consent_required'); |
||
127 | } |
||
128 | |||
129 | return $this->resourceOwner->obtainConsent($this->getClient(), $this->getScopes(), $this->loginHint); |
||
130 | } |
||
131 | |||
132 | if (empty($consentGiven)) { |
||
133 | throw new OAuthException('access_denied', 'The resource owner denied the request.', |
||
134 | 'https://tools.ietf.org/html/rfc6749#section-4.1'); |
||
135 | } |
||
136 | |||
137 | $responseData = $this->getResponseType()->handleAuthorizationRequest($this, $requestData); |
||
138 | } catch (OAuthException $e) { |
||
139 | /** |
||
140 | * If the Authorization Server encounters any error, it MUST return an error response, per Section 3.1.2.6. |
||
141 | */ |
||
142 | $responseData = [ |
||
143 | 'error' => $e->getError() |
||
144 | ]; |
||
145 | if ($e->getErrorDescription()) { |
||
146 | $responseData['error_description'] = $e->getErrorDescription(); |
||
147 | } |
||
148 | if ($e->getErrorUri()) { |
||
149 | $responseData['error_uri'] = $e->getErrorUri(); |
||
150 | } |
||
151 | } |
||
152 | |||
153 | if (!empty($this->getState())) { |
||
154 | $responseData['state'] = $this->getState(); |
||
155 | } |
||
156 | |||
157 | return $this->getResponseMode()->buildResponse($this, $requestData, $responseData); |
||
158 | } |
||
239 | } |