1

I have integrated Federated Authentication.

After user is authenticated, I want to redirect to another page instead of dashboard page.

So, on which pipeline can I write that logic where I can get Sitecore.Context.User.IsAuthenticate true before redirecting to dashboard page?

2 Answers 2

0

As per the Sitecore documents you must create a new processor for the owin.identityProviders pipeline. To create a new processor:

  1. Inherit the Sitecore.Owin.Authentication.Pipelines.IdentityProviders.IdentityProvidersProcessor class.

  2. Override the IdentityProviderName property with the name you specified for the identityProvider in the configuration.

  3. Override the ProcessCore method.

Ref: https://doc.sitecore.com/xp/en/developers/102/sitecore-experience-manager/configure-federated-authentication.html

And in the ProcessCode method, you can add the parameters something like this.

public class AzureADIdentityProviderProcessor : IdentityProvidersProcessor
{
   public AzureADIdentityProviderProcessor(FederatedAuthenticationConfiguration federatedAuthenticationConfiguration, ICookieManager cookieManager, BaseSettings settings) : base(federatedAuthenticationConfiguration, cookieManager, settings)
   {
   }

  protected override void ProcessCore(IdentityProvidersArgs args)
   {
       Assert.ArgumentNotNull(args, nameof(args));

       var identityProvider = this.GetIdentityProvider();
       var authenticationType = this.GetAuthenticationType();
       var saveSigninToken = identityProvider.TriggerExternalSignOut;

       var targetHostName = GetTargetHostName();
       string aadInstance = "https://login.microsoftonline.com/{0}/";
       string tenant = Settings.GetSetting("Foundation.Accounts.SSO.AD.Tenant");
       string clientId = Settings.GetSetting("Foundation.Accounts.SSO.AD.ClientId");
       string clientSecret = Settings.GetSetting("Foundation.Accounts.SSO.AD.ClientSecret");
       string postLogoutRedirectURI = $"{targetHostName}{Settings.GetSetting("Foundation.Accounts.SSO.AD.PostLogoutRedirectURI")}";
       string redirectURI = $"{targetHostName}{Settings.GetSetting("Foundation.Accounts.SSO.AD.RedirectURI")}";
       string scope = Settings.GetSetting("Foundation.Accounts.SSO.AD.Scope");

And add the pipeline here.

<pipelines>
   <owin.identityProviders>
     <processor type="Foundation.Accounts.Services.AzureActiveDirectory.AzureADIdentityProviderProcessor, Foundation.Accounts" resolve="true" />
   </owin.identityProviders>
 </pipelines>

Under this method you can add the provider for RedirectToIdentityProviderAsync like this.

Notifications = new OpenIdConnectAuthenticationNotifications
            {
                RedirectToIdentityProvider = this.RedirectToIdentityProviderAsync,
                SecurityTokenValidated = this.SecurityTokenValidatedAsync
            },

And add the method like below.

private Task RedirectToIdentityProviderAsync(
        RedirectToIdentityProviderNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>
            notification)
{
   // logic
}

Refer to these documents for the whole implementation.

https://rmcdigital.com/sitecore/sitecore-single-sign-on-federated-authentication-with-azure-ad/

https://www.jeroenbreuer.nl/blog/custom-identity-provider-in-sitecore/

Hope this will work for you.

5
  • If I will redirect directly from IdentityProvider then Sitecore.Context.User.IsAuthenticate will not be true
    – Bhawana
    May 25 at 10:14
  • Updated my answer. refer to the articles I have shared. May 25 at 10:58
  • RedirectToIdentityProvider calls at the time of Authentication/Logout/Token not after,where I can access IsAuthenticate
    – Bhawana
    May 26 at 1:54
  • @Bhawana Did you check the second article I have given where they are checking the authentication in this condition? protocolMessage.RequestType == OpenIdConnectRequestType.Authentication May 26 at 6:23
  • Yes I checked in OpenIdConnectRequestType.Authentication, it will give IsAuthenticated as true in second time, not the first time. I just want to know the pipeline where Sitecore set Sitecore.Context.User.IsAuthenticated as true
    – Bhawana
    May 26 at 16:16
0

There are 2 pipelines you can try out to patch your custom processor.

  1. loggedin
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <processors>
            <loggedin>
                <processor patch:before="processor[position()=last()]" method="Process"  mode="on" type="YourCustomProcessor, YourAssembly" resolve="true"/>
            </loggedin>
        </processors>
    </sitecore>
</configuration>
  1. owin.cookieAuthentication.signedIn - If you are using an identity server for federated authentication this pipeline should work fine.
<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <owin.cookieAuthentication.signedIn>
        <processor  patch:before="*[@type='Sitecore.Owin.Authentication.Pipelines.CookieAuthentication.SignedIn.CreateTicket, Sitecore.Owin.Authentication']"
            type="YourCustomProcessor, YourAssembly" resolve="true"/>
      </owin.cookieAuthentication.signedIn>
    </pipelines>
  </sitecore>
</configuration>

Hope it helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.