![]() |
VOOZH | about |
dotnet add package AppleAuth.NET --version 1.0.8
NuGet\Install-Package AppleAuth.NET -Version 1.0.8
<PackageReference Include="AppleAuth.NET" Version="1.0.8" />
<PackageVersion Include="AppleAuth.NET" Version="1.0.8" />Directory.Packages.props
<PackageReference Include="AppleAuth.NET" />Project file
paket add AppleAuth.NET --version 1.0.8
#r "nuget: AppleAuth.NET, 1.0.8"
#:package AppleAuth.NET@1.0.8
#addin nuget:?package=AppleAuth.NET&version=1.0.8Install as a Cake Addin
#tool nuget:?package=AppleAuth.NET&version=1.0.8Install as a Cake Tool
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.
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
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.
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.
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".
AppleAuthProvider.csCreate 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.
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;
}
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.
We do not have any strict guidelines for creating pull requests, but you can use the already known for general guidelines.
This project is licensed under the MIT License - see LICENSE.md for details
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 netstandard2.1 is compatible. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 2 NuGet packages that depend on AppleAuth.NET:
| Package | Downloads |
|---|---|
|
EIAM.Package.Security
EIAM Security and Authorization Complete Package |
|
|
Vita4AI.Core
Official Vita4AI Core Package |
This package is not used by any popular GitHub repositories.
Add parameters for base url and query strings