2017-09-19 74 views
1

我試圖建立Github上在ASP.NET 2.0核心的外部供應商,如下:Github上的OAuth提供者不工作

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

我還設置一個Github的APP具有重定向URL

enter image description here

的externel提供商(Github上)按鈕時所顯示的登錄頁面上。當按下按鈕時,Github登錄頁面也會顯示。輸入憑證並按下授權後,用戶將被重定向到我的服務的登錄頁面,但註冊是不可能的。

enter image description here

相同的情況下正常工作與微軟,谷歌和Facebook。電子郵件地址顯示在「註冊」頁面,用戶可以註冊。

你有什麼想法嗎?

+1

查看示例這裏https://github.com/aspnet/Security/blob/1367a5d3858d4446c126940fe5c26267d0ac2512/samples/SocialSample/Startup.cs#L175 – Tratcher

+0

@Tratcher,THX它的工作原理 –

+0

很大的幫助我:d – Ivan

回答

2

爲了好奇,這裏缺少的元素是將用戶信息映射到索賠。以下是鏈接示例的摘錄。 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");