简体   繁体   English

{“ error”:“ unsupported_grant_type”}进行语音通话

[英]{“error”:“unsupported_grant_type”} for angular call

My api post call for retrieving a jwt token responds with 400 error. 我的用于检索jwt令牌的api调用响应为400错误。 Here is my api angular call. 这是我的api角度通话。 I tried with URLSearchparams too. 我也尝试了URLSearchparams。

authenticateUser(userid: string, password: string) {
        // var authorization_grant = "password";
        // let body = new URLSearchParams();
        // body.append('username', userid);
        // body.append('password', password);
        // body.append('grant_type', authorization_grant);
        let body = 'userName=' + userid+ '&password=' +password +'&grant_type=password';
        let headers = new Headers();
        headers.append('Content-Type', 'application/x-www-form-urlencoded');
        headers.append('Access-Control-Allow-Origin', '*');
        let options = new RequestOptions({ headers: headers });

        return this.http.post(this.config.apiBaseUrl + '/token', body, options).retry(3).map((res: Response) => {
            if (res.status == 200) {
                this.validatedUser = res.json();
                localStorage.setItem("access_token", this.validatedUser.access_token);
            }
            return this.validatedUser;
        })
    }

OK, after investigating the traffic in Fiddler tool, I compared the headers when called from postman vs angular. 好的,在调查了Fiddler工具中的流量之后,我比较了从邮递员和有角度的人调用时的标头。

On Client-Side: I removed line headers.append('Access-Control-Allow-Origin', '*'); 在客户端:我删除了header.append('Access-Control-Allow-Origin','*'); from my code which resolved this issue. 从我的代码解决了这个问题。

On Server-Side Most importantly I moved app.UseCors(CorsOptions.AllowAll) line of code on top of app.UseOAuthAuthorizationServer where I generate token in my startup.cs. 在服务器端最重要的是,我将app.UseCors(CorsOptions.AllowAll)代码行移到了app.UseOAuthAuthorizationServer顶部,在我的startup.cs中生成了令牌。

Thanks @jps, @biswajit-rout and @Ruard Van Elburg for looking into it. 感谢@ jps,@ biswajit-rout和@Ruard Van Elburg对其进行调查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 cordova项目给出了unsupported_grant_type错误,但在浏览器上也可以使用 - cordova project gives unsupported_grant_type error but same works on browser 角度与resteasy-Mediatype不支持的错误 - angular with resteasy - Mediatype unsupported error 带门卫和Angular的Oauth2密码授予类型 - Oauth2 password grant type with Doorkeeper and Angular 415不支持的媒体类型与Angular JS - 415 unsupported media type With Angular JS HTTP状态415 –带角度js的Spring MVC中不支持的媒体类型错误 - HTTP Status 415 – Unsupported Media Type error in Spring MVC with angular js 使用$ http从角度发布到aspnetcore api时出现415不支持的媒体类型错误 - 415 unsupported media type error when posting to aspnetcore api from angular using $http HTTP状态415 –不支持的媒体类型错误 - HTTP Status 415 – Unsupported Media Type error 如何在 angular http 请求中实现 client_credentials 授权类型? - How to implement a client_credentials grant type in an angular http request? 缺少必需的参数:grant_type ngCordova / angular - Required parameter is missing: grant_type ngCordova/angular 调用REST API原因415(不支持的媒体类型) - Call to a REST API cause 415 (Unsupported Media Type)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM