appleProvider function
Apple Sign In OAuth provider.
Based on Apple's Sign in with Apple documentation.
Resources
- https://developer.apple.com/sign-in-with-apple/get-started/
- https://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_rest_api
Example
final provider = appleProvider(
AppleProviderOptions(
clientId: 'your.service.id',
clientSecret: 'generated-jwt',
redirectUri: 'https://example.com/auth/callback/apple',
),
);
Implementation
OAuthProvider<AppleProfile> appleProvider(AppleProviderOptions options) {
return OAuthProvider<AppleProfile>(
id: 'apple',
name: 'Apple',
type: AuthProviderType.oidc,
clientId: options.clientId,
clientSecret: options.clientSecret,
authorizationEndpoint: Uri.parse(
'https://appleid.apple.com/auth/authorize',
),
tokenEndpoint: Uri.parse('https://appleid.apple.com/auth/token'),
oidcIssuer: Uri.parse('https://appleid.apple.com'),
oidcJwksUri: Uri.parse('https://appleid.apple.com/auth/keys'),
redirectUri: options.redirectUri,
scopes: options.scopes,
authorizationParams: {'response_mode': 'form_post'},
useBasicAuth: false,
profileParser: AppleProfile.fromJson,
profileSerializer: (profile) => profile.toJson(),
profile: (profile) {
return AuthUser(
id: profile.sub,
name: profile.fullName,
email: profile.email,
attributes: profile.toJson(),
);
},
);
}