We are upgrading our existing site from Sitecore 8.2
to Sitecore 9.3
.
We are using federated authentication
for our CD site with OAuth2.0
. The login to the site is working as expected but in the further requests, the value of the .AspNet.Cookies
cookie changes which causes unexpected behavior in other pages of the site.
In the first request, after the user enters their credential to login to the site, the .AspNet.Cookies
stores below value (after decryption) -
Using the Microsoft.Owin.Security.Cookies-SessionId
, we get the ticket value (decrypted) stored in database -
Now, if I navigate to some other page, the decrypted value of .AspNet.Cookies
cookie changes to -
In Sitecore 8.2
, the value of the cookie remains same but this is happening after upgrading to Sitecore 9.3
.
Can anybody please suggest what we are missing here?
IdentityProvidersProcessor
Code -
using System;
using System.Collections.Generic;
using System.Linq;
using Project.Configuration;
using Project.Models;
using Microsoft.Owin.Infrastructure;
using Microsoft.Owin.Security.OAuth;
using Owin;
using Sitecore.Abstractions;
using Sitecore.Configuration;
using Sitecore.Diagnostics;
using Sitecore.Owin.Authentication.Configuration;
using Sitecore.Owin.Authentication.Pipelines.IdentityProviders;
using Sitecore.Web;
namespace Project.Feature.Login.Providers
{
[CLSCompliant(false)]
public class AzureAdB2OAuthBearerIdentityProvider : IdentityProvidersProcessor
{
protected override string IdentityProviderName => "AzureAD";
public AzureAdB2OAuthBearerIdentityProvider(
FederatedAuthenticationConfiguration federatedAuthenticationConfiguration,
ICookieManager cookieManager,
BaseSettings settings) :
base(federatedAuthenticationConfiguration, cookieManager, settings)
{
}
protected override void ProcessCore(IdentityProvidersArgs args)
{
Assert.ArgumentNotNull(args, nameof(args));
List<SiteInfo> siteInfoList = Factory.GetSiteInfoList();
IEnumerable<OAuthSiteInfo> sites =
siteInfoList.Select(s => new OAuthSiteInfo(s)).Where(s => s.UsesOauth);
CookieAuthentication.ConfigureCookieAuthentication(args.App);
foreach (OAuthSiteInfo site in sites)
{
// NOTE [ILs] SXA allows adding multiple hostnames to be matched seperated by |
foreach (string hostname in site.HostName.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries))
{
args.App.UseOAuthBearerAuthentication(CreateOptionsFromSiteInfo(site));
}
}
}
private OAuthBearerAuthenticationOptions CreateOptionsFromSiteInfo(OAuthSiteInfo site)
{
return new OAuthBearerAuthenticationOptions()
{
AccessTokenProvider = new OAuthBearerAuthenticationTokenProvider(FederatedAuthenticationConfiguration, GetIdentityProvider()),
Provider = new OAuthBearerAuthenticationProvider(site, FederatedAuthenticationConfiguration, GetIdentityProvider())
};
}
}
}