在具有Identity Framework的.net項目中,即使我可以生成令牌,但無法續訂令牌。唯一的例外是如下:在令牌刷新時,AuthenticationTokenReceiveContext無法訪問Owin.Security/Identity Framework中的令牌值
[ArgumentNullException: Value cannot be null.
Parameter name: token]
Microsoft.Owin.Security.Infrastructure.AuthenticationTokenReceiveContext..ctor(IOwinContext context, ISecureDataFormat`1 secureDataFormat, String token) +136
Microsoft.Owin.Security.OAuth.<InvokeTokenEndpointRefreshTokenGrantAsync>d__44.MoveNext() +158
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) +25
Microsoft.Owin.Security.OAuth.<InvokeTokenEndpointAsync>d__1e.MoveNext() +2159
由於此異常,調試器甚至不會踏進令牌提神功能:
public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
{
var allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin");
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });
string hashedTokenId = Helper.GetHash(context.Token);
using (AuthRepository _repo = new AuthRepository())
{
var refreshToken = await _repo.FindRefreshToken(hashedTokenId);
if (refreshToken != null)
{
//Get protectedTicket from refreshToken class
context.DeserializeTicket(refreshToken.ProtectedTicket);
var result = await _repo.RemoveRefreshToken(hashedTokenId);
}
}
}
我使用郵差調試,並張貼請求包含正確令牌,這在請求正文中未檢測到,在請求頭中也沒有。
武士刀開發團隊已將此標記爲一個bug:http://katanaproject.codeplex.com/workitem/480,但也表示沒有更新即將到來。
的相同的代碼運行在遠程服務器上:在此可以重現http://ngauthenticationweb.azurewebsites.net/
完整的項目,請訪問:https://github.com/tjoudeh/AngularJSAuthentication
我怎麼能強迫令牌插入的背景下,爲了防止異常?
grant_type是在初始登錄時 '密碼' 和它的偉大工程。不起作用的是'refresh_token'的grant_type - 它用於基於刷新令牌的重新認證。 – Kurak