[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>
}
}