我必須找到問題的解決方案。所以我正在開發網站,我堅持認證。首先,我們使用Azure Active Directory進行用戶存儲。所以我找到了WebApp-WebAPI-OpenIDConnect-DotNet,並使它適合我的需求。到目前爲止它工作正常。但現在我還必須實施外部登錄(facebook,twitter等)。因此,我評論了以前的所有工作,以便我處理此任務。我不得不重寫一些UserManager和UserStore類,但它已經可以工作了。我可以登錄Facebook。但是現在,當我需要將這兩個登錄名一起加入時,它們不起作用。看起來,他們在框架內發生衝突。 Facebook登錄需要app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
,但當我打開此功能時,天藍色登錄將停止工作。如果我評論這一點,天藍色的登錄工程,Facebook沒有。任何人都可以給我一些幫助解決這個問題嗎?我會提供我Startup.Auth.cs
Azure身份驗證和OAuth身份驗證
using System;
using Owin;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Cookies;
using Microsoft.Owin.Security.OpenIdConnect;
using System.Configuration;
using System.Globalization;
using Microsoft.AspNet.Identity;
using Microsoft.Owin;
using Microsoft.AspNet.Identity.Owin;
using ClearRoadmapWeb.LoginProviderHelpers;
using Microsoft.Owin.Security.Facebook;
using System.Collections.Generic;
namespace ClearRoadmapWeb
{
public partial class Startup
{
private static string clientId = ConfigurationManager.AppSettings["ida:ClientId"];
private static string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance"];
private static string tenant = ConfigurationManager.AppSettings["ida:Tenant"];
private static string postLogoutRedirectUri = ConfigurationManager.AppSettings["ida:PostLogoutRedirectUri"];
string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(DefaultAuthenticationTypes.ExternalCookie);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = authority,
PostLogoutRedirectUri = postLogoutRedirectUri
}
);
app.CreatePerOwinContext<AzureIdentityUserManager>(AzureIdentityUserManager.Create); //For Faceook
app.CreatePerOwinContext<AzureIdentitySignInManager>(AzureIdentitySignInManager.Create); //For Facebook
#region FacebookOptions
//app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
FacebookAuthenticationOptions facebookOptions = new FacebookAuthenticationOptions()
{
AppId = "fb appId",
AppSecret = "fb appSecret"
};
facebookOptions.Scope.Add("email");
facebookOptions.Provider = new FacebookAuthenticationProvider()
{
OnAuthenticated = async context =>
{
foreach (var x in context.User)
{
context.Identity.AddClaim(new System.Security.Claims.Claim(x.Key, x.Value.ToString()));
}
//Get the access token from FB and store it in the database and use FacebookC# SDK to get more information about the user
context.Identity.AddClaim(new System.Security.Claims.Claim("FacebookAccessToken", context.AccessToken));
}
};
#endregion
app.UseFacebookAuthentication(facebookOptions);
}
}
}
OpenID的工作,但對於臉譜,我不得不改變''FaceBook「'到'」Facebook「'。但後來,在Facebook登錄後,它將我循環到'https:// localhost:44300/Account/ExternalLogin?provider = Facebook&error = access_denied&error = access_denied ...&error = access_denied ...'(每次添加'&error = access_denied' ) – Wish 2014-12-08 08:11:00