【发布时间】:2017-02-28 09:11:30
【问题描述】:
嘿,我刚刚在tutorial 之后编写了一个基于令牌的身份验证。 因此,只要我将 POST 请求作为 x-www-form-urlencoded 发送,一切都会好起来的。所以现在我的队友需要用一个json来获取令牌,但他得到的只是“不支持的grant_type”。那么我可以更改令牌的可接受类型还是必须找到其他解决方案?
我的配置如下:
public void Configuration(IAppBuilder app)
{
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
var myProvider = new MyAuthorizationServerProvider();
OAuthAuthorizationServerOptions options = new OAuthAuthorizationServerOptions
{
AllowInsecureHttp = true,
TokenEndpointPath = new PathString("/token"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
Provider = myProvider
};
app.UseOAuthAuthorizationServer(options);
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
HttpConfiguration config = new HttpConfiguration();
WebApiConfig.Register(config);
}
}
【问题讨论】:
-
您是否在请求中将
grant_type作为password发送..?? -
在我的问题中添加了我的请求图片。是这样吗?
-
是的,它是正确的...现在在您的标头中使用 access_token 验证您的 API 请求...
-
Eg: Authorization : bearer access_token...in the header of postman
-
是的,我已经知道了,但问题是这只适用于 x-www-form-urlencoded 而不是 JSON
标签: c# asp.net json asp.net-web-api asp.net-identity