Skip to content

martincostello/SignInWithAppleSample

Sign in with Apple Example Integration

Build status

This repository contains a sample implementation of Sign in with Apple for ASP.NET Core written in C#.

Overview

Sign in with Apple is a way of allowing users of websites to sign in using their Apple ID.

This example integration shows a minimal sample of how to integrate Sign in with Apple a website to authenticate a user using their Apple ID and retrieve their email address (or a relay address to it) and their name.

Setup

To setup the repository to run the sample, perform the steps below:

  1. Install the .NET SDK, Visual Studio or Visual Studio Code version compatible with .NET 7.
  2. Fork this repository.
  3. Clone the repository from your fork to your local machine: git clone https://github.com/{username}/SignInWithAppleSample.git
  4. Follow the steps to obtain your Client ID, Private Key, Key ID and Domain Verification file, if you do not already have them.
  5. Place the Domain Verification file (apple-developer-domain-association.txt) in the src\SignInWithApple\wwwroot\.well-known folder.
  6. Either add your .p8 file contining the private key to generate the client secret to the root of the application in src\SignInWithApple (but not in the wwwroot folder), or use some other mechanism, such as loading it from a blob storage account.
  7. Update the favicon (src\SignInWithApple\wwwroot\favicon.ico) to your own design.
  8. Configure the following settings as appropriate in either your environment variables or in src\SignInWithApple\appsettings.json:
    • AppleClientId
    • AppleKeyId
    • AppleTeamId
  9. Deploy the application to the hosting environment for the domain where you wish to use Sign in with Apple.
  10. Verify the domain in the Apple Developer Portal.

You should now be able to sign in with your Apple ID in the deployed application.

Local Debugging

You should be able to debug the application in Visual Studio Code or Visual Studio 2022 (17.3 or later).

Azure App Service Deployment

If you are deploying the sample application to a Microsoft Azure App Service Web App, you will need to make the following configuration changes to your Web App for the sample application to run correctly:

ℹ️ The Free and Shared pricing tiers do not support features required to load the private key. See the Azure App Service documentation for the the other available pricing tiers.

  • Navigate to the Application settings tab of your Web App and add the following settings:
    • WEBSITE_LOAD_USER_PROFILE to a value of 1.
    • Save the changes.
  • Ensure the hostname you are using (either {yourappname}.azurewebsites.net or a custom hostname that you have set up) has been added in the Apple Developer portal to your service id and you've added the Apple Developer domain validation file as described in the Setup section above.

Feedback

Any feedback or issues can be added to the issues for this project in GitHub.

License

This project is licensed under the Apache 2.0 license.

External Links