0
我在服務器端使用Owin來獲取訪問令牌。之後,我將令牌從客戶端發送到服務器進行身份驗證。我想知道,如何在授權完成後精確地運行一個函數? (我試過AccessTokenProvider - > OnReceiveAsync,但它沒有正常工作)。在Owin Token授權後調用函數處理程序C#
我在服務器端使用Owin來獲取訪問令牌。之後,我將令牌從客戶端發送到服務器進行身份驗證。我想知道,如何在授權完成後精確地運行一個函數? (我試過AccessTokenProvider - > OnReceiveAsync,但它沒有正常工作)。在Owin Token授權後調用函數處理程序C#
我找到了答案。在App Start中使用OnReceive代替OnReceiveAsync就足夠了,或者您可以在其中啓動Oauth Object,如下所示:
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/GetAuthToken",
Provider = new ApplicationOAuthProvider(PublicClientId, UserManagerFactory),
AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin",
AccessTokenExpireTimeSpan = TimeSpan.FromDays(10),
AllowInsecureHttp = true,
AccessTokenProvider = new AuthenticationTokenProvider()
{
OnReceive = context =>
{
context.DeserializeTicket(context.Token);
// After this you can be sure that your ticket is initialized and have
// an access to the user
if(context.Ticket.Identity.IsAuthenticated)
EntityContext.UserId = context.Ticket.Identity.GetUserId();
else
EntityContext.UserId = "";
}
}
};