dhc-tech/apple_sign_in_plugin
dhc-tech/apple_sign_in_plugin open-source repository details.
- Stars
- 5
- Forks
- 0
- Último push (UTC)
- 18 de fev. de 2026
- Status do projeto
- Ativo
Dependências usadas
Lista de dependências 7 itens
- flutter
{"sdk":"flutter"} - http
>=1.6.0 <3.0.0 - jose
>=0.3.5 <2.0.0 - sign_in_with_apple
>=7.0.1 <9.0.0 - get_storage
>=2.1.1 <4.0.0 - flutter_testDesenvolvimento
{"sdk":"flutter"} - flutter_lintsDesenvolvimento
>=6.0.0 <8.0.0
README original
Texto original em inglês. Visite o GitHub para a versão atual.
Expandir / recolher README
Apple Sign In Plugin
A comprehensive Flutter package for integrating Apple Sign-In with features for secure authentication and user data management. It handles the complete flow, including token exchange and refresh, making it ready for backend integration.
✨ Features
- 🔐 Secure Authentication: Handles the complete Apple Sign-In flow securely.
- 📦 Backend Ready: Returns
idToken,accessToken, andrefreshTokenessential for server-side verification. - 🔄 Token Management: Automatically handles token refreshes and revocations.
- 👤 User Data: Retrieves name, email, and stable user ID.
- 📱 Cross-Platform: Supports iOS, macOS, Android, and Web.
📱 Platform Support
| Platform | Supported | Implementation Note |
|---|---|---|
| iOS | ✅ | Native Framework |
| macOS | ✅ | Native Framework |
| Android | ✅ | via Apple Web Auth |
| Web | ✅ | via Apple JS SDK |
🛠 Prerequisites
Before using this plugin, ensure you have the following configured in your Apple Developer Account:
- App ID & Service ID: Created and configured for Sign in with Apple.
- Team ID: Your 10-character Team ID.
- Key ID: The ID of your private key.
- Private Key file (.p8): Downloaded from Apple. Rename it to
apple_private_key.pem.
📦 Installation
Add this to your package's pubspec.yaml file:
dependencies:
apple_sign_in_plugin: ^1.2.6
⚙️ Setup & Configuration
1. Asset Configuration (Required)
Add your .pem private key file to your Flutter assets in pubspec.yaml:
flutter:
assets:
- assets/keys/apple_private_key.pem
2. iOS / macOS
- Open your project in Xcode.
- Go to Signing & Capabilities.
- Add the Sign in with Apple capability.
3. Android / Web
- Ensure you have created a Service ID in the Apple Developer Console.
- Configure your Return URLs and Web Domain for the Service ID.
🚀 Usage
1. Initialize
Initialize the plugin once, preferably in main.dart or before the first usage.
await AppleSignInPlugin.initialize(
pemKeyPath: 'assets/keys/apple_private_key.pem',
keyId: 'YOUR_KEY_ID',
teamId: 'YOUR_TEAM_ID',
bundleId: 'YOUR_BUNDLE_ID', // Must match your Service ID
);
2. Sign In
Call signInWithApple() to start the authentication flow.
try {
final result = await AppleSignInPlugin.signInWithApple();
if (result != null) {
print("Sign In Successful!");
print("ID Token: ${result.idToken}");
print("Email: ${result.email}");
print("User ID: ${result.userIdentifier}");
} else {
print("Sign In Cancelled");
}
} catch (e) {
print("Sign In Failed: $e");
}
3. Sign Out
Securely signs the user out and invalidates the tokens.
await AppleSignInPlugin.signOut();
4. Check State
Check if the user is currently considered logged in (locally).
bool isLoggedIn = AppleSignInPlugin.isSignedIn();
📦 The Result Object (AppleSignInResult)
The plugin returns an AppleSignInResult object containing all necessary data.
| Field | Description | Usage |
|---|---|---|
idToken |
JSON Web Token (JWT). | Verify on Backend. Proves user identity. |
accessToken |
Short-lived Apple API token. | Accessing Apple APIs. |
refreshToken |
Long-lived token. | Getting new access tokens. |
userIdentifier |
Unique User ID. | Database Key. Identify users in your DB. |
email |
User's email. | User contact/profile. |
givenName |
First Name. | User profile (First login only). |
familyName |
Last Name. | User profile (First login only). |
authorizationCode |
One-time code. | Used internally for token exchange. |
❓ Troubleshooting
| Error Code | Possible Cause | Solution |
|---|---|---|
invalid_client |
Incorrect credentials. | Check Team ID, Key ID, Bundle ID, and ensure the .pem file is correct and loaded. |
invalid_grant |
Expired/Used code. | Expected if reusing a code. Sign in again to get a fresh code. |
invalid_request |
Missing parameters. | Verify all initialize() parameters are non-empty strings. |
Simulation Fail |
iOS Simulator issue. | Test on a Real Device. Simulators often fail with Keychain errors. |
📄 License
MIT License. See LICENSE for details.