Git Product home page Git Product logo

appleauth-net's Introduction

NuGet

What is AppleAuth.NET?

AppleAuth is a very simple library for .NET that encapsulates the logic for communicating with Apple's REST API for Sign in with Apple. The main goal is to make the implementation of Sign in with Apple easier for any web application.

How to use it?

Installation

To install the package execute the following command in your Package Manager Console:

PM> Install-Package AppleAuth.NET

Or alternatively just install the package using Nuget package manager. The project can be found here: Link to NuGet

Prerequisites

Configure Sign in with Apple from the Developer Portal

In order to use Sign in with Apple you must enroll in the Apple Developer Program. After you have enrolled in the program go to Developer Account Help and navigate to Configure app capabilities > Sign in with Apple. There you can find the information for configuring Sign in with Apple for your app.

You can also checkout my blogpost for more information on setting the settings in your developer account implementing Sign in with Apple.

Display the "Sign in with Apple" button

Next, you have to configure your web page for Sign in with Apple. Follow the guidelines from the official documentation. You can also refer to this link to see how to setup the styles of the buttons.

Configure your hosting environment

If you are deploying your app to an Azure Web App make sure you add the following setting: WEBSITE_LOAD_USER_PROFILE = 1, so IIS can access the private key storage under the user account store. You can apply this from the Azure portal from Configuration > Application Settings, or you can run the following command in Cloud Shell:
az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings WEBSITE_LOAD_USER_PROFILE=1.
It's also important to note that this setting is available only for non-shared pricing tiers.

If you are deploying your app to your own webserver, running Microsoft IIS, you'll need to enable "Load User Profile" under "Advanced settings" on your Application Pool. Otherwise you'll get a CryptographicException saying "The system cannot find the file specified".

Example

Using AppleAuthProvider.cs

Create new instance of AppleAuthProvider, pass the required parameters and you are good to go. Use the GetAuthorizationToken method to get an authorization token from Apple; Use the GetRefreshToken method to verify if a user is still using 'Sign in with Apple' to sign in your system; Use the GetButtonHref method to get a query string for the 'Sign in with Apple' button.

Handling initial response from Apple

After the user clicks on the "Sign in with Apple" button on your page they will be redirected to https://appleid.apple.com/. After they provide their credentials Apple will make a POST request to the url that you have specified as Redirect URL. You can handle the request using InitialTokenResponse.cs. In order to retrieve an authorization token you should first create new instance of AppleAuthProvider with the required parameters. After that just call GetAuthorizationToken() method passing code from your InitialTokenResponse object and your private key. Here is a sample implementation in C#:

        [HttpPost]
        public async Task HandleResponseFromApple(AppleAuth.TokenObjects.InitialTokenResponse response)
        {
            string privateKey = System.IO.File.ReadAllText("path/to/file.p8");

            AppleAuth.AppleAuthProvider provider = new AppleAuth.AppleAuthProvider("MyClientID", "MyTeamID", "MyKeyID", "MyRedirectUrl", "SomeState");

            AppleAuth.TokenObjects.AuthorizationToken authorizationToken = await provider.GetAuthorizationToken(response.code, privateKey);
        }

Keep in mind that tokens returned from Apple are short-lived, so you should create a session or a user in your system using the returned AppleAuth.TokenObjects.AuthorizationToken object. After that you can verify if the user is still logged in using "Sign in with Apple" by retrieving a refresh token using the GetRefreshToken method:

        [HttpPost]
        public async Task<bool> IsUserUsingAppleID()
        {
            string privateKey = System.IO.File.ReadAllText("path/to/file.p8");

            AppleAuth.AppleAuthProvider provider = new AppleAuthProvider("MyClientID", "MyTeamID", "MyKeyID", "https://myredirecturl.com/HandleResponseFromApple", "SomeState");

            AppleAuth.TokenObjects.AuthorizationToken refreshToken = await provider.GetRefreshToken(authorizationToken.RefreshToken, privateKey);

            return refreshToken != null;
        }

Contributing

You are more than welcome to contribute to the project and make it better. When contributing please try to maintain a strictly professional, respectful and friendly attitude. Also make sure you communicate the change you want to make via issue or any other method with the owners of this repository.

Creating a pull request

We do not have any strict guidelines for creating pull requests, but you can use the already known GitHub flow for general guidelines.

