尝试获取令牌时,不支持的授予类型错误

时间:2018-06-02 04:09:54

标签: angular

我尝试获取令牌时遇到错误。我在服务器端使用ASP,在客户端使用Angular。我在POSTMAN中测试过并获得令牌,但是当我在dev中本地运行我的客户端时,我收到此错误“不支持的授权类型错误”。

有人可以帮我一把吗?

客户端:

{

 var data="userName=user&password=user&grant_type=password";

 const _headers=new Headers({"Content-Type":"application/x-www-form-urlencoded"});

 return this.http.post('http://website/token',data,{headers:_headers}); 

}

服务器:

public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)

{
   context.OwinContext.Response.Headers.Add("Access-Control-Allow->Origin", new[] { "*" });


    var identity = new ClaimsIdentity context.Options.AuthenticationType);

   if (context.UserName == "admin" && context.Password == "Admin")
    {
        identity.AddClaim(new Claim(ClaimTypes.Role, "user"));
        identity.AddClaim(new Claim("username", "user"));
        identity.AddClaim(new Claim(ClaimTypes.Name, "Sr Name"));
        context.Validated(identity);
    }
    else
    {
        context.SetError("invalid_grant", "Provided username and password is incorrect");
    }
}

0 个答案:

没有答案