Skip to content
Advertisement

Laravel 5.4 Passport: unsupported_grant_type

Hello I try to do a web application and I have a problem. When I request the token from /oauth/token I receive this response:

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

And my code is:

import { Injectable } from '@angular/core';
import { Http, Response, RequestOptions, Headers } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/Rx';

@Injectable()
export class UserService {

    private API: string = 'api/';
    private OAuth: string = 'oauth/'

    constructor(private _HTTP: Http) { }

    private get_header(): RequestOptions {
        let headers = new Headers();
        headers.append('Access-Control-Allow-Origin', '*' ); 
        headers.append('Content-Type', 'application/x-www-form-urlencoded' );  
        return new RequestOptions({ headers: headers });
    }

    Signin(email: string, password: string): void {

        let data = {
            form_params: {
                grant_type: 'password',
                client_id: 2,
                client_secret: 'vSFxVqALQHjyotPyGfhrGj3ziudUGsts2ZWiAGms',
                username: email,
                password: password,
                scope: '*',
            }
        };

        this._HTTP.post(
            this.OAuth + 'token',
            data,
            this.get_header()
        ).toPromise()
        .then( (_response) => {
           console.log (_response); 
        });
    }
}

And the request header:

POST /oauth/token HTTP/1.1
Host: localhost:8000
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0
Accept: application/json, text/plain, */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://localhost:8000/signin
Access-Control-Allow-Origin: *
Content-Type: application/json
X-XSRF-TOKEN: eyJpdiI6IkxtOHhqd0RDUW9MVjl1YVh0U0c4N2c9PSIsInZhbHVlIjoiUmdrenlLWll2eEFtdGFQK2dsWGN0Nm5jWGY2MW5HXC9zMDJFdU52SEh4RUoxSkY1QWVHUFNySXFkUUQ3SDNaTW0zNll6SVRONlFHQjBFVzZPT0RxQkR3PT0iLCJtYWMiOiIwNzg5ZjliMzUwYjE5ZWM4MWE3MTg3NDRjYWZiMDE1MWI1NWJjN2E1NmI5ZTMzY2UzMTIwODI4ODY0ZDQ1ZDY5In0=
Content-Length: 208
Cookie: XSRF-TOKEN=eyJpdiI6IkxtOHhqd0RDUW9MVjl1YVh0U0c4N2c9PSIsInZhbHVlIjoiUmdrenlLWll2eEFtdGFQK2dsWGN0Nm5jWGY2MW5HXC9zMDJFdU52SEh4RUoxSkY1QWVHUFNySXFkUUQ3SDNaTW0zNll6SVRONlFHQjBFVzZPT0RxQkR3PT0iLCJtYWMiOiIwNzg5ZjliMzUwYjE5ZWM4MWE3MTg3NDRjYWZiMDE1MWI1NWJjN2E1NmI5ZTMzY2UzMTIwODI4ODY0ZDQ1ZDY5In0%3D; laravel_session=eyJpdiI6ImlrdlNMTGtTK241WVArZGx6MzE5Mnc9PSIsInZhbHVlIjoiRVQxSmlpZFwvV3B4eVRHVUdVYlRtY1VOZHUzZ09FQnMyZjhjSnZoQjA0VVBvM0x5YnJJbmx3b25cL3dCbVZScTVUb2lTVkg5Sldyd3R0aFluMDBvcmhxQT09IiwibWFjIjoiZDk4NjZkMDhiNTE0NzA3YzQxODVkNGJjN2E3OTRjNWEzMjc2Njk2ZjEyODY2MzY3NmRhYzAzN2U1NGE0ZTg4NCJ9
Connection: keep-alive

Response header:

HTTP/1.1 400 Bad Request
Host: localhost:8000
Connection: close
x-powered-by: PHP/7.1.1
Content-Type: application/json
Cache-Control: no-cache, private
Date: Thu, 27 Jul 2017 09:35:53 +0000, Thu, 27 Jul 2017 09:35:53 GMT
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 59

Post data:

{
  "form_params": {
    "grant_type": "password",
    "client_id": 2,
    "client_secret": "vSFxVqALQHjyotPyGfhrGj3ziudUGsts2ZWiAGms",
    "username": "fasfa",
    "password": "fasfa",
    "scope": "*"
  }
}

I don’t have any other detail.

Advertisement

Answer

You need to install a password client for Passport. Assuming you’ve installed and configured Passport, to generate a password client, run:

php artisan passport:client --password

Make sure to use the details from the output of this command in your API requests.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement