Skip to main content

Apple Provider

Package: @nauth-toolkit/social-apple Type: Social Auth Provider

npm install @nauth-toolkit/social-apple

Exports

ExportTypeEntry
AppleSocialAuthServiceClassDefault
AppleOAuthClientClassDefault
TokenVerifierServiceClassDefault
VerifiedAppleTokenProfileInterfaceDefault
AppleSocialAuthModuleNestJS Module/nestjs

Configuration

Configure Apple under config.social.apple (in @nauth-toolkit/core config).

Apple requires a JWT client secret for web OAuth, which is automatically generated and refreshed by the toolkit from your Apple Developer credentials. The JWT is stored in the database and refreshed when it has less than 30 days until expiration.

KeyTypeRequiredDescription
enabledbooleanNoEnable Apple Sign-In
clientIdstringYes (if enabled)Apple Services ID (e.g., 'com.myapp.services')
teamIdstringYes (if enabled for web)Apple Developer Team ID (required for web OAuth)
keyIdstringYes (if enabled for web)Apple Key ID (kid) from your .p8 key (required for web OAuth)
privateKeyPemstringYes (if enabled for web)Contents of your .p8 private key file in PEM format (required for web OAuth)
callbackUrlstringYes (if enabled)Backend callback URL (/auth/social/apple/callback)
scopesstring[]NoDefault: ['name', 'email']
autoLinkbooleanNoAuto-link to existing users by verified email
allowSignupbooleanNoAllow creating new users on first login
oauthParamsRecord<string, string>NoAdditional OAuth parameters to include in authorization URL. These act as defaults and can be overridden on a per-request basis.

OAuth Parameters

The oauthParams option allows you to customize the Apple OAuth authorization flow. These parameters are appended to Apple's authorization URL and can be overridden on a per-request basis from the frontend.

Common Parameters:

  • nonce: For ID token validation and replay attack prevention
  • Any other Apple-supported OAuth parameters

Example:

social: {
apple: {
enabled: true,
clientId: 'com.myapp.services',
teamId: 'ABC123DEF4',
keyId: 'XYZ789ABC0',
privateKeyPem: process.env.APPLE_PRIVATE_KEY_PEM,
callbackUrl: 'https://api.myapp.com/auth/social/apple/callback',
scopes: ['name', 'email'],
oauthParams: {
nonce: 'default-nonce-value', // For ID token validation
},
},
}

See Social Login Guide for usage examples.

Note: For native iOS apps, teamId, keyId, and privateKeyPem are not required as native apps do not use the web OAuth flow.

Usage

import { AppleSocialAuthModule } from '@nauth-toolkit/social-apple/nestjs';

@Module({
imports: [AuthModule.forRoot(config), AppleSocialAuthModule],
})
export class AppModule {}

Profile Data

FieldTypeDescription
idstringApple user ID
emailstringEmail (may be private relay)
emailVerifiedbooleanAlways true from Apple
namestring?Only on first auth