无法使用refresh_token生成令牌

时间:2017-04-20 13:21:45

标签: asp.net oauth-2.0

我正在将刷新令牌传递给我的本地主机服务器,但获得不受支持的授权类型响应(请参阅图像)。 Refresh Token Postman Request

我使用以下代码使用刷新令牌生成令牌。

public class MyAuthorizationServerProvider: OAuthAuthorizationServerProvider
{
    public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
    {
        context.Validated(); //
    }
    public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
    {
        var identity = new ClaimsIdentity(context.Options.AuthenticationType);

        if (context.UserName == “admin” && context.Password == “admin”)
        {
           identity.AddClaim(new Claim(ClaimTypes.Role, “admin”));
           identity.AddClaim(new Claim(“username”, “admin”));
           identity.AddClaim(new Claim(ClaimTypes.Name, “admin”));
           context.Validated(identity);
        }
        else if (context.UserName == “dmuser” && context.Password == “dmuser”)
        {
           identity.AddClaim(new Claim(ClaimTypes.Role, “dmuser”));
           identity.AddClaim(new Claim(“username”, “dmuser”));
           identity.AddClaim(new Claim(ClaimTypes.Name, “dmuser”));
           context.Validated(identity);
        }
        else
        {
           context.SetError(“invalid_grant”, “Provided username and password is incorrect”);
           return;
        }
    }

    public override async Task GrantRefreshToken( OAuthGrantRefreshTokenContext context)
    {
     // chance to change authentication ticket for refresh token requests
        var newId = new ClaimsIdentity(context.Ticket.Identity);
        var newTicket = new AuthenticationTicket(newId, context.Ticket.Properties);
        context.Validated(newTicket);
     }
 }

如果有人知道为什么我的GrantRefreshToken()方法在使用refresh_token生成新令牌时没有调用。 请回复! 在此先感谢!!!

1 个答案:

答案 0 :(得分:-1)

尝试使用标题,如下所示。请参阅RFC6749

Roslyn