.NET Sign In With Apple - Incorrect Redirect After Login

27 Views Asked by At

I have set up Sign In With Apple on my .NET 7 web app using AspNet.Security.OAuth.Apple. It appears to be working - I visit my action to redirect me to challenge the Apple scheme, I am then able to login. It passes back to my website, but for some reason, after authenticating it passes me back to my AppleLogin action rather than the `/signin-apple' that it should do.

This basically puts it in a loop where I login and it passes me right back again!

Using other providers (Facebook, Google) the redirect back to /signin-facebook and signin-google ok, so I'm not sure why its not working for Apple.

From Startup.cs

.AddApple()
    .Services
    .AddOptions<AppleAuthenticationOptions>(AppleAuthenticationDefaults.AuthenticationScheme)
    .Configure<IConfiguration, IServiceProvider>((options, configuration, serviceProvider) =>
    {
        options.AccessDeniedPath = "/denied";
        options.ClientId = "com.rackemapp.applelogin";
        options.KeyId = "*********";
        options.TeamId = "*********";

        var environment = serviceProvider.GetRequiredService<IHostEnvironment>();
        options.UsePrivateKey(
            keyId =>
                environment.ContentRootFileProvider.GetFileInfo($"/Certs/AuthKey_{keyId}.p8"));

    });

The action that I use to kickstart the process - this is where Apple seemingly erroneously redirects back to after a login

public IActionResult AppleLogin(string invitecode = null, bool mobile = false)
{
    return Challenge("Apple");
}
1

There are 1 best solutions below

0
Arjen Sarı On
var properties = new AuthenticationProperties
{
RedirectUri = Url.Action("ExternalLoginCallback"),
AllowRefresh = true
};
return Challenge(properties,provider); 

provider is "Apple"