I am using ASP.NET Core 2.0 Web API to create application with authentication. I want to login using "login/password" combination and using Facebook. I am using JWT tokens for authorization. From Startup.cs I am calling extension method RegisterAuth.
public static void RegisterAuth(this IServiceCollection services, AuthSettings authSettings)
{
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.SaveToken = true;
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = false,
ValidateLifetime = true,
ValidateIssuerSigningKey = false,
ValidIssuer = authSettings.Issuer,
ValidAudience = authSettings.Audience,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(authSettings.SecretKey))
};
})
.AddFacebook(facebookOptions =>
{
facebookOptions.AppId = authSettings.Facebook.AppId;
facebookOptions.AppSecret = authSettings.Facebook.AppSecret;
facebookOptions.SignInScheme = "Bearer";
});
}
In my controller I have 2 methods. Login for "login/password" combination which it works and returns me jwt token. And SignIn for facebook which does not work.
[Route("SignIn/{provider}")]
public IActionResult SignIn(string provider)
{
return Challenge(new AuthenticationProperties(), provider);
}
SignIn redirects to the facebook page from where after signing in it throws an exception.
InvalidOperationException: No IAuthenticationSignInHandler is configured to handle sign in for the scheme: Bearer
So please help me to fix Facebook Auth. Thank you!