2017-05-11 1 views
2

J'ai mis en œuvre avec succès l'octroi de code d'autorisation et l'octroi d'un mot de passe avec passeport 2.0 et laravel 5.4. Après avoir ajouté le Passport :: enableImplicitGrant(); dans AuthServiceProvider.php, j'ai essayé d'implémenter la subvention implicite avec une application angular2.Subvention implicite Laravel 5.4 passeport unsupported_grant_type erreur

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; 
    } 

Cependant, je reçois une erreur unsupported_grant_type

+0

J'ai ce problème aussi, actuellement à la recherche d'une solution sur le net –

Répondre

0

Quand vous faites Grant Implicite Type sur la Laravel 5.4 Documentation Réponse:

Pourquoi Implicite Grant ne fonctionne pas

Suite aux résultats de tutoriel en:

// 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" 
    } 

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

Dans le code de demande de jeton de subvention implicite, il fait une demande à: http://oauth2server1/oauth/authorize $ query

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

Le gestionnaire de oauth/autoriser la demande GET est: Laravel \ Passeport \ Http \ contrôleurs \ AuthorizationController @ autoriser selon route artisan php: liste

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

... Quelque part sur la ligne

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

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(); 
    } 

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

... Quelque part sur la ligne

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

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”   => “” 

comme un effet ... ce code renvoie toujours faux, et l'exécution de code revient à la fonction appelante

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

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? 
    } 

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

... quelque part sur la ligne

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

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); 
    } 

semble terriblement familier non?

+0

Je voudrais me corriger, je résolu mon problème en ce qui concerne en ajoutant les lignes suivantes dans le serveur d'autorisation: En AuthServiceProvider.php fonction publique boot() { $ this-> registerPolicies(); \t Passport :: routes(); \t Passport :: enableImplicitGrant(); } précédemment ,,, je les ai sur mon application CLIENT –