현재 Forms 인증 (또는 FormsAuthenticationTicket 쿠키를 설정하는 LDAP)을 사용하는 웹 양식 응용 프로그램이 있습니다. 이 프로젝트에 SSO를 추가해야하며 현재 OpenID/Azure AD를 사용하여 인증하고 있습니다. 다음 Startup.cs가 구성되었습니다. (결코 타격을 받고있는 것 같다 없지만. - 내가 인증을 필요로하는 페이지를 탐색 할 때 인증 프로세스가 킥오프 원인이되어야 다른 뭔가를)기존 Web Forms 응용 프로그램에 SSO OpenId/Azure AD 인증 추가
public void Configuration(IAppBuilder app)
{
string appId = "<id here>";
string aadInstance = "https://login.microsoftonline.com/{0}";
string tenant = "<tenant here>";
string postLogoutRedirectUri = "https://localhost:21770/";
string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = appId,
Authority = authority,
PostLogoutRedirectUri = postLogoutRedirectUri,
Notifications = new OpenIdConnectAuthenticationNotifications
{
SecurityTokenReceived = context =>
{
System.Diagnostics.Debug.WriteLine("SecurityTokenReceived");
return Task.FromResult(0);
},
SecurityTokenValidated = async n =>
{
var claims_to_exclude = new[]
{
"aud", "iss", "nbf", "exp", "nonce", "iat", "at_hash"
};
var claims_to_keep =
n.AuthenticationTicket.Identity.Claims
.Where(x => false == claims_to_exclude.Contains(x.Type)).ToList();
claims_to_keep.Add(new Claim("id_token", n.ProtocolMessage.IdToken));
if (n.ProtocolMessage.AccessToken != null)
{
claims_to_keep.Add(new Claim("access_token", n.ProtocolMessage.AccessToken));
//var userInfoClient = new UserInfoClient(new Uri("https://localhost:44333/core/connect/userinfo"), n.ProtocolMessage.AccessToken);
//var userInfoResponse = await userInfoClient.GetAsync();
//var userInfoClaims = userInfoResponse.Claims
// .Where(x => x.Item1 != "sub") // filter sub since we're already getting it from id_token
// .Select(x => new Claim(x.Item1, x.Item2));
//claims_to_keep.AddRange(userInfoClaims);
}
var ci = new ClaimsIdentity(
n.AuthenticationTicket.Identity.AuthenticationType,
"name", "role");
ci.AddClaims(claims_to_keep);
n.AuthenticationTicket = new AuthenticationTicket(
ci, n.AuthenticationTicket.Properties
);
},
MessageReceived = context =>
{
System.Diagnostics.Debug.WriteLine("MessageReceived");
return Task.FromResult(0);
},
AuthorizationCodeReceived = context =>
{
System.Diagnostics.Debug.WriteLine("AuthorizationCodeReceived");
return Task.FromResult(0);
},
AuthenticationFailed = context =>
{
System.Diagnostics.Debug.WriteLine("AuthenticationFailed");
context.HandleResponse();
context.Response.Write( context.Exception.Message);
return Task.FromResult(0);
}
,
RedirectToIdentityProvider = (context) =>
{
System.Diagnostics.Debug.WriteLine("RedirectToIdentityProvider");
//string currentUrl = context.Request.Scheme + "://" + context.Request.Host + context.Request.Path;
//context.ProtocolMessage.RedirectUri = currentUrl;
return Task.FromResult(0);
}
}
});
app.UseStageMarker(PipelineStage.Authenticate);
}
내 마스터 페이지로드 이벤트에서이 놓여있다
내가이 청구 정보로 로그인하고 내 이메일을 볼 수 있습니다,하지만 난 다음에 무엇을 확실하지 않다 - 나는 SecurityTokenValidated 및 AuthorizationCodeReceived 기능을 타격하고 있기 때문에if (!Request.IsAuthenticated)
{
HttpContext.Current.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = "/Login.aspx" }, OpenIdConnectAuthenticationDefaults.AuthenticationType);
}
내 푸른 설정은 모든 정확합니다. 나는 끝없는 인증 요청 루프를 가지고 있습니다. 나는 내가 폼 인증으로받은 클레임 정보를 번역하지 않았기 때문에 이것을 가정하고 있습니까? AuthorizationCodeReceived에서 응답에 더미 인증 티켓을 추가하려고 시도했지만 아무 것도 변경하지 못했습니다. 여전히 반복 인증 요청을 받고 있습니다.
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, "<UserName>", DateTime.Now, DateTime.Now.AddMinutes(60), true,"");
String encryptedTicket = FormsAuthentication.Encrypt(authTicket);
context.Response.Cookies.Append(FormsAuthentication.FormsCookieName, encryptedTicket);
"인증 요청이 끊어지지 않는 루프"문제가 있습니까? 메모리에서, 나는 명백한 로그온 코드를 사용할 필요가 없다고 확신한다 - 그것은 startup.cs에 올바른 것을 추가함으로써 모두 처리되었다. 아마도 가장 좋은 해결책은 OpenID를 사용하여 새로운 프로젝트를 만들고 자동 생성되는 코드를 살펴 보는 것입니다. –
문제는 두 가지입니다. - 결코 끝나지 않는 루프와 내가 알고있는 사용자에게 광고에 로그인 한 친구, 내 앱 등에서 어떤 역할을 받았는지 (사실은 직설적 인 이메일이된다고 가정 함) 주소 비교). 나는 새로운 프로젝트를 볼 것이다. –