tauri-plugin-siwa-api 1.0.0
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/LICENSE +8 -0
- package/README.md +140 -0
- package/dist-js/index.cjs +11 -0
- package/dist-js/index.d.ts +16 -0
- package/dist-js/index.js +9 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Copyright 2024 Manaf Mhamdi Alaoui
|
|
2
|
+
Modifications Copyright 2025 Gavyn Stanley
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
5
|
+
|
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# tauri-plugin-siwa
|
|
2
|
+
|
|
3
|
+
Sign In with Apple for Tauri 2 — supports **iOS** and **macOS**.
|
|
4
|
+
|
|
5
|
+
> **Attribution:** Based on [tauri-plugin-sign-in-with-apple](https://crates.io/crates/tauri-plugin-sign-in-with-apple) by [Manaf941](https://github.com/Manaf941), licensed under the [MIT License](./LICENSE). Modified by Gavyn Stanley to add macOS support.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Platform Support
|
|
10
|
+
|
|
11
|
+
| Platform | Supported |
|
|
12
|
+
|----------|-----------|
|
|
13
|
+
| iOS | ✅ |
|
|
14
|
+
| macOS | ✅ |
|
|
15
|
+
| Android | ❌ |
|
|
16
|
+
| Windows | ❌ |
|
|
17
|
+
| Linux | ❌ |
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
Add the Rust crate to your `src-tauri/Cargo.toml`:
|
|
24
|
+
|
|
25
|
+
```toml
|
|
26
|
+
[dependencies]
|
|
27
|
+
tauri-plugin-siwa = "1.0.0"
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Install the JavaScript package:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install tauri-plugin-siwa-api
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Setup
|
|
39
|
+
|
|
40
|
+
### 1. Register the plugin
|
|
41
|
+
|
|
42
|
+
In `src-tauri/src/main.rs` (or `lib.rs`):
|
|
43
|
+
|
|
44
|
+
```rust
|
|
45
|
+
fn main() {
|
|
46
|
+
tauri::Builder::default()
|
|
47
|
+
.plugin(tauri_plugin_siwa::init())
|
|
48
|
+
.run(tauri::generate_context!())
|
|
49
|
+
.expect("error while running tauri application");
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 2. Add the capability permission
|
|
54
|
+
|
|
55
|
+
In your capability file (e.g. `src-tauri/capabilities/default.json`):
|
|
56
|
+
|
|
57
|
+
```json
|
|
58
|
+
{
|
|
59
|
+
"permissions": [
|
|
60
|
+
"siwa:allow-get-apple-id-credential"
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### 3. Apple Developer setup
|
|
66
|
+
|
|
67
|
+
- Enable the **Sign In with Apple** capability in your Apple Developer account for your App ID.
|
|
68
|
+
- Add the entitlement to your app. In `src-tauri/entitlements.plist`:
|
|
69
|
+
|
|
70
|
+
```xml
|
|
71
|
+
<key>com.apple.developer.applesignin</key>
|
|
72
|
+
<array>
|
|
73
|
+
<string>Default</string>
|
|
74
|
+
</array>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Usage
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { getAppleIdCredential } from 'tauri-plugin-siwa-api';
|
|
83
|
+
|
|
84
|
+
const response = await getAppleIdCredential({
|
|
85
|
+
scope: ['fullName', 'email'],
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
console.log(response.userIdentifier); // Stable user ID — store this
|
|
89
|
+
console.log(response.email); // Only returned on first sign-in
|
|
90
|
+
console.log(response.identityToken); // JWT — verify on your server
|
|
91
|
+
console.log(response.authorizationCode); // Short-lived code for server exchange
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
> **Note:** `email`, `givenName`, and `familyName` are only returned on the **first** sign-in. Store them immediately — Apple will not return them again.
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## API
|
|
99
|
+
|
|
100
|
+
### `getAppleIdCredential(request)`
|
|
101
|
+
|
|
102
|
+
Presents the Sign In with Apple sheet and returns credentials.
|
|
103
|
+
|
|
104
|
+
#### Request
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
interface AppleIDAuthorizationRequest {
|
|
108
|
+
scope: ('fullName' | 'email')[];
|
|
109
|
+
nonce?: string; // Recommended: associate with your server session
|
|
110
|
+
state?: string; // Optional: passed back in the response unchanged
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
#### Response
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
interface AppleIDAuthorizationResponse {
|
|
118
|
+
userIdentifier: string | null; // Stable, unique user ID
|
|
119
|
+
givenName: string | null; // First sign-in only
|
|
120
|
+
familyName: string | null; // First sign-in only
|
|
121
|
+
email: string | null; // First sign-in only
|
|
122
|
+
authorizationCode: string; // Short-lived server exchange code
|
|
123
|
+
identityToken: string | null; // JWT — verify with Apple's public keys
|
|
124
|
+
state: string | null; // Echoed from request
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
#### Errors
|
|
129
|
+
|
|
130
|
+
| Error | Cause |
|
|
131
|
+
|-------|-------|
|
|
132
|
+
| `Unsupported platform` | Called on a non-Apple platform |
|
|
133
|
+
| `Failed to decode authorization code` | Apple returned malformed data |
|
|
134
|
+
| `Sign In With Apple error: <msg>` | macOS ASAuthorization failure (e.g. user cancelled) |
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
|
|
140
|
+
MIT — see [LICENSE](./LICENSE).
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@tauri-apps/api/core');
|
|
4
|
+
|
|
5
|
+
async function getAppleIdCredential(request) {
|
|
6
|
+
return core.invoke('plugin:siwa|get_apple_id_credential', {
|
|
7
|
+
payload: request,
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
exports.getAppleIdCredential = getAppleIdCredential;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type Scope = 'fullName' | 'email';
|
|
2
|
+
export interface AppleIDAuthorizationRequest {
|
|
3
|
+
scope: Scope[];
|
|
4
|
+
nonce?: string;
|
|
5
|
+
state?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface AppleIDAuthorizationResponse {
|
|
8
|
+
userIdentifier: string | null;
|
|
9
|
+
givenName: string | null;
|
|
10
|
+
familyName: string | null;
|
|
11
|
+
email: string | null;
|
|
12
|
+
authorizationCode: string;
|
|
13
|
+
identityToken: string | null;
|
|
14
|
+
state: string | null;
|
|
15
|
+
}
|
|
16
|
+
export declare function getAppleIdCredential(request: AppleIDAuthorizationRequest): Promise<AppleIDAuthorizationResponse>;
|
package/dist-js/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tauri-plugin-siwa-api",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"author": "GavynStanley",
|
|
5
|
+
"contributors": ["Manaf941"],
|
|
6
|
+
"description": "Sign In with Apple for Tauri 2 — supports iOS and macOS.",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"types": "./dist-js/index.d.ts",
|
|
10
|
+
"main": "./dist-js/index.cjs",
|
|
11
|
+
"module": "./dist-js/index.js",
|
|
12
|
+
"exports": {
|
|
13
|
+
"types": "./dist-js/index.d.ts",
|
|
14
|
+
"import": "./dist-js/index.js",
|
|
15
|
+
"require": "./dist-js/index.cjs"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist-js",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "rollup -c",
|
|
23
|
+
"format": "prettier --write \"guest-js/**/*.ts\" && cargo fmt && swift-format format -i -r ios/Sources macos/Sources",
|
|
24
|
+
"prepublishOnly": "npm run build",
|
|
25
|
+
"pretest": "npm run build",
|
|
26
|
+
"publish:npm": "npm publish",
|
|
27
|
+
"publish:cargo": "cargo publish"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@tauri-apps/api": ">=2.0.0-beta.6"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
34
|
+
"prettier": "^3.0.0",
|
|
35
|
+
"rollup": "^4.9.6",
|
|
36
|
+
"tslib": "^2.6.2",
|
|
37
|
+
"typescript": "^5.3.3"
|
|
38
|
+
}
|
|
39
|
+
}
|