License

This project is licensed under the MIT License - see LICENSE.md for details

appleauth-net's People

Contributors

ari-zelanko-autopoint avatar danailstoichkov avatar drgrieve avatar nkovacic avatar rh101 avatar scottluskcis avatar sunecko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

appleauth-net's Issues

The System Cannot Find The File Specified.

Hello, after I'm trying to get the authorizationToken using the following line of code:
AuthorizationToken authorizationToken = await provider.GetAuthorizationToken(response.code, privateKey);
The code runs into catch with the error message "The system cannot find the file specified".
I am using the below function to handle the initial response.

[HttpPost]
public async Task HandleResponseFromApple(InitialTokenResponse response)
{
string privateKey = "privatekey";

AppleAuth.AppleAuthProvider provider = new AppleAuth.AppleAuthProvider("MyClientID", "MyTeamID", "MyKeyID", "MyRedirectUrl", "SomeState");

AuthorizationToken authorizationToken = await provider.GetAuthorizationToken(response.code, privateKey);

}

Get FirstName and LastName of user from Apple

Glad to find this, I need to know how and where I can find the First Name and the Last Name received from Apple,
with web API by given id_token
and if the response from apple doesn't contain such data, so How can we get them?

What is private key on localhost?

Dear Contributors,

string privateKey = System.IO.File.ReadAllText("path/to/file.p8");

What is this file, how can we get this on localhost / not Azure?

Android redirect url generator

I had to implement my own URL generator for redirect url on Android. I think it's a good idea to include this support in the library

JWT Token Generation issue results in invalid_client error

For some reason after December 2022, using this library stopped working for me.

After extensive debugging it seems like for some reason Apple servers don't like tokens generated using .net

I extracted the code from GetAuthorizationToken to debug and experiment on it. Even tho the generated JWT seems to completely fine and appropriate when checking it on https://jwt.io, I get an invalid_client error.

I discovered the issue is the JWT token generation because if I generate it using some simple nodejs code it works.

Consider this code:

var restClient = new AppleRestClient();
var appleClientSecret = new TokenGenerator().GenerateAppleClientSecret(privateKey, appleOAuthSettings.TeamId, appleOAuthSettings.ClientId, appleOAuthSettings.KeyId);
var requestMessage = restClient.GenerateRequestMessage("authorization_code", authorizationCode, appleClientSecret, appleOAuthSettings.ClientId, appleOAuthSettings.RedirectUrl);
var response = await restClient.SendRequest(requestMessage);
var tokenResponse = JsonSerializer.Deserialize<AuthorizationToken>(response);

If I replace the value of appleClientSecret with a JWT that has the exact same properties and was made using the same key, as verified with https://jwt.io, but using nodejs, the rest of the code will work properly. Instead of an invalid_client error I just get the expected output.

