ASP.Net MVC 5 Google Authentification avec Portée

Je vais essayer d'obtenir ASP.Net MVC 5 Google authentification OAuth2 travail correctement.

Quand je passe dans un GoogleOauth2AuthenticationOptions sans aucune portée, alors je suis en mesure de vous connecter avec succès.

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);

Alors cet appel renvoie un ExternalLoginInfo objet avec toutes les propriétés définies

ExternalLoginInfo loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

Quand je ajouter un champ cependant, puis-je ne pas obtenir les informations de connexion retourné. C'est juste nul.

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);

L'appel externes infos retourne null.

ExternalLoginInfo loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

Dans Google dev console, j'ai l'Api suivantes allumé..

  • Analytics API
  • BigQuery API
  • Google Cloud SQL
  • Google Cloud Storage
  • Google Cloud Storage API JSON
  • Google+ API
  • Google+ les Domaines de l'API
  • Identité Trousse à outils API
  • YouTube Analytics API
  • YouTube de Données de l'API v3

Quelque chose au sujet de l'ajout de portée pour les options, c'est de casser GetExternalLoginInfoAsync.

OriginalL'auteur Rob Gibbens | 2014-03-27