Intermittent ASP.NET oAuth issue with Google, AuthenticationManager.GetExternalIdentityAsync is returning null

后端 未结 7 1606
北海茫月
北海茫月 2020-12-29 23:37

I am trying to fix an intermittent issue when using Google as an external login provider.

When attempting to login, the user is redirected back to the login page ra

7条回答
  •  [愿得一人]
    2020-12-30 00:02

    I believe you should't be using app.UseGoogleAuthentication(); as that's a call which will try to use OpenID 2.0, which has been deprecated.
    What you should be using instead is OAuth 2.0 for Login (OpenID Connect).
    So:

    1. register your app in Google Developers Console
    2. enable it to access Google+ API (even though you do not intend to use Google+ directly - it's now used as a mean of authentication)
    3. enable ASP.NET Identity's Google authentication this way
    app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()  
    {  
        ClientId = "YOUR_CLIENT_ID",  
        ClientSecret = "YOUR_CLIENT_SECRET",  
    });
    

提交回复
热议问题