Skip to content

dydxprotocol/test-apple

Repository files navigation

Apple Login Example

This example demonstrates Sign in with Apple using the REST API per Apple's docs: https://developer.apple.com/documentation/signinwithapplerestapi/request-an-authorization-to-the-sign-in-with-apple-server

Setup

  1. Create a Service ID in Apple Developer and configure the return URL:
    • Redirect URI: http://localhost:3000/api/callback
  2. Generate a Sign In with Apple private key and note the Key ID.
  3. Create .env.local with the following variables:
NEXT_PUBLIC_BASE_URL=http://localhost:3000
APPLE_TEAM_ID=YOUR_APPLE_TEAM_ID
APPLE_CLIENT_ID=YOUR_SERVICE_ID
APPLE_KEY_ID=YOUR_KEY_ID
APPLE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----"
APPLE_REDIRECT_URI=http://localhost:3000/api/callback

Run

  • Install deps from repo root: pnpm install
  • Start this example:
cd examples/apple-login
pnpm dev

Open http://localhost:3000 and click "Sign in with Apple".

Notes

  • This demo uses response_mode=form_post.
  • The server generates a client secret JWT signed with your private key.
  • For production, verify id_token with Apple's JWKS.

Troubleshooting "Sign in could not be completed"

  • Ensure APPLE_REDIRECT_URI EXACTLY matches the value configured on your Service ID.
  • Ensure the Service ID is of type Web and domain localhost is added if required.
  • Ensure the private key corresponds to the same Team and Key ID, and is in PKCS#8 format.
  • Clear Apple cookies or try a private window; cached sessions can cause opaque errors.
  • Check server logs: the callback will display error and error_description from Apple if present.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published