Conditions | 20 |
Paths | 733 |
Total Lines | 91 |
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 | * @return null|ResponseInterface |
||
86 | * @throws OAuthException |
||
87 | */ |
||
88 | protected function verifyResourceOwner(): ?ResponseInterface |
||
89 | { |
||
90 | if (!$this->resourceOwner->isAuthenticated(self::PROMPT_LOGIN)) { |
||
|
|||
91 | if ($this->prompt == self::PROMPT_NONE) { |
||
92 | throw new OAuthException('login_required'); |
||
93 | } |
||
94 | |||
95 | // may throw interaction_required |
||
96 | return $this->resourceOwner->authenticate($this->prompt == self::PROMPT_SELECT_ACCOUNT, $this->loginHint); |
||
97 | } |
||
98 | |||
99 | if($this->idTokenHint) { |
||
100 | // check if user associated to this id token is the current user. |
||
101 | // var_dump($this->idTokenHint['sub']);die; |
||
102 | if($this->idTokenHint['sub'] !== $this->resourceOwner->getIdentifier()) { |
||
103 | if($this->prompt == self::PROMPT_NONE) { |
||
104 | throw new OAuthException('invalid_request'); |
||
105 | } |
||
106 | else { |
||
107 | throw new OAuthException('login_required'); |
||
108 | } |
||
109 | } |
||
110 | } |
||
111 | |||
112 | if ($this->prompt == self::PROMPT_NONE && |
||
113 | $this->resourceOwner->isInteractionRequiredForConsent($this)) { |
||
114 | throw new OAuthException('interaction_required'); |
||
115 | } |
||
116 | |||
117 | return null; |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * @return null|ResponseInterface |
||
122 | * @throws OAuthException |
||
123 | */ |
||
124 | protected function verifyConsent(): ?ResponseInterface |
||
125 | { |
||
126 | $consentGiven = $this->resourceOwner->hasGivenConsent($this->getClient(), $this->getScopes(), |
||
127 | $this->prompt == self::PROMPT_CONSENT); |
||
128 | |||
129 | if (is_null($consentGiven)) { |
||
130 | if ($this->prompt == self::PROMPT_NONE) { |
||
131 | throw new OAuthException('consent_required'); |
||
132 | } |
||
133 | |||
134 | return $this->resourceOwner->obtainConsent($this->getClient(), $this->getScopes()); |
||
135 | } |
||
136 | |||
137 | if (empty($consentGiven)) { |
||
138 | throw new OAuthException('access_denied', 'The resource owner denied the request.', |
||
139 | 'https://tools.ietf.org/html/rfc6749#section-4.1'); |
||
140 | } |
||
141 | |||
142 | return null; |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * @param array $requestData |
||
147 | * @throws OAuthException |
||
148 | */ |
||
149 | protected function verifyRequestData(array $requestData) |
||
150 | { |
||
151 | parent::verifyRequestData($requestData); |
||
152 | |||
153 | if (!in_array('openid', $this->getScopes())) { |
||
154 | return; |
||
155 | } |
||
156 | |||
157 | $this->nonce = empty($requestData['nonce']) ? null : $requestData['nonce']; |
||
158 | $this->display = empty($requestData['display']) ? null : $requestData['display']; |
||
159 | $this->prompt = empty($requestData['prompt']) ? null : $requestData['prompt']; |
||
160 | $this->maxAge = empty($requestData['max_age']) ? null : $requestData['max_age']; |
||
161 | $this->uiLocales = empty($requestData['ui_locales']) ? null : explode(' ', $requestData['ui_locales']); |
||
162 | |||
163 | if(!empty($requestData['id_token_hint'])) { |
||
164 | try { |
||
165 | $this->idTokenHint = $this->idTokenManager->decode($requestData['id_token_hint']); |
||
166 | } catch (\Exception $exception) { |
||
167 | throw new OAuthException('invalid_request', 'Failed to decode id_token_hint : '.$exception->getMessage()); |
||
168 | } |
||
169 | } |
||
170 | |||
171 | $this->loginHint = empty($requestData['login_hint']) ? null : $requestData['login_hint']; |
||
172 | $this->acrValues = empty($requestData['acr_values']) ? null : explode(' ', $requestData['acr_values']); |
||
173 | } |
||
174 | |||
175 | /** |
||
176 | * @return ResourceOwnerInterface |
||
246 | } |