I had done SSO authentication which is working locally and on-premise, when I deployed on AWS, it was not working on Chrome but working on Mozilla.
public class ProjectIdentityProvider : IdentityProvidersProcessor
{
private readonly ICookieManager cookieManager;
public ProjectIdentityProvider(
FederatedAuthenticationConfiguration federatedAuthenticationConfiguration,
ICookieManager cookieManager,
BaseSettings settings) : base(federatedAuthenticationConfiguration, cookieManager, settings)
{
this.cookieManager = cookieManager ?? throw new ArgumentNullException(nameof(cookieManager));
}
protected override void ProcessCore(IdentityProvidersArgs args)
{
var authenticationType = this.GetAuthenticationType();
var identityProvider = this.GetIdentityProvider();
var saveSigninToken = identityProvider.TriggerExternalSignOut;
var oidcOptions = this.SetupOidcOptions(authenticationType, saveSigninToken);
args.App.UseOpenIdConnectAuthentication(oidcOptions);
}
public OpenIdConnectAuthenticationOptions SetupOidcOptions(
string authenticationType,
bool saveSigninToken)
{
var oidcOptions = new OpenIdConnectAuthenticationOptions
{
AuthenticationType = authenticationType,
Authority = authority,
ClientId = clientId,
ClientSecret = clientSecret,
ResponseType = OpenIdConnectResponseType.IdTokenToken,
RedirectUri = redirectUri,
PostLogoutRedirectUri = postLogoutRedirectUri,
Scope = OpenIdConnectScope.OpenIdProfile + " " + OpenIdConnectScope.OfflineAccess,
SaveTokens = true,
Notifications = new OpenIdConnectAuthenticationNotifications
{
RedirectToIdentityProvider = this.RedirectToIdentityProviderAsync,
SecurityTokenValidated = this.SecurityTokenValidatedAsync,
AuthenticationFailed = (context) =>
{
if (context.Exception.Message.Contains(errorCode))
{
context.SkipToNextMiddleware();
}
return Task.FromResult(true);
}
},
TokenValidationParameters =
{
SaveSigninToken = saveSigninToken
},
};
return oidcOptions;
}
protected override string IdentityProviderName => "ProjectIdentityProvider";
protected BaseLog Log { get; }
public Collection<string> Scopes { get; } = new Collection<string>();
private Task RedirectToIdentityProviderAsync(
RedirectToIdentityProviderNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>
notification)
{
var owinContext = notification.OwinContext;
var protocolMessage = notification.ProtocolMessage;
var user = Sitecore.Context.User;
if (protocolMessage.RequestType == OpenIdConnectRequestType.Authentication)
{
protocolMessage.RedirectUri = postLogoutRedirectUri;
}
if (protocolMessage.RequestType == OpenIdConnectRequestType.Logout)
{
protocolMessage.PostLogoutRedirectUri = postLogoutRedirectUri;
protocolMessage.IdTokenHint = this.GetIdTokenHint(owinContext);
}
return Task.CompletedTask;
}
private Task SecurityTokenValidatedAsync(SecurityTokenValidatedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions> notification)
{
var identityProvider = this.GetIdentityProvider();
var identity = notification.AuthenticationTicket.Identity;
foreach (var current in identityProvider.Transformations)
{
current.Transform(identity, new TransformationContext(this.FederatedAuthenticationConfiguration, identityProvider));
}
return Task.CompletedTask;
}
}