[英]cordova project gives unsupported_grant_type error but same works on browser
I have a ASP.Net WebAPI2 website that has a /token implementing the OWIN token service. 我有一个ASP.Net WebAPI2网站,该网站具有实现OWIN令牌服务的/ token。 This service is working just fine for my website, I am able to use rest clients and get the token as expected both from my PC as well as Android Phone.
这项服务在我的网站上正常工作,我可以使用其余客户端,并从PC和Android Phone上按预期方式获得令牌。
however when I call the service from inside my ionic project deployed on my android phone KitKat OS, i get {"error":"unsupported_grant_type"}
. 但是,当我从部署在Android手机KitKat OS上的离子项目内部调用服务时,我得到
{"error":"unsupported_grant_type"}
。 Its on the same wifi so I am able to use a rest client and get the token using that. 它在同一个wifi上,因此我可以使用rest客户端并使用该客户端获取令牌。
here is the angular code that I am using: 这是我正在使用的角度代码:
.service('LoginTokenService', ['$resource', function ($resource) {
function getToken(payLoad, fnSuccess, fnError) {
return $resource("http://192.168.1.104/token", {},
{
"getAuthToken": {
method: "POST",
isArray: false,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
}
})
.getAuthToken(payLoad, fnSuccess, fnError);
}
return ({
getToken: getToken
});
Also on my webapi code I have set the option app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
同样在我的webapi代码上,我设置了选项
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
like below 像下面
public void ConfigureAuth(IAppBuilder app)
{
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
// Mounts the middleware on the provided app with the options configured
// above
app.UseOAuthBearerTokens(OAuthOptions);
}
Also the payLoad
contains UserName='myuser@domain.com', Password='my_password' & grant_type='password'
此外,
payLoad
包含UserName='myuser@domain.com', Password='my_password' & grant_type='password'
as I am relatively new to ionic and cardova I was wondering if anyone has encountered the similar issue. 因为我对Ionic和Cardova还是比较陌生,所以我想知道是否有人遇到过类似的问题。
I think I know the issue. 我想我知道这个问题。 on my Website, i used
$.param(payload)
to send login info to the /token service, but as JQuery was not available in the ionic by default, I removed that. 在我的网站上,我使用
$.param(payload)
将登录信息发送到/ token服务,但是由于默认情况下Iionic无法使用JQuery,因此我将其删除了。
I have now used the $httpParamSerializerJQLike(payLoad)
to serialize the payload and its working now.. 我现在使用
$httpParamSerializerJQLike(payLoad)
来序列化有效负载及其工作状态。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.