gpt4 book ai didi

php - Laravel 5.4 护照 : unsupported_grant_type

转载 作者:可可西里 更新时间:2023-10-31 22:40:21 32 4
gpt4 key购买 nike

您好,我尝试做一个 Web 应用程序,但遇到了问题。当我从/oauth/token 请求 token 时,我收到此响应:

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

我的代码是:

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

以及请求 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

响应头:

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

发布数据:

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

我没有任何其他细节。

最佳答案

您需要为 Passport 安装一个 password 客户端。假设您已经安装并配置了 Passport,要生成密码客户端,请运行:

php artisan passport:client --password

确保在您的 API 请求中使用此命令输出的详细信息。

关于php - Laravel 5.4 护照 : unsupported_grant_type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45347058/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com