0

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?

  • Hi @Abhay I noticed this question is related to this one, sitecore.stackexchange.com/questions/24782/… where I have given an answer on ADFS. Does this work for you? – Julius A Apr 1 at 10:23
  • 1
    thanks for your response Julius , yes implementing provider on IDs is the option I went with to implement this functionality – Abhay Dhar Apr 2 at 11:34
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>
                    }
                } 
| improve this answer | |
  • Thanks for your response, but I am trying this for CM instance. – Abhay Dhar Feb 6 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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