Skip to main content
Glama
apple-authentication.md5.78 kB
--- title: AppleAuthentication description: A library that provides Sign-in with Apple capability for iOS. sourceCodeUrl: https://github.com/expo/expo/tree/sdk-51/packages/expo-apple-authentication packageName: expo-apple-authentication platforms: ["ios", "tvos"] --- `expo-apple-authentication` provides Apple authentication for iOS. It does not yet support Android or web. Any app that includes third-party authentication options **must** provide Apple authentication as an option to comply with App Store Review guidelines. For more information, see Apple authentication on the [Sign In with Apple](https://developer.apple.com/sign-in-with-apple/) website. ## Installation ## Configuration in app config You can configure `expo-apple-authentication` using its built-in [config plugin](/config-plugins/introduction/) if you use config plugins in your project ([EAS Build](/build/introduction) or `npx expo run:[android|ios]`). The plugin allows you to configure various properties that cannot be set at runtime and require building a new app binary to take effect. If your app does **not** use EAS Build, then you'll need to manually configure the package. ### Setup iOS project To enable the **Sign In with Apple** capability in your app, set the [`ios.usesAppleSignIn`](../config/app/#usesapplesignin) property to `true` in your project's app config: ```json app.json { "expo": { "ios": { "usesAppleSignIn": true } } } ``` Running [EAS Build](/build/introduction) locally will use [iOS capabilities signing](/build-reference/ios-capabilities) to enable the required capabilities before building. ```json app.json { "expo": { "plugins": ["expo-apple-authentication"] } } ``` Apps that don't use [EAS Build](/build/introduction) must [manually configure](/build-reference/ios-capabilities#manual-setup) the **Apple Sign In** capability for their bundle identifier. If you enable the **Apple Sign In** capability through the [Apple Developer Console](/build-reference/ios-capabilities#apple-developer-console), then be sure to add the following entitlements in your **ios/[app]/[app].entitlements** file: ```xml <key>com.apple.developer.applesignin</key> <array> <string>Default</string> </array> ``` Also, set `CFBundleAllowMixedLocalizations` to `true` in your **ios/[app]/Info.plist** to ensure the sign-in button uses the device locale. ## Usage ```jsx return ( <View style={styles.container}> <AppleAuthentication.AppleAuthenticationButton buttonType={AppleAuthentication.AppleAuthenticationButtonType.SIGN_IN} buttonStyle={AppleAuthentication.AppleAuthenticationButtonStyle.BLACK} cornerRadius={5} style={styles.button} onPress={async () => { try { const credential = await AppleAuthentication.signInAsync({ requestedScopes: [ AppleAuthentication.AppleAuthenticationScope.FULL_NAME, AppleAuthentication.AppleAuthenticationScope.EMAIL, ], }); // signed in } catch (e) { if (e.code === 'ERR_REQUEST_CANCELED') { // handle that the user canceled the sign-in flow } else { // handle other errors } } }} /> </View> ); } const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', justifyContent: 'center', }, button: { width: 200, height: 44, }, }); ``` ## Development and testing You can test this library in Expo Go on iOS without following any of the instructions above. However, you'll need to add the config plugin to use this library if you are using EAS Build. When you sign into Expo Go, the identifiers and values you receive will likely be different than what you'll receive in standalone apps. You can do limited testing of this library on the iOS Simulator. However, not all methods will behave the same as on a device, so we highly recommend testing on a real device when possible while developing. ## Verifying the Response from Apple Apple's response includes a signed JWT with information about the user. To ensure that the response came from Apple, you can cryptographically verify the signature with Apple's public key, which is published at https://appleid.apple.com/auth/keys. This process is not specific to Expo. ## API ```js ``` ## Error codes Most of the error codes match the official [Apple Authorization errors](https://developer.apple.com/documentation/authenticationservices/asauthorizationerror/code). | Code | Description | | --------------------------- | ----------------------------------------------------------------------------------- | | ERR_INVALID_OPERATION | An invalid authorization operation has been performed. | | ERR_INVALID_RESPONSE | The authorization request received an invalid response. | | ERR_INVALID_SCOPE | An invalid [`AppleAuthenticationScope`](#appleauthenticationscope) was passed in. | | ERR_REQUEST_CANCELED | The user canceled the authorization attempt. | | ERR_REQUEST_FAILED | The authorization attempt failed. See the error message for additional information. | | ERR_REQUEST_NOT_HANDLED | The authorization request wasn't correctly handled. | | ERR_REQUEST_NOT_INTERACTIVE | The authorization request isn't interactive. | | ERR_REQUEST_UNKNOWN | The authorization attempt failed for an unknown reason. |

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jaksm/expo-docs-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server