【发布时间】:2017-04-21 11:16:54
【问题描述】:
我正在向我的本地主机服务器传递一个刷新令牌,但获得了不受支持的授权类型响应(请参见图片)。
我正在使用以下代码使用刷新令牌生成令牌。
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 生成新令牌时没有调用。 请回复! 提前致谢!!!
【问题讨论】: