我在.net MVC4上使用AAD登录, 返回的token是有的
我解析这个token发现登录是成功的
但是 request的 IsAuthenticated的状态一直是false,Claims也是空的
web.config
求解!
我在.net MVC4上使用AAD登录, 返回的token是有的
1、检查是否配置了令牌缓存,如果没有,则需要在Startup.Auth.cs中配置:
app.UseTokenCache();
2、检查是否正确配置了OpenID Connect 验证流,如果没有,则需要在Startup.Auth.cs中配置:
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
// 省略其他配置
});
3、检查是否配置了Microsoft.Owin.Security.Cookies,如果没有,则需要在Startup.Auth.cs中配置:
app.UseCookieAuthentication(
new CookieAuthenticationOptions
{
// 省略其他配置
});
4、检查是否在授权回调URL中配置了allowImplicitFlow参数,如果没有,则需要在Startup.Auth.cs中配置:
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
// 省略其他配置
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthorizationCodeReceived = OnAuthorizationCodeReceived
},
AuthenticationMode = AuthenticationMode.Active,
ClientId = clientId,
Authority = Authority,
PostLogoutRedirectUri = postLogoutRedirectUri,
RedirectUri = redirectUri,
Scope = OpenIdConnectScope.OpenIdProfile,
ResponseType = OpenIdConnectResponseType.IdToken,
TokenValidationParameters = new TokenValidationParameters
{
// 省略其他配置
},
AllowImplicitFlow = true
});
5、检查是否在授权回调中调用了SignIn或SignInAsync,如果没有,则需要在OnAuthorizationCodeReceived函数中调用:
// Sign in the user
await HttpContext.GetOwinContext().Authentication.SignInAsync(
OpenIdConnectAuthenticationDefaults.AuthenticationType,
userInfo.Identity);