Here is the nodejs code I used to generate the token (taken from https://www.npmjs.com/package/apple-auth):

const jwt = require("jsonwebtoken")

let exp = Math.floor(Date.now() / 1000) + ( 86400 * 180 ); // Make it expire within 6 months

const claims = {
    iss: teamId,
    iat: Math.floor(Date.now() / 1000),
    exp,
    aud: 'https://appleid.apple.com',
    sub: clientId,
};

jwt.sign(claims, privateKey, { algorithm: 'ES256', keyid }, (err, token) => {
    console.log(token)
});

I am not sure if anyone else is dealing with this issue or what the cause may be, it has stunlocked me for months. Any help would be appreciated.

invalid_grant error

When calling GetAuthorizationToken, I'm getting an error with the following message: "invalid_grant"

I'm not sure I'm providing the correct clientId to the AppleAuthProvider constructor.

Documentation comments say that it's a 10-character key identifier also known as Service ID, but I cannot find such string in the developer console. I tried several 10-character and reversed domain values, but I'm still getting that error.

Does it ring a bell to someone? Thanks!

/// A10-character key identifier obtained from your developer account. (aka "Service ID" that is configured for “Sign In with Apple”)
/// A 10-character key identifier obtained from your developer account.
/// A 10-character key identifier obtained from your developer account. Configured for "Sign In with Apple"
/// URL to which the user will be redirected after successful verification.
/// You need to configure a verified domain and map the redirect URL to it. Can’t be an IP address or localhost
/// Can be used for any internal identifiers (e.g. Session IDs, User IDs, Query Strings, etc.)
public AppleAuthProvider(string clientId, string teamId, string keyId, string redirectUrl, string state)
{

How to access user's name in addition to email?

I'm authenticating with the scope of "name email" but I'm only getting the email in id_token. I've seen #7 but that issue is closed without an actual answer. It says that I can only access name data only on first request, which is fine, but doesn't tell how to access it in the first request.

If I can get the user's name only on the first request, then, how do I access user's name on the first request?

Adjust the exp of client secret

Is it possible to make this a configurable value? It looks like in TokenGenerator class in GenerateClientSecret this is set with an exp of 5 min?

public string GenerateAppleClientSecret(string privateKey, string teamId, string clientId, string keyId)

I would like for a way to make this longer but not seeing this is supported. Before I fork the repo and add a change is this something anyone has already added or plan to?

.Net Core version

I have a fork that compiles to .NETCore. Wasn't difficult at all. Was wondering if this would be useful to you?

HowTo: Retrieve user information.

Hello,

can you please tell me how I can retrieve some additional user information?
I have received the initial token and then I received a successful response of type "AppleAuth.TokenObjects.AuthorizationToken" in the method "HandleResponseFromApple", is there a way to get user first name and last name?

Thanks

Support .NET 4.7.2

Hello,
is it possible also to target .NET Framework? I need it for old asp.net forms project which doesn't build properly with .NET Standard 2.0. NET 4.7.1 or lower will do

invalid_grant error

I'm trying to implement this plugin, however I keep getting the "invalid_grant" error.

I've set up an "Apple Sign In" service in my Apple developer account, and I'm using the key id from this service.

However I'm using null for the redirect URL, as I'm using this in conjunction with an app. This means there's no redirect going on, as the server is merely validating the token.

Could this be why, and if that's the case, how do I go about solving it?

An Error Occurred While Sending The Request.

Hey, I'm trying to get the authorization token, using the code below:
AuthorizationToken authorizationToken = await provider.GetAuthorizationToken(response.code, privateKey);
However, I'm getting the following error: "An error occurred while sending the request.". Kindly find below the redirect Uri API I'm using:

[HttpPost]
public async Task HandleResponseFromApple(InitialTokenResponse response)
{
    string privateKey = System.IO.File.ReadAllText("path/to/file.p8");

    AppleAuthProvider provider = new AppleAuthProvider("MyClientID", "MyTeamID", "MyKeyID", "MyRedirectUrl", "SomeState");

    AuthorizationToken authorizationToken = await provider.GetAuthorizationToken(response.code, privateKey);
}

Hosting on Azure

Hi! Thanks for this library it is really useful.

Just a quick suggestion you might want to add to your readme.

For this code to work in an Azure web app the setting WEBSITE_LOAD_USER_PROFILE = 1 needs to be added to the web app settings in the Azure portal to allow the code to access the key store when it imports the private key needed to create the Apple secret (see https://stackoverflow.com/a/49649930/1162133). Otherwise the code will fail here (https://github.com/Accedia/appleauth-net/blob/master/Cryptography/TokenGenerator.cs#L34) with a file not found exception.

Thanks!

GetAuthorizationToken fail on linux system

this lib always fine. on my debug flow.
but publish code to my linux server always fail.
this my error code. can you help me?
System.PlatformNotSupportedException: at System.Security.Cryptography.CngKeyBlobFormat.get_Pkcs8PrivateBlob (System.Security.Cryptography.Cng, Version=4.3.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a) at AppleAuth.Cryptography.TokenGenerator.GenerateAppleClientSecret (AppleAuth, Version=1.0.2.0, Culture=neutral, PublicKeyToken=null) at AppleAuth.AppleAuthProvider+<GetAuthorizationToken>d__23.MoveNext (AppleAuth, Version=1.0.2.0, Culture=neutral, PublicKeyToken=null) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at UserSystem.Api.UsersController+d__11.MoveNext (UserSystem, Version=0.0.0.109, Culture=neutral, PublicKeyToken=nullUserSystem, Version=0.0.0.109, Culture=neutral, PublicKeyToken=null: C:\Jenkins\workspace\MultiTrim\Backend\UserSystem\Api\UsersController.csUserSystem, Version=0.0.0.109, Culture=neutral, PublicKeyToken=null: 148)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter1.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor+TaskOfIActionResultExecutor+<Execute>d__0.MoveNext (Microsoft.AspNetCore.Mvc.Core, Version=3.1.14.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Threading.Tasks.ValueTask1.get_Result (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.ValueTaskAwaiter1.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker+<<InvokeActionMethodAsync>g__Logged|12_1>d.MoveNext (Microsoft.AspNetCore.Mvc.Core, Version=3.1.14.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker+<<InvokeNextActionFilterAsync>g__Awaited|10_0>d.MoveNext (Microsoft.AspNetCore.Mvc.Core, Version=3.1.14.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow (Microsoft.AspNetCore.Mvc.Core, Version=3.1.14.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next (Microsoft.AspNetCore.Mvc.Core, Version=3.1.14.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync (Microsoft.AspNetCore.Mvc.Core, Version=3.1.14.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker+<<InvokeNextResourceFilter>g__Awaited|24_0>d.MoveNext (Microsoft.AspNetCore.Mvc.Core, Version=3.1.14.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow (Microsoft.AspNetCore.Mvc.Core, Version=3.1.14.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next (Microsoft.AspNetCore.Mvc.Core, Version=3.1.14.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync (Microsoft.AspNetCore.Mvc.Core, Version=3.1.14.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker+<<InvokeAsync>g__Logged|17_1>d.MoveNext (Microsoft.AspNetCore.Mvc.Core, Version=3.1.14.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.AspNetCore.Routing.EndpointMiddleware+<<Invoke>g__AwaitRequestTask|6_0>d.MoveNext (Microsoft.AspNetCore.Routing, Version=3.1.14.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware+<Invoke>d__5.MoveNext (Microsoft.AspNetCore.Authorization.Policy, Version=3.1.14.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at IdentityServer4.Hosting.IdentityServerMiddleware+<Invoke>d__3.MoveNext (IdentityServer4, Version=3.0.0.0, Culture=neutral, PublicKeyToken=f294d0afe402bb2b) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at IdentityServer4.Hosting.MutualTlsTokenEndpointMiddleware+<Invoke>d__4.MoveNext (IdentityServer4, Version=3.0.0.0, Culture=neutral, PublicKeyToken=f294d0afe402bb2b) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware+<Invoke>d__6.MoveNext (Microsoft.AspNetCore.Authentication, Version=3.1.14.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at IdentityServer4.Hosting.BaseUrlMiddleware+<Invoke>d__3.MoveNext (IdentityServer4, Version=3.0.0.0, Culture=neutral, PublicKeyToken=f294d0afe402bb2b) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware+<Invoke>d__6.MoveNext (Microsoft.AspNetCore.Authentication, Version=3.1.14.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware+<<Invoke>g__Awaited|6_0>d.MoveNext (Microsoft.AspNetCore.Diagnostics, Version=3.1.14.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)

Potential NullReferenceException in SetUserInformation

Glad to find this so that I can try out an alternative implementation to my own. I've been getting the dreaded invalid_client response from Apple. With your library, I'm getting a NullReferenceException. I'm not sure what is going on (Apple Sign-In used to work for us and no code changes were applied) but I wanted to report back that there is a potential NullRef exception in the method SetUserInformation.

System.NullReferenceException: Object reference not set to an instance of an object.
   at AppleAuth.AppleAuthProvider.SetUserInformation(AuthorizationToken tokenResponse)
   at AppleAuth.AppleAuthProvider.<GetAuthorizationToken>d__23.MoveNext()

Looking at your source, either deserializeUserInformation is null, or deserializeUserInformation.Claims is null or auth_time is null.

Retrieve User Information

What kind of way should I follow to access the username and surname in the steps after the first login?

I see that there are not enough answers to the requests opened for a similar topic. Can you give detailed information?

Add requestUri as an optional parameter

Currently requestUri is hardcoded inside AppleRestClient:

  • GenerateRequestMessage - https://appleid.apple.com/auth/token
  • GenerateRevokeMessage - https://appleid.apple.com/auth/revoke

As a result, it is impossible to write API tests for Apple login flow using, for example, https://wiremock.org/.
Let's add at least a baseUri parameter with the https://appleid.apple.com value by default to make the experience better.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.