Trouble Signing in with Apple

Stesvis 1,041 Reputation points
2021-01-19T21:04:20.513+00:00

I am trying to implement the backend to sign-in with Apple but it's not working yet and I need some help.

Startup.cs

services.AddAuthentication(options =>
{
    // some options
})
// Adding Jwt Bearer
.AddJwtBearer(options =>
{
    options.SaveToken = true;
    options.RequireHttpsMetadata = false;
    options.TokenValidationParameters = new TokenValidationParameters()
    {
        ValidateIssuer = true,
        ValidateAudience = true,
        ValidAudience = Configuration["JWT:ValidAudience"],
        ValidIssuer = Configuration["JWT:ValidIssuer"],
        IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["JWT:Secret"]))
    };
})
.AddCookie()
.AddFacebook(options =>
{
    // some options
})
.AddGoogle(options =>
{
    // some options
})
.AddApple(a =>
{
    a.ClientId = Configuration["Authentication:Apple:ClientId"];
    a.KeyId = Configuration["Authentication:Apple:KeyId"];
    a.TeamId = Configuration["Authentication:Apple:TeamId"];
    a.UsePrivateKey(keyId => this.env.ContentRootFileProvider.GetFileInfo($"AuthKey_{keyId}.p8"));
    a.SaveTokens = true;
});

Then I have an endpoint /api/oauth/{scheme} and I have the code found in this sample:
https://github.com/xamarin/Essentials/blob/develop/Samples/Sample.Server.WebAuthenticator/Controllers/MobileAuthController.cs#L20

Everything works with Facebook and Google, but it's not working with Apple.
If I go to https://mysite.com/api/oauth/apple i am presented with the authentication page from Apple, then I can sign in successfully, but at that point I get an error.

With Facebook and Google, it redirects you back to an endpoint like https://mysite.com/signin-facebook and then redirects back to your callbackScheme, but with Apple that endpoint fails.

So I am stuck here and not sure what's wrong.

Test: https://api.tradeality.com/api/OAuth/Apple

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,357 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,573 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,962 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.