How do I make a custom authentication provider like LinkedIn
appear in SignInManager.GetExternalAuthenticationSchemes()
from where Login.cshtml
picks up by default
Background Details:
I am trying to understand asp.net core identity framework. In that quest, I created a standard .net core project
I tried out the supported Google
authentication alongside reading the documentation and it all worked fine for me.
I was able to make LinkedIn
authentication work for me, but couldn't understand how to make certain pieces work. To add support for LinkedIn
authentication, I made the following changes
Added the below lines In Startup.Configure
method
app.UseOAuthAuthentication(new OAuthOptions() {
AuthenticationScheme = "LinkedIn",
ClientId = Configuration["Authentication:LinkedIn:ClientID"],
ClientSecret = Configuration["Authentication:LinkedIn:ClientSecret"],
CallbackPath = new PathString("/signin-linkedin"),
AuthorizationEndpoint = "https://www.linkedin.com/oauth/v2/authorization",
TokenEndpoint = "https://www.linkedin.com/oauth/v2/accessToken",
UserInformationEndpoint = "https://api.linkedin.com/v1/people/~:(id,formatted-name,email-address,picture-url)",
Scope = { "r_basicprofile", "r_emailaddress" },
});
Added the required ClientId
and ClientSecret
to the configuration
Added the following line to the Login.cshtml
<button type="submit" class="btn btn-default" name="provider" value="LinkedIn" title="Log in using your LinkedIn account">LinkedIn</button>
All this works fine. Now my question is:
For supported authentication providers, as soon as I call, say, app.UseGoogleAuthentication
in Startup.Configure
, my call to SignInManager.GetExternalAuthenticationSchemes()
in Login.cshtml
lists Google
as a provider. What do I need to do, so the call to SignInManager.GetExternalAuthenticationSchemes()
will also list LinkedIn
as a provider
What do I need to do, so the call to SignInManager.GetExternalAuthenticationSchemes() will also list LinkedIn as a provider
This method only lists the authentication middleware that have been assigned a "display name".
To include Linked in the providers list, set OAuthOptions.DisplayName
:
app.UseOAuthAuthentication(new OAuthOptions
{
DisplayName = "LinkedIn"
// ...
});