2017-05-11 2 views
2

Ich habe Autorisierung Code Grant und Passwort gewähren mit Pass 2.0 und Laravel 5.4 erfolgreich implementiert. Nach dem Hinzufügen der Passport :: enableImplicitGrant(); In AuthServiceProvider.php habe ich versucht, die implizite Grant mit einer angular2 App zu implementieren.Implizite Gewährung Laravel 5.4 Pass unsupported_grant_type Fehler

getImplicitAccessToken() { 
    const headers = new Headers({ 
     'Content-Type': 'application/json', 
     'Accept' : 'application/json' 
    }); 
    const query = { 
     'grant_type' : 'token', 
     'client_id' : Constants.IMPLICIT_TEST_CLIENT_ID, 
     'redirect_uri' : window.location.origin + '/implicit-code-grant', 
     'scope': '' 
    }; 
    const params = this.getParamsFromJson(query); 
    window.location.href = Constants.OAUTH_AUTHORIZATION_URL + '?' + params.toString(); 
    } 
    private getParamsFromJson(query: any) { 
    const params = new URLSearchParams(); 
    for (const key in query) { 
     params.set(key, query[key]); 
    } 
    return params; 
    } 

aber ich erhalte eine unsupported_grant_type Fehler

+0

Ich habe dieses Problem auch noch für eine Lösung über das Netz –

Antwort

0

Wenn auf der Dokumentation Laravel 5.4 Implizite Grant Typ tun Antwort:

Warum Implizite Grants funktioniert nicht

Nach den Tutorial Ergebnisse in:

// 20170711152854 
// http://oauth2server1/oauth/authorize?KEY=14997536295521&client_id=1&redirect_uri=http%3A%2F%2Fauthorizationgrantclient1%2Fcallback&response_type=token&scope=%3FXDEBUG_SESSION_START%3DECLIPSE`enter code here`_DBGP 

    { 
     "error": "unsupported_grant_type", 
     "message": "The authorization grant type is not supported by the authorization server.", 
     "hint": "Check the `grant_type` parameter" 
    } 

============================================================================================ 

In dem impliziten Bewilligungstoken Anforderungscode wird eine Anforderung an: http://oauth2server1/oauth/authorize $ query

============================================================================================ 

die Handler von oauth/GET-Anfrage genehmigen ist: Laravel \ Passport \ Http \ Controllers \ AuthorizationController @ autorisieren nach php Handwerker Route: Liste

============================================================================================ 

... nach unten irgendwo die Linie

============================================================================================ 

In vendor\league\oauth2-server\src\AuthorizationServer.php -> function validateAuthorizationRequest() 

    /** 
    * Validate an authorization request 
    * 
    * @param ServerRequestInterface $request 
    * 
    * @throws OAuthServerException 
    * 
    * @return AuthorizationRequest 
    */ 
    public function validateAuthorizationRequest(ServerRequestInterface $request) 
    { 
     foreach ($this->enabledGrantTypes as $grantType) 
     { 
      if($grantType->canRespondToAuthorizationRequest($request)) // <— ValidationStartsHere 
      { 
       return $grantType->validateAuthorizationRequest($request); 
      } 
     } 

     throw OAuthServerException::unsupportedGrantType(); 
    } 

============================================================================================ 

... Irgendwo auf der ganzen Linie

============================================================================================ 

In vendor/league/oauth2-server/src/Grant/AuthCodeGrant.php -> function canRespondToAuthorizationRequest() 

    /** 
    * {@inheritdoc} 
    */ 
    public function canRespondToAuthorizationRequest(ServerRequestInterface $request) 
    { 
     return (array_key_exists('response_type', $request->getQueryParams()) // TRUE 
       && $request->getQueryParams()['response_type'] === 'code'  // FALSE 
       && isset($request->getQueryParams()['client_id'])    // TRUE 
     ); 
    } 

the values of the following variables are as follows: 
$request->getQueryParams(): 
“KEY”   => “14997536295521”, 
“client_id”  => “1”, 
“redirect_uri” => “http://authorizationgrantclient1/callback”, // refer this value back to how to make an  implicit grant token request 
“response_type” => “token”, 
“scope”   => “” 

als Effekt ... Dieser Code gibt immer false zurück, und die Ausführung von Code geht zurück an die aufrufende Funktion

============================================================================================ 

going back to vendor\league\oauth2-server\src\AuthorizationServer.php->validateAuthorizationRequest() 

    /** 
    * Validate an authorization request 
    * 
    * @param ServerRequestInterface $request 
    * 
    * @throws OAuthServerException 
    * 
    * @return AuthorizationRequest 
    */ 
    public function validateAuthorizationRequest(ServerRequestInterface $request) 
    { 
     foreach ($this->enabledGrantTypes as $grantType) { 
      if ($grantType->canRespondToAuthorizationRequest($request)) { 
       return $grantType->validateAuthorizationRequest($request); 
      } 
     } 

     throw OAuthServerException::unsupportedGrantType(); // <—looks familiar? 
    } 

============================================================================================ 

... irgendwo auf der ganzen Linie

============================================================================================ 

In vendor\league\oauth2-server\src\Exception\OAuthServerException.php->function unsupportedGrantType() 

    /** 
    * Unsupported grant type error. 
    * 
    * @return static 
    */ 
    public static function unsupportedGrantType() 
    { 
     $errorMessage = 'The authorization grant type is not supported by the authorization server.'; 
     $hint = 'Check the `grant_type` parameter'; 

     return new static($errorMessage, 2, 'unsupported_grant_type', 400, $hint); 
    } 

sieht sehr vertraut, oder?

+0

suche ich mich korrigieren möchte, löste ich mein Problem in Bezug auf das durch die folgenden Zeilen in dem Autorisierungs-Server hinzufügen: In AuthServiceProvider.php öffentliche Funktion boot() { $ this-> registerPolicies(); \t Passport :: routes(); \t Passport :: enableImplicitGrant(); } zuvor ,,, Ich habe sie auf meiner CLIENT-Anwendung –