簡體   English   中英

.net OWIN oauth2 AuthenticateCoreAsync() 在使用身份驗證代碼從提供者重定向后未被調用

[英].net OWIN oauth2 AuthenticateCoreAsync() not being called after reidrect from provider with auth code

我正在 .net 中使用 OWIN 實現 oauth。 我能夠成功登錄到我的提供商,並使用 URL 中的身份驗證代碼重定向到我的應用程序。 在這一點上一切似乎都很好,但是 AuthenticateCoreAsync() 方法似乎沒有在我的 AuthHandler 中使用。 這是從 URL 中提取代碼以調用令牌端點以獲取聲明的地方。

有誰知道為什么這種方法沒有被重定向回我的應用程序?

根據我的理解,這是流程:

用戶點擊登錄。

應用程序從 ApplyResponseChallaengeAsync() 重定向到提供程序

提供程序使用授權碼重定向到應用程序。

這是我不明白會發生什么的地方

應用程序處於具有身份驗證代碼但未命中令牌端點的狀態。

我有一個帶有 [Authorize] 標簽的自定義端點,當點擊它時,應用程序提示我登錄,然后我通過登錄過程,並返回我的應用程序,但未命中身份驗證代碼和令牌端點.

我剛剛完成了 owin OpenIdConnect 與 Apple ID 的集成,我花了很長時間來解決所有問題。 我從你的描述中認為你沒有處理從蘋果返回的代碼。 如果是這樣,您應該在 Startup.Auth.cs 中使用自定義 openId 通知處理程序 (AuthorizationCodeReceived) 執行此操作,如下所示:

Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthorizationCodeReceived = (context) =>
{
    var clientToken = JwtTokenGenerator.CreateNewToken();

    logger.LogInfo("Apple: clientToken generated");
    context.TokenEndpointRequest.ClientSecret = clientToken;
    logger.LogInfo("Apple: TokenEndpointRequest ready");

    return Task.FromResult(0);
},
TokenResponseReceived = (context) =>
{
    logger.LogInfo("Apple: TokenResponseReceived");

    return Task.FromResult(0);
},
SecurityTokenReceived = (context) =>
{
    logger.LogInfo("Apple: SecurityTokenReceived");

    return Task.FromResult(0);
},
SecurityTokenValidated = (context) =>
{
    string userID = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.NameIdentifier).Value;
    logger.LogInfo("Apple: SecurityTokenValidated with userID=" + userID);

    return Task.FromResult(0);
},
...
};

app.UseOpenIdConnectAuthentication(appleIdOptions);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM