| Conditions | 4 |
| Paths | 18 |
| Total Lines | 99 |
| Code Lines | 11 |
| 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 |
||
| 26 | function handleRequest(ServerRequestInterface $request): ResponseInterface |
||
|
|
|||
| 27 | { |
||
| 28 | $requestData = $request->getMethod() == 'GET' ? $request->getQueryParams() : $request->getParsedBody(); |
||
| 29 | |||
| 30 | |||
| 31 | try { |
||
| 32 | /** |
||
| 33 | * The Authorization Server MUST validate all the OAuth 2.0 parameters according to the OAuth 2.0 specification |
||
| 34 | */ |
||
| 35 | $this->verifyRequestData($requestData); |
||
| 36 | |||
| 37 | |||
| 38 | /** |
||
| 39 | * Verify that a scope parameter is present and contains the openid scope value. |
||
| 40 | * (If no openid scope value is present, the request may still be a valid OAuth 2.0 request, but is not an OpenID Connect request.) |
||
| 41 | */ |
||
| 42 | $scope = $requestData['scope'] ?? ''; |
||
| 43 | $scopes = explode(' ', $scope); |
||
| 44 | if(!in_array('openid', $scopes)) { |
||
| 45 | return parent::handleRequest($request); |
||
| 46 | } |
||
| 47 | |||
| 48 | $responseData = $this->getResponseType()->handleAuthorizationRequest($this, $requestData); |
||
| 49 | return $this->getResponseMode()->buildResponse($this, $requestData, $responseData); |
||
| 50 | |||
| 51 | /** |
||
| 52 | * If the sub (subject) Claim is requested with a specific value for the ID Token, |
||
| 53 | * the Authorization Server MUST only send a positive response |
||
| 54 | * if the End-User identified by that sub value has an active session with the Authorization Server |
||
| 55 | * or has been Authenticated as a result of the request. |
||
| 56 | * The Authorization Server MUST NOT reply with an ID Token or Access Token for a different user, |
||
| 57 | * even if they have an active session with the Authorization Server. |
||
| 58 | * Such a request can be made either using an id_token_hint parameter |
||
| 59 | * or by requesting a specific Claim Value as described in Section 5.5.1, |
||
| 60 | * if the claims parameter is supported by the implementation. |
||
| 61 | */ |
||
| 62 | |||
| 63 | |||
| 64 | /** |
||
| 65 | * The Authorization Server MUST verify that all the REQUIRED parameters are present and their usage conforms to this specification. |
||
| 66 | */ |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Authorization Server Authenticates the End-User. |
||
| 70 | * |
||
| 71 | * If the request is valid, the Authorization Server attempts to Authenticate the End-User |
||
| 72 | * or determines whether the End-User is Authenticated, depending upon the request parameter values used. |
||
| 73 | * The methods used by the Authorization Server to Authenticate the End-User |
||
| 74 | * (e.g. username and password, session cookies, etc.) are beyond the scope of this specification. |
||
| 75 | * An Authentication user interface MAY be displayed by the Authorization Server, |
||
| 76 | * depending upon the request parameter values used and the authentication methods used. |
||
| 77 | * |
||
| 78 | * The Authorization Server MUST attempt to Authenticate the End-User in the following cases: |
||
| 79 | * |
||
| 80 | * The End-User is not already Authenticated. |
||
| 81 | * The Authentication Request contains the prompt parameter with the value login. |
||
| 82 | * In this case, the Authorization Server MUST reauthenticate the End-User |
||
| 83 | * even if the End-User is already authenticated. |
||
| 84 | * |
||
| 85 | * The Authorization Server MUST NOT interact with the End-User in the following case: |
||
| 86 | * |
||
| 87 | * The Authentication Request contains the prompt parameter with the value none. |
||
| 88 | * In this case, the Authorization Server MUST return an error if an End-User is not already Authenticated |
||
| 89 | * or could not be silently Authenticated. |
||
| 90 | * |
||
| 91 | * When interacting with the End-User, the Authorization Server MUST employ appropriate measures |
||
| 92 | * against Cross-Site Request Forgery and Clickjacking as, described in Sections 10.12 and 10.13 of OAuth 2.0 [RFC6749]. |
||
| 93 | */ |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Authorization Server obtains End-User Consent/Authorization. |
||
| 97 | * |
||
| 98 | * Once the End-User is authenticated, the Authorization Server MUST obtain an authorization decision |
||
| 99 | * before releasing information to the Relying Party. |
||
| 100 | * When permitted by the request parameters used, |
||
| 101 | * this MAY be done through an interactive dialogue with the End-User |
||
| 102 | * that makes it clear what is being consented to or by establishing consent |
||
| 103 | * via conditions for processing the request or other means (for example, via previous administrative consent). |
||
| 104 | * Sections 2 and 5.3 describe information release mechanisms. |
||
| 105 | */ |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Authorization Server sends the End-User back to the Client with an Authorization Code. |
||
| 109 | * |
||
| 110 | * An Authentication Response is an OAuth 2.0 Authorization Response message |
||
| 111 | * returned from the OP's Authorization Endpoint in response to the Authorization Request message sent by the RP. |
||
| 112 | * |
||
| 113 | * When using the Authorization Code Flow, the Authorization Response MUST return the parameters |
||
| 114 | * defined in Section 4.1.2 of OAuth 2.0 [RFC6749] by adding them as query parameters to the redirect_uri |
||
| 115 | * specified in the Authorization Request using the application/x-www-form-urlencoded format, |
||
| 116 | * unless a different Response Mode was specified. |
||
| 117 | */ |
||
| 118 | } |
||
| 119 | catch (OAuthException $e) { |
||
| 120 | /** |
||
| 121 | * If the Authorization Server encounters any error, it MUST return an error response, per Section 3.1.2.6. |
||
| 122 | */ |
||
| 123 | |||
| 124 | return new Response(400, ['content-type' => 'application/json'], $e->jsonSerialize()); |
||
| 125 | } |
||
| 149 | } |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.