Я прочитал это и это , и, насколько я понимаю, это не помогло мне решить мою проблему.
Фрагменты кода
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
var options = new OpenIdConnectAuthenticationOptions
{
// These are standard OpenID Connect parameters, with values pulled from web.config
ClientId = clientId,
RedirectUri = redirectUri,
PostLogoutRedirectUri = redirectUri,
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthenticationFailed = OnAuthenticationFailed,
RedirectToIdentityProvider = OnRedirectToIdentityProvider,
AuthorizationCodeReceived = OnAuthorizationCodeReceived,
SecurityTokenValidated = OnSecurityTokenValidated
},
Scope = "openid offline_access",
ResponseType = "code id_token",
// The PolicyConfigurationManager takes care of getting the correct Azure AD authentication
// endpoints from the OpenID Connect metadata endpoint. It is included in the PolicyAuthHelpers folder.
ConfigurationManager = new PolicyConfigurationManager(
string.Format(CultureInfo.InvariantCulture, aadInstance, tenant, "/v2.0", OIDCMetadataSuffix),
new[] { GlobalSignInPolicyId, GlobalResetPasswordPolicyId }),
// This piece is optional - it is used for displaying the user's name in the navigation bar.
TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = "name",
SaveSigninToken = true
}
};
app.UseOpenIdConnectAuthentication(options);
}
Следующий метод не срабатывает
private async Task OnAuthorizationCodeReceived(AuthorizationCodeReceivedNotification notification)
{
notification.AuthenticationTicket.Identity.AddClaim(new Claim("code", notification.Code));
}
OnRedirectToIdentityProvider
стреляет.
Мы используем Framework 4.6.2 - Microsoft.Owin версия 3.0.1.0
Странно то, что я взял код из другого проекта (назовите его Project A), который работает, но мой проект (назовите его Project B) - нет. Если я предоставлю Проект A, мои учетные данные OnAuthorizationCodeReceived
по-прежнему будут срабатывать. Если я возьму учетные данные проекта А и введу их в проект B OnAuthorizationCodeReceived
, он не будет запущен. Поэтому я думаю, что могу исключить проблему конфигурации.
Один ключевой момент, который я, возможно, пропустил: Проект A - это проект MVC, а Проект B - проект Asp.net WebForms