작동하지 역 직렬화 티켓, 다음 코드는 여기에 ASP.NET API OAuth2를 새로 고침 토큰 - 나는 ASP.NET API2와 OWIN와의 OAuth 2 새로 고침 토큰을 구현하고있어
public static OAuthAuthorizationServerOptions AuthorizationServerOptions
{
get
{
if (_AuthorizationServerOptions == null)
{
_AuthorizationServerOptions = new OAuthAuthorizationServerOptions()
{
AuthenticationType = OAuthDefaults.AuthenticationType,
AllowInsecureHttp = true,
TokenEndpointPath = new PathString(AuthSettings.TokenEndpoint),
AuthorizeEndpointPath = new PathString(AuthSettings.AuthorizeEndpoint),
AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(AuthSettings.TokenExpiry),
Provider = new CustomOAuthAuthorizationServerProvider(AuthSettings.PublicClientId),
// TODO: Remove the dependency with Thinktecture.IdentityModel library here
AccessTokenFormat = new CustomJWTFormat(),
RefreshTokenProvider = new CustomRefreshTokenProvider()
};
}
return _AuthorizationServerOptions;
}
}
내 CustomRefreshTokenProvider 클래스 내 OAuthAuthorizationOptions입니다 내가
Postman refresh token 서버 수익 400 잘못된 요청 상태 코드를 다음과 같이 토큰 끝점에 POST 요청을 보내는 우편 배달부를 사용했다
public override Task CreateAsync(AuthenticationTokenCreateContext context)
{
var identifier = context.Ticket.Identity.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier);
if (identifier == null || string.IsNullOrEmpty(identifier.Value))
{
return Task.FromResult<object>(null);
}
var refreshToken = HashHelper.Hash(Guid.NewGuid().ToString("n"));
var tokenIssued = DateTime.UtcNow;
var tokenExpire = DateTime.UtcNow.AddSeconds(AuthSettings.RefreshTokenExpiry);
context.Ticket.Properties.IssuedUtc = tokenIssued;
context.Ticket.Properties.ExpiresUtc = tokenExpire;
context.Ticket.Properties.AllowRefresh = true;
var protectedTicket = context.SerializeTicket();
AuthService.AddUserRefreshTokenSession(
identifier.Value,
refreshToken,
tokenIssued,
tokenExpire,
protectedTicket);
context.SetToken(refreshToken);
return Task.FromResult<object>(null);
}
public override Task ReceiveAsync(AuthenticationTokenReceiveContext context)
{
var refToken = context.Token;
var protectedTicket = AuthService.GetProtectedTicket(refToken);
if (!string.IsNullOrEmpty(protectedTicket))
{
context.DeserializeTicket(protectedTicket);
}
return Task.FromResult<object>(null);
}
. 나는 디버깅과 context.DeserializeTicket (protectedTicket) 나는 그것이 AuthSettings.RefreshTokenExpiry 지금부터 30 일입니다 때문에 만료 문제라고 생각하지 않습니다 예외
Exception thrown: 'System.Security.Cryptography.CryptographicException' in System.Web.dll
를 던질 것을 발견했다. 또한 내 web.config에 컴퓨터 키를 추가하려고 시도했습니다. OAuth Refresh Token does not deserialize/invalid_grant
여전히 작동하지 않습니다.
누구나 아이디어가 있습니까? 모든 솔루션을 높이 평가할 것입니다.
당신이 해결책을 찾았습니까? 나는 똑같은 문제가 있습니다. –
@Amin K 늦은 응답을 드려 죄송합니다. 방금 대답했습니다. 필요한 것입니까? –