2016-02-24 71 views
1

我目前正在用ASP.NET核心MVC6構建一個Web應用程序並使用新的Identity模型。不幸的是,目前關於此主題的文檔並不多,我希望實施社交認證。瞭解如何使用MVC6/Identity實現此功能,最好的方法是什麼?MVC6社會認證

+1

有文檔這裏https://docs.asp.net/en/latest/security/authentication/sociallogins.html –

回答

1

像喬·奧德特一樣,有很好的文檔:Enabling authentication using external providers

有例如對於Facebook,但以同樣的方式,你可以添加微軟,谷歌和Twitter - 只是通過NuGet包中添加提供程序(Microsoft.AspNet.Authentication*) - 或者你可以使用一般的OAuth 2.0提供商與任何其他客戶端支持的OAuth 2.0

但請注意,由我提及的OAuth 2.0提供商可能會對其他提供商產生意想不到的影響,特別是當您設置CallbackPath時 - 不要問爲什麼,因爲我還不知道。

至於現在我只使用微軟和谷歌提供者和兩個使用默認設置運行良好 - 下面你可以找到與我使用範圍我的例子:

Startup.cs 
... 

app.UseIdentity(); 

// External Authentication 
app.UseGoogleAuthentication(options => 
{ 
    options.ClientId = Configuration["OAuth:Google:ClientId"]; 
    options.ClientSecret = Configuration["OAuth:Google:ClientSecret"]; 
    options.AutomaticAuthenticate = false; 
    options.Scope.Add("https://www.googleapis.com/auth/userinfo.email"); 
    options.Scope.Add("https://www.googleapis.com/auth/userinfo.profile"); 
    //options.Scope.Add("https://www.googleapis.com/auth/plus.me"); 
    //options.Scope.Add("https://www.googleapis.com/auth/plus.login"); 
}); 

app.UseMicrosoftAccountAuthentication(options => 
{ 
    options.ClientId = Configuration["OAuth:MicrosoftAccount:ClientId"]; 
    options.ClientSecret = Configuration["OAuth:MicrosoftAccount:ClientSecret"]; 
    options.AutomaticAuthenticate = false; 
    options.Scope.Add("wl.emails"); 
    options.Scope.Add("wl.basic"); 
    //options.Scope.Add("wl.phone_numbers"); 
    //options.Scope.Add("wl.signin"); 
    //options.Scope.Add("wl.offline_access"); 
}); 

... 


更多範圍:


+0

怎樣才能然後檢索從外部供應商索賠和預填登記表? – Andrii