无法使用refresh_token生成令牌

问题描述:

我将刷新令牌传递给本地主机服务器,但获取不受支持的授予类型响应(请参阅图像)。 Refresh Token Postman Request无法使用refresh_token生成令牌

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

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); 
    } 
} 

如果任何人有任何想法,为什么在使用refresh_token产生新的凭证我GrantRefreshToken()方法调用没有。 请回复! 在此先感谢!

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

POST /token HTTP/1.1 
    Host: server.example.com 
    Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW 
    Content-Type: application/x-www-form-urlencoded 

    grant_type=refresh_token&refresh_token=tGzv3JOkF0XG5Qx2TlKWIA 
+0

感谢您的回复,但仍然无法正常工作。 GrantRefreshToken()方法未调用。 你能告诉如何调试? –

+0

它是否在处理你的邮递员请求?如果是这样,我们可以深入代码。您也可以尝试使用Curl来测试您的请求。 –

+0

邮递员请求无效(请检查附图) 当我给邮递员请求时,方法ValidateClientAuthentication被调用,但下一个方法,即GrantRefreshToken没有被调用。 –