2017-09-19 2 views
1

J'ai essayé d'installer Github en tant que fournisseur externe dans ASP.NET Core 2.0, comme suit:Github fournisseur OAuth avec ASP.NET Core 2.0 ne fonctionne pas

services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) 
      .AddCookie() 
      .AddOAuth("Github", "Git Hub", gitHubOptions => 
      { 
       gitHubOptions.ClientId = Configuration["Auth:Github:ClientId"]; 
       gitHubOptions.ClientSecret = Configuration["Auth:Github:ClientSecret"]; 
       gitHubOptions.CallbackPath = new PathString("/signin-github"); 
       gitHubOptions.AuthorizationEndpoint = "http://github.com/login/oauth/authorize"; 
       gitHubOptions.TokenEndpoint = "https://github.com/login/oauth/access_token"; 
      }) 

J'ai aussi installer un Github APP avec une URL de redirection

enter image description here

le bouton fournisseur de externel (Github) est affiché sur la page de connexion. Lorsque le bouton est enfoncé, la page de connexion Github est également affichée. Après avoir entré les informations d'identification et appuyer sur autoriser, l'utilisateur est redirigé vers la page de connexion de mon service, mais une inscription n'est pas possible.

enter image description here

Le même scénario fonctionne très bien avec Microsoft, Google et Facebook. Une adresse e-mail est affichée sur la page "enregistrer" et l'utilisateur peut être enregistré.

Avez-vous une idée?

+1

Voir un exemple ici https://github.com/aspnet/Security/blob/1367a5d3858d4446c126940fe5c26267d0ac2512/samples/SocialSample/Startup.cs#L175 – Tratcher

+0

@Tratcher, thx ça marche me –

+0

grande aide: D – Ivan

Répondre

2

Pour les curieux, l'élément manquant ici est de mapper des informations d'utilisateur aux revendications. Voici un extrait de l'échantillon lié. https://github.com/aspnet/Security/blob/1367a5d3858d4446c126940fe5c26267d0ac2512/samples/SocialSample/Startup.cs#L175

o.ClientId = Configuration["github:clientid"]; 
o.ClientSecret = Configuration["github:clientsecret"]; 
o.CallbackPath = new PathString("/signin-github"); 
o.AuthorizationEndpoint = "https://github.com/login/oauth/authorize"; 
o.TokenEndpoint = "https://github.com/login/oauth/access_token"; 
o.UserInformationEndpoint = "https://api.github.com/user"; 
// Retrieving user information is unique to each provider. 
o.ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id"); 
o.ClaimActions.MapJsonKey(ClaimTypes.Name, "login"); 
o.ClaimActions.MapJsonKey("urn:github:name", "name"); 
o.ClaimActions.MapJsonKey(ClaimTypes.Email, "email", ClaimValueTypes.Email); 
o.ClaimActions.MapJsonKey("urn:github:url", "url");