IdentityServer4 link directly to Facebook authentication

Viewed 1904

I have an IdentityServer4 app which has Facebook integration, this is working fine.

I also have an Angular2 app that makes use of the IdentityServer. Currently if the user wants to log in via Facebook they have to click 'login' which takes them to the IdentityServer and then click on the Facebook button.

I want to have a 'Facebook' button on my Angular app which then automatically redirects them straight to Facebook, bypassing the main login screen.

I noticed the following line the the code:

public async Task<IActionResult> Login(string returnUrl)
{
    ...
    if (vm.IsExternalLoginOnly)
    {
        // only one option for logging in
        return ExternalLogin(vm.ExternalProviders.First().AuthenticationScheme, returnUrl);
    }
    ...
}

Which is basically what I want, automatically redirect to Facebook. So I added the following method:

public async Task<IActionResult> FacebookLogin(string returnUrl)
{
    var vm = await _account.BuildLoginViewModelAsync(returnUrl);

    // only one option for logging in
    return ExternalLogin(vm.ExternalProviders.First(x => x.DisplayName.ToUpper() == "FACEBOOK").AuthenticationScheme, returnUrl);
}

While this does redirect straight to Facebook and does authenticate, it doesn't redirect back to the calling app. I can see errors logged regarding invalid redirectUri, I assume this is because I'm not calling connect/authorize?

So is there a way to pass an additional parameter to connect/authorize to specify to use Facebook that I can then use in my controller, or call a different method?

Thanks

1 Answers
Related