@capawesome/capacitor-apple-sign-in 0.1.0 â 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -4
- package/android/build.gradle +1 -1
- package/ios/Plugin/AppleSignIn.swift +11 -5
- package/ios/Plugin/AppleSignInPlugin.swift +2 -0
- package/package.json +11 -6
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Capacitor Apple Sign-In Plugin
|
|
2
2
|
|
|
3
3
|
Unofficial Capacitor plugin to sign-in with Apple.[^1]
|
|
4
4
|
|
|
@@ -10,7 +10,7 @@ Unofficial Capacitor plugin to sign-in with Apple.[^1]
|
|
|
10
10
|
|
|
11
11
|
## Features
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
The Capacitor Apple Sign-In plugin is one of the most complete Apple authentication solutions for Capacitor apps. Here are some of the key features:
|
|
14
14
|
|
|
15
15
|
- ðĨïļ **Cross-platform**: Supports Android, iOS, and Web.
|
|
16
16
|
- ð **Native Sign-In**: Uses native AuthenticationServices on iOS.
|
|
@@ -18,12 +18,21 @@ We are proud to offer one of the most complete and feature-rich Capacitor plugin
|
|
|
18
18
|
- ð§ **Scope support**: Request email and full name on all platforms.
|
|
19
19
|
- ð **Nonce & state**: Supports nonce for replay protection and state for CSRF protection.
|
|
20
20
|
- ðŠķ **Lightweight**: Just a single dependency and zero unnecessary bloat.
|
|
21
|
-
- ðĪ **Compatibility**: Compatible with the [Google Sign-In](https://capawesome.io/
|
|
21
|
+
- ðĪ **Compatibility**: Compatible with the [Google Sign-In](https://capawesome.io/docs/sdks/capacitor/google-sign-in/) and [OAuth](https://capawesome.io/docs/sdks/capacitor/oauth/) plugins.
|
|
22
22
|
- ðĶ **CocoaPods & SPM**: Supports CocoaPods and Swift Package Manager for iOS.
|
|
23
23
|
- ð **Up-to-date**: Always supports the latest Capacitor version.
|
|
24
24
|
|
|
25
25
|
Missing a feature? Just [open an issue](https://github.com/capawesome-team/capacitor-plugins/issues) and we'll take a look!
|
|
26
26
|
|
|
27
|
+
## Use Cases
|
|
28
|
+
|
|
29
|
+
The Apple Sign-In plugin is typically used to let users authenticate with their Apple ID, for example:
|
|
30
|
+
|
|
31
|
+
- **User authentication**: Offer Sign in with Apple as a login option in your app on Android, iOS, and Web.
|
|
32
|
+
- **Account creation**: Request the user's email address and full name during sign-up using the email and full name scopes.
|
|
33
|
+
- **Backend integration**: Send the authorization code and ID token to your backend to verify the sign-in and create a user session.
|
|
34
|
+
- **Secure sign-in flows**: Pass a nonce for replay protection and a state value for CSRF protection.
|
|
35
|
+
|
|
27
36
|
## Compatibility
|
|
28
37
|
|
|
29
38
|
| Plugin Version | Capacitor Version | Status |
|
|
@@ -36,6 +45,21 @@ Missing a feature? Just [open an issue](https://github.com/capawesome-team/capac
|
|
|
36
45
|
|
|
37
46
|
## Installation
|
|
38
47
|
|
|
48
|
+
You can use our **AI-Assisted Setup** to install the plugin.
|
|
49
|
+
Add the [Capawesome Skills](https://github.com/capawesome-team/skills) to your AI tool using the following command:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npx skills add capawesome-team/skills --skill capacitor-plugins
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Then use the following prompt:
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capawesome/capacitor-apple-sign-in` plugin in my project.
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
If you prefer **Manual Setup**, install the plugin by running the following commands and follow the platform-specific instructions below:
|
|
62
|
+
|
|
39
63
|
```bash
|
|
40
64
|
npm install @capawesome/capacitor-apple-sign-in
|
|
41
65
|
npx cap sync
|
|
@@ -60,14 +84,28 @@ No configuration required for this plugin.
|
|
|
60
84
|
|
|
61
85
|
## Usage
|
|
62
86
|
|
|
87
|
+
The following examples show how to initialize the plugin and sign in with Apple.
|
|
88
|
+
|
|
89
|
+
### Initialize the plugin
|
|
90
|
+
|
|
91
|
+
On Android and Web, you must initialize the plugin with your Apple Service ID before calling `signIn(...)`. This method is only available on Android and Web:
|
|
92
|
+
|
|
63
93
|
```typescript
|
|
64
|
-
import { AppleSignIn
|
|
94
|
+
import { AppleSignIn } from '@capawesome/capacitor-apple-sign-in';
|
|
65
95
|
|
|
66
96
|
const initialize = async () => {
|
|
67
97
|
await AppleSignIn.initialize({
|
|
68
98
|
clientId: 'com.example.app.signin',
|
|
69
99
|
});
|
|
70
100
|
};
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Sign in with Apple
|
|
104
|
+
|
|
105
|
+
Start the sign-in flow and receive the authorization code and ID token. Use the `scopes` option to request the user's email address and full name, and pass a `nonce` for replay protection. The `redirectUrl` and `state` options are only available on Android and Web:
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
import { AppleSignIn, SignInScope } from '@capawesome/capacitor-apple-sign-in';
|
|
71
109
|
|
|
72
110
|
const signIn = async () => {
|
|
73
111
|
const result = await AppleSignIn.signIn({
|
|
@@ -209,6 +247,29 @@ This plugin is purpose-built for Apple Sign-In and focuses on providing a clean
|
|
|
209
247
|
- **Scope support**: Request email and full name on all platforms.
|
|
210
248
|
- **Error codes**: Provides typed error codes for proper error handling.
|
|
211
249
|
|
|
250
|
+
### Do I need to call initialize on iOS?
|
|
251
|
+
|
|
252
|
+
No, the `initialize(...)` method is only available on Android and Web, where it must be called before `signIn(...)` to set the Apple Service ID. On iOS, the plugin uses the native AuthenticationServices framework and no initialization is required.
|
|
253
|
+
|
|
254
|
+
### Why are the email and name only returned on the first sign-in on iOS?
|
|
255
|
+
|
|
256
|
+
On iOS, Apple only provides the user's email address, given name, and family name on the first sign-in; on subsequent sign-ins, these values are `null`. Make sure to persist this information, for example on your backend, when you receive it for the first time.
|
|
257
|
+
|
|
258
|
+
### Can I use this plugin with Ionic, React, Vue or Angular?
|
|
259
|
+
|
|
260
|
+
Yes, the plugin is framework-agnostic. It works in any Capacitor app regardless of the web framework, including Ionic with Angular, React, or Vue, as well as plain JavaScript projects.
|
|
261
|
+
|
|
262
|
+
## Related Plugins
|
|
263
|
+
|
|
264
|
+
- [Google Sign-In](https://capawesome.io/docs/sdks/capacitor/google-sign-in/): Sign in with Google.
|
|
265
|
+
- [Facebook Sign-In](https://capawesome.io/docs/sdks/capacitor/facebook-sign-in/): Sign in with Facebook.
|
|
266
|
+
- [OAuth](https://capawesome.io/docs/sdks/capacitor/oauth/): Communicate with OAuth 2.0 and OpenID Connect providers.
|
|
267
|
+
- [Passkeys](https://capawesome.io/docs/sdks/capacitor/passkeys/): Create and authenticate with passkeys based on the WebAuthn standard.
|
|
268
|
+
|
|
269
|
+
## Newsletter
|
|
270
|
+
|
|
271
|
+
Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).
|
|
272
|
+
|
|
212
273
|
## Changelog
|
|
213
274
|
|
|
214
275
|
See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/apple-sign-in/CHANGELOG.md).
|
package/android/build.gradle
CHANGED
|
@@ -30,7 +30,7 @@ android {
|
|
|
30
30
|
buildTypes {
|
|
31
31
|
release {
|
|
32
32
|
minifyEnabled false
|
|
33
|
-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
33
|
+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
lintOptions {
|
|
@@ -4,6 +4,7 @@ import AuthenticationServices
|
|
|
4
4
|
@objc public class AppleSignIn: NSObject {
|
|
5
5
|
|
|
6
6
|
private var completion: ((_ result: SignInResult?, _ error: Error?) -> Void)?
|
|
7
|
+
private var authorizationController: ASAuthorizationController?
|
|
7
8
|
|
|
8
9
|
@objc public func signIn(_ options: SignInOptions, presentationContextProvider: ASAuthorizationControllerPresentationContextProviding, completion: @escaping (_ result: SignInResult?, _ error: Error?) -> Void) {
|
|
9
10
|
self.completion = completion
|
|
@@ -17,15 +18,19 @@ import AuthenticationServices
|
|
|
17
18
|
request.nonce = nonce
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
DispatchQueue.main.async {
|
|
22
|
+
let controller = ASAuthorizationController(authorizationRequests: [request])
|
|
23
|
+
controller.delegate = self
|
|
24
|
+
controller.presentationContextProvider = presentationContextProvider
|
|
25
|
+
self.authorizationController = controller
|
|
26
|
+
controller.performRequests()
|
|
27
|
+
}
|
|
24
28
|
}
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
extension AppleSignIn: ASAuthorizationControllerDelegate {
|
|
28
32
|
public func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
|
|
33
|
+
authorizationController = nil
|
|
29
34
|
guard let credential = authorization.credential as? ASAuthorizationAppleIDCredential else {
|
|
30
35
|
completion?(nil, CustomError.signInFailed)
|
|
31
36
|
completion = nil
|
|
@@ -37,11 +42,12 @@ extension AppleSignIn: ASAuthorizationControllerDelegate {
|
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
public func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) {
|
|
45
|
+
authorizationController = nil
|
|
40
46
|
let asError = error as? ASAuthorizationError
|
|
41
47
|
if asError?.code == .canceled {
|
|
42
48
|
completion?(nil, CustomError.signInCanceled)
|
|
43
49
|
} else {
|
|
44
|
-
completion?(nil,
|
|
50
|
+
completion?(nil, error)
|
|
45
51
|
}
|
|
46
52
|
completion = nil
|
|
47
53
|
}
|
|
@@ -43,6 +43,8 @@ public class AppleSignInPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
43
43
|
var code: String?
|
|
44
44
|
if let customError = error as? CustomError {
|
|
45
45
|
code = customError.code
|
|
46
|
+
} else if let authorizationError = error as? ASAuthorizationError {
|
|
47
|
+
code = String(authorizationError.code.rawValue)
|
|
46
48
|
}
|
|
47
49
|
call.reject(error.localizedDescription, code)
|
|
48
50
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capawesome/capacitor-apple-sign-in",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Capacitor plugin to sign-in with Apple.",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Capacitor plugin to sign-in with Apple on Android, iOS, and Web.",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
7
7
|
"types": "dist/esm/index.d.ts",
|
|
@@ -36,7 +36,15 @@
|
|
|
36
36
|
"keywords": [
|
|
37
37
|
"capacitor",
|
|
38
38
|
"plugin",
|
|
39
|
-
"native"
|
|
39
|
+
"native",
|
|
40
|
+
"capacitor-plugin",
|
|
41
|
+
"apple sign in",
|
|
42
|
+
"sign in with apple",
|
|
43
|
+
"apple login",
|
|
44
|
+
"apple id",
|
|
45
|
+
"social login",
|
|
46
|
+
"authentication",
|
|
47
|
+
"oauth"
|
|
40
48
|
],
|
|
41
49
|
"scripts": {
|
|
42
50
|
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
@@ -63,9 +71,7 @@
|
|
|
63
71
|
"@capacitor/docgen": "0.3.1",
|
|
64
72
|
"@capacitor/ios": "8.0.0",
|
|
65
73
|
"@ionic/eslint-config": "0.4.0",
|
|
66
|
-
"@ionic/swiftlint-config": "2.0.0",
|
|
67
74
|
"eslint": "8.57.0",
|
|
68
|
-
"prettier": "3.4.2",
|
|
69
75
|
"prettier-plugin-java": "2.6.7",
|
|
70
76
|
"rimraf": "6.1.2",
|
|
71
77
|
"rollup": "4.53.3",
|
|
@@ -75,7 +81,6 @@
|
|
|
75
81
|
"peerDependencies": {
|
|
76
82
|
"@capacitor/core": ">=8.0.0"
|
|
77
83
|
},
|
|
78
|
-
"swiftlint": "@ionic/swiftlint-config",
|
|
79
84
|
"eslintConfig": {
|
|
80
85
|
"extends": "@ionic/eslint-config/recommended"
|
|
81
86
|
},
|