1

Trying to implement Federated Authentication with ADFS for Sitecore 9.2 CM Instance, Following this blog post -

http://blog.nikkipunjabi.com/2018/03/sitecore-federated-authentication-part-2-google-and-facebook-app-and-the-custom-processor.html

But Unable to get the buttons for Facebook or Google to come up on the screen. Do I need to implement anything else as well

Or since this is Identity Server I need to implement a sub-provider within the Sitecore Identity server website for the same?

3

2 Answers 2

0
[Service(typeof(IFedAuthLoginButtonService))]
public class FedAuthLoginButtonService : IFedAuthLoginButtonService
{
    #region Constructor

    /// <summary>
    /// Initializes a new instance of the <see cref="FedAuthLoginButtonService"/> class.
    /// </summary>
    /// <param name="pipelineManager">The base core pipeline manager.</param>
    public FedAuthLoginButtonService(BaseCorePipelineManager pipelineManager)
    {
        this.PipelineManager = pipelineManager;
        this.GetRedirectUrlService = new GetRedirectUrlService();
    }

    #endregion

    #region Properties

    /// <summary>
    /// Gets the pipeline manager.
    /// </summary>
    /// <value>
    /// The pipeline manager.
    /// </value>
    private BaseCorePipelineManager PipelineManager { get; }

    /// <summary>
    /// Gets the redirect url service.
    /// </summary>
    /// <value>
    /// The the redirect url service.
    /// </value>
    private GetRedirectUrlService GetRedirectUrlService { get; }

    #endregion

    /// <summary>
    /// Gets all login buttons for the custom identity providers.
    /// </summary>
    /// <returns>list of <see cref="FedAuthLoginButtonModel" />/></returns>
    public IEnumerable<FedAuthLoginButtonModel> GetAll()
    {
        var returnUrl = this.GetRedirectUrlService.GetRedirectUrl(AuthenticationStatus.Authenticated);
        var args = new GetSignInUrlInfoArgs(Context.Site.Name, returnUrl);
        GetSignInUrlInfoPipeline.Run(this.PipelineManager, args);
        if (args.Result == null)
        {
            throw new InvalidOperationException("Could not retrieve federated authentication logins");
        }
        return args.Result.Select(CreateFedAuthLoginButton).ToArray();
    }

    #region Subroutines

    private static FedAuthLoginButtonModel CreateFedAuthLoginButton(SignInUrlInfo signInInfo)
    {
        var caption = signInInfo.IdentityProvider;
        string iconClass = null;
        switch (signInInfo.IdentityProvider.ToLower())
        {
            case "facebook":
                iconClass = "fab fa-facebook-square";
                break;
            case "google":
                iconClass = "fa fa-google-plus-square";
                break;
            case "linkedin":
                iconClass = "fa fa-linkedin";
                break;
            case "twitter":
                iconClass = "fa fa-twitter";
                break;
            default:
                iconClass = "fa fa-cloud";
                break;
        }

        return new FedAuthLoginButtonModel
        {
            Provider = signInInfo.IdentityProvider,
            IconClass = iconClass,
            Href = signInInfo.Href,
            Caption = caption,
        };
    }

    #endregion
}



Try to implement this and get the list of buttons wherever you want like this:


@if (Model.LoginButtons.Any())
                {
                    foreach (var loginLink in Model.LoginButtons)
                    {
                        <form action="@loginLink.Href" method="post" class="form- 
signin">
                            @if (!string.IsNullOrWhiteSpace(loginLink.IconClass))
                            {
                                <button onclick=""><i class="@loginLink.IconClass" 
style="line-height: 0;"></i></button>
                            }
                        </form>
                    }
                } 
1
  • Thanks for your response, but I am trying this for CM instance.
    – Abhay Dhar
    Feb 6, 2020 at 17:02
0

We just need to add the , and that will automatically add the button. Reference: http://blog.nikkipunjabi.com/2018/02/sitecore-federated-authentication-part-1-authentication-google-facebook-identity-providers.html

<identityProvider id="Google" type="Sitecore.Owin.Authentication.Configuration.DefaultIdentityProvider, Sitecore.Owin.Authentication">
  <param desc="name">$(id)</param>
  <param desc="domainManager" type="Sitecore.Abstractions.BaseDomainManager" resolve="true" />
  <!--This text will be showed for button-->
  <caption>Log in with Google</caption>
  <icon>/sitecore/shell/themes/standard/Images/24x24/Google.jpg</icon>
  <!--Domain name which will be added when create a user-->
  <domain>sitecore</domain>
  <triggerExternalSignOut>true</triggerExternalSignOut>
  <!--list of identity transfromations which are applied to the provider when a user signin-->
  <transformations hint="list:AddTransformation">
    <!--SetIdpClaim transformation-->
    <transformation name="set idp claim" type="Sitecore.Owin.Authentication.Services.SetIdpClaimTransform, Sitecore.Owin.Authentication" />
  </transformations>
</identityProvider> 

Also make sure you check the comment added in this page http://blog.nikkipunjabi.com/2018/03/sitecore-federated-authentication-part-2-google-and-facebook-app-and-the-custom-processor.html.

That resolved the cookie related issues we faced.

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.