Trouble Signing in with Apple
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.