我有一个使用web表单编写的遗留应用程序。在这个项目中,我们开始将一些webforms转换为SPA、angular.js和WebAPI。SPA页面直接与WebAPI通信。这个想法是,最终,所有的webforms都将被转换成新技术。
对于SPA页面,我已经实现了adal.js,对于使用ADAL.net的webforms。显然,两者都在使用Azure。然而,他们似乎没有使用相同的无记名令牌,因为单点登录不起作用。从网页移动到SPA页面需要另一个登录。
如何在项目中获得正确工作的单一标志?
我的代码如下:
public void ConfigureAuth( IAppBuilder app )
{
JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>( );
app.SetDefaultSignInAsAuthenticationType( CookieAuthenticationDefaults.AuthenticationType );
app.UseCookieAuthentication( new CookieAuthenticationOptions( ) );
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
Authority = "https://login.microsoftonline.com/XXXXX.onmicrosoft.com",
PostLogoutRedirectUri = "https://XXXX:4432/gbl/Home.aspx",
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthenticationFailed = context =>
{
context.HandleResponse( );
context.Response.Redirect( "/Error?message=" + context.Exception.Message );
return Task.FromResult( 0 );
},
SecurityTokenValidated = async n =>
{
var uniqueName = n.AuthenticationTicket.Identity.FindFirst( "unique_name" ).Value;
var userName = getUserNameFromUniqueName( uniqueName );
var claims = getRoleClaims( n.AuthenticationTicket.Identity ).ToList2( );
claims.Add( new Claim( "unique_name", uniqueName ) );
claims.Add( new Claim( ClaimTypes.Name, userName ) );
claims.Add( new Claim( ClaimTypes.UserData, "" ) );
var profileClaims = new ClaimsTransformer( ).GetTake2ProfileClaims( userName );
claims.AddRange( profileClaims );
var newIdentity = new ClaimsIdentity( n.AuthenticationTicket.Identity.AuthenticationType, "given_name", "roles" );
newIdentity.AddClaims( claims );
n.AuthenticationTicket = new AuthenticationTicket( newIdentity, n.AuthenticationTicket.Properties );
},
}
} );
}发布于 2015-09-01 23:33:12
ADAL和OpenId连接中间件并不是真正设计为协同工作的--您的应用程序是用webforms或MVC实现的,这并没有真正的区别,问题是ADAL希望与通过OAuth2承载令牌保护的后端调用Web进行交互,而OpenId连接则希望通过cookies来保护完整的回发。有关这两种不同方法的背景信息,请参阅http://www.cloudidentity.com/blog/2014/04/22/authentication-protocols-web-ux-and-web-api/。我认为您必须决定是否要迁移到SPA基础设施,在这种情况下,您可以使用ADAL和OAuth2中间件,但是webforms会有点尴尬(但仍然可能),或者如果您想坚持基于回发的设计并使用OpenId连接。
https://stackoverflow.com/questions/32321076
复制相似问题