ASP.Net MVC 5 Google-Authentifizierung mit Rahmen
Ich versuche zu bekommen ASP.Net MVC 5 Google OAuth2-Authentifizierung korrekt funktioniert.
Wenn ich den pass in einer GoogleOauth2AuthenticationOptions ohne Rahmen, dann bin ich in der Lage, log-in erfolgreich.
var googlePlusOptions = new GoogleOAuth2AuthenticationOptions
{
ClientId = googleClientId,
ClientSecret = googleClientSecret,
SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
Provider = new GoogleOAuth2AuthenticationProvider()
{
OnAuthenticated = async ctx =>
{
ctx.Identity.AddClaim(new Claim("urn:tokens:googleplus:accesstoken", ctx.AccessToken));
}
},
};
app.UseGoogleAuthentication(googlePlusOptions);
Dann dieser Anruf zurück ExternalLoginInfo-Objekt mit allen Eigenschaften
ExternalLoginInfo loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
Wenn ich hinzufügen Geltungsbereich wenn, dann ich bekomme keine login-info zurückgegeben. Es ist einfach null.
var googlePlusOptions = new GoogleOAuth2AuthenticationOptions
{
ClientId = googleClientId,
ClientSecret = googleClientSecret,
SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
Provider = new GoogleOAuth2AuthenticationProvider()
{
OnAuthenticated = async ctx =>
{
ctx.Identity.AddClaim(new Claim("urn:tokens:googleplus:accesstoken", ctx.AccessToken));
}
},
};
googlePlusOptions.Scope.Add(YouTubeService.Scope.Youtube);
app.UseGoogleAuthentication(googlePlusOptions);
Dann wird der Anruf auf externe Informationen nur gibt null zurück,.
ExternalLoginInfo loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
In den Google dev console, ich habe die folgenden APIs eingeschaltet..
- Analytics-API
- BigQuery API
- Google Cloud SQL
- Google Cloud Storage
- Google Cloud Storage-JSON-API
- Google+ API
- Google+ Domains API
- Identity Toolkit API
- YouTube Analytics API
- YouTube Data API v3
Etwas über das hinzufügen von Rahmen, um die Optionen zu brechen GetExternalLoginInfoAsync.
Du musst angemeldet sein, um einen Kommentar abzugeben.
Wenn jemand noch Probleme mit diesem mit den neuesten Microsoft
OWIN-middleware (3.0.0+)...
Ich bemerkt Geiger, dass standardmäßig die folgenden Rahmen gesendet wird accounts.google.com:
Wenn Sie fügen Sie Ihre eigenen scope(s) über GoogleOAuth2AuthenticationOptions.Umfang.Add(...), so ist der Umfang wird:
Daher müssen Sie den Standard-scopes zu (oder zumindest, das das Problem bei mir):
So, ich dachte mir, diese, mit viel Hilfe von http://www.beabigrockstar.com/blog/google-oauth-sign-asp-net-identity. Es stellt sich heraus, dass die eingebaute Google-authentication-provider für MVC ist openId nur. Das ist, warum das hinzufügen einen Bereich brach es. Mit Fiddler konnte ich sehen, der GET-Anforderung an accounts.google.com inklusive "scope=openid" im querystring.
Durch die Umstellung auf die GooglePlusOAuth2 Anbieter in den link oben, oder über Nuget https://www.nuget.org/packages/Owin.Security.GooglePlus und mit dem provider-Namen "GooglePlus", ich war in der Lage, erfolgreich fügen Sie die Bereiche, und noch immer wieder die login-info von GetExternalLoginInfoAsync.
Die änderungen, die Google vorgenommen hat, Ihre auth-Mechanismen wurden spiegelt sich in der version 3.0.0 von Microsoft Owin-middleware. Sie haben richtig erkannt, eine der änderungen haben sich den OAuth Endpunkt zu Google+ (https://www.googleapis.com/plus/v1/people/me).
Also, der Schlüssel ist, um: