Repository navigation
Apple Auth start #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Apple Auth start #58
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8d7aded
Apple Auth start
AnthonyRonning 8f24af3
Attempt apple oauth
AnthonyRonning 41922b8
Remove apple non-native signin
AnthonyRonning 19f254f
Bump opensecret
AnthonyRonning a77b832
iOS auth cleanup
AnthonyRonning d9ecdde
Add apple nonce parameter
AnthonyRonning File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| # Sign in with Apple Integration | ||
|
|
||
| ## Overview | ||
| This document provides a comprehensive guide to the Sign in with Apple integration for Maple, supporting both native iOS authentication and web-based OAuth. | ||
|
|
||
| ## Integration Types | ||
|
|
||
| ### 1. Native iOS Authentication | ||
| - Uses the iOS native Sign In with Apple dialog | ||
| - Implemented via `tauri-plugin-sign-in-with-apple` (version 1.0.0) | ||
| - Returns user credentials directly to the app | ||
| - Provides access to user identifiers, email, and name (only on first sign-in) | ||
|
|
||
| ### 2. Web-based OAuth Flow | ||
| - Similar to GitHub and Google OAuth flow | ||
| - Redirects users to Apple's authentication page | ||
| - Supports both web and desktop (non-iOS) platforms | ||
| - Handles callback with auth code and state verification | ||
|
|
||
| ## Configuration | ||
|
|
||
| ### iOS Native Auth | ||
| 1. Required entitlements have been added in `maple_iOS.entitlements` | ||
| 2. The capability is registered in `capabilities/default.json` and `capabilities/mobile-ios.json` | ||
| 3. Plugin is configured in Cargo.toml and registered in the app | ||
|
|
||
| ### OAuth Configuration | ||
| 1. Set up these parameters in your OpenSecret project settings: | ||
| - **Client ID**: Your Apple Services ID (e.g., com.example.web) | ||
| - **Client Secret**: The base64-encoded contents of your Apple private key (p8 file) | ||
| - **Redirect URI**: Configure as `https://api.opensecret.cloud/auth/apple/callback` | ||
|
|
||
| ## Implementation Details | ||
|
|
||
| ### Frontend Integration | ||
|
|
||
| #### iOS Native Flow | ||
| ```typescript | ||
| // iOS native authentication | ||
| const result = await invoke("plugin:sign-in-with-apple|get_apple_id_credential", { | ||
| payload: { | ||
| scope: ["email", "fullName"], | ||
| state: "apple-auth-state", | ||
| options: { debug: true } | ||
| } | ||
| }); | ||
|
|
||
| // Format and send to backend | ||
| const appleUser = { | ||
| user_identifier: result.user, | ||
| identity_token: result.identityToken, | ||
| email: result.email, | ||
| given_name: result.fullName?.givenName, | ||
| family_name: result.fullName?.familyName | ||
| }; | ||
|
|
||
| // Call OpenSecret SDK | ||
| await os.handleAppleNativeSignIn(appleUser, inviteCode); | ||
| ``` | ||
|
|
||
| #### Web OAuth Flow | ||
| ```typescript | ||
| // Web OAuth authentication | ||
| const { auth_url } = await os.initiateAppleAuth(inviteCode); | ||
| window.location.href = auth_url; | ||
|
|
||
| // Callback handling (in separate component) | ||
| await handleAppleCallback(code, state, inviteCode); | ||
| ``` | ||
|
|
||
| ### Platform Detection | ||
| The app automatically determines the appropriate flow: | ||
| 1. Checks if the app is running on iOS and uses native flow | ||
| 2. Checks if running in a Tauri environment (desktop) and uses the desktop auth flow | ||
| 3. Uses the web OAuth flow for all other cases | ||
|
|
||
| ## Callback Handling | ||
| For the web OAuth flow, callbacks are handled in `auth.$provider.callback.tsx`: | ||
| 1. Extracts code and state from URL parameters | ||
| 2. Verifies auth state to prevent CSRF attacks | ||
| 3. Processes the authentication with the backend | ||
| 4. Redirects to appropriate page after successful authentication | ||
|
|
||
| ## Debugging | ||
| If you experience issues with Sign in with Apple: | ||
| 1. Check debug logs (enabled by default in both flows) | ||
| 2. Verify that iOS entitlements are properly configured (for native flow) | ||
| 3. For OAuth flow, check if Apple Developer account is properly set up | ||
| 4. Verify that the OpenSecret project settings are correctly configured | ||
|
|
||
| ## Apple Developer Setup | ||
| To use Sign in with Apple, you need: | ||
| 1. An Apple Developer account | ||
| 2. An App ID with "Sign In with Apple" capability | ||
| 3. A Services ID for web authentication | ||
| 4. A Bundle ID for iOS apps | ||
| 5. A private key for JWT token signing | ||
|
|
||
| ## Resources | ||
| - [Apple Developer Documentation](https://developer.apple.com/documentation/sign_in_with_apple) | ||
| - [OpenSecret Apple Auth API](https://docs.opensecret.cloud/docs/guides/authentication) | ||
| - [tauri-plugin-sign-in-with-apple](https://crates.io/crates/tauri-plugin-sign-in-with-apple) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| "url": "https://trymaple.ai/*" | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| "sign-in-with-apple:default" | ||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| { | ||
| "$schema": "../gen/schemas/mobile-schema.json", | ||
| "identifier": "mobile-ios", | ||
| "description": "Capabilities for iOS", | ||
| "windows": [ | ||
| "main" | ||
| ], | ||
| "platforms": ["iOS"], | ||
| "permissions": [ | ||
| "core:default", | ||
| "updater:default", | ||
| { | ||
| "identifier": "opener:allow-open-url", | ||
| "allow": [ | ||
| { | ||
| "url": "http://localhost:5173/*" | ||
| }, | ||
| { | ||
| "url": "https://trymaple.ai/*" | ||
| } | ||
| ] | ||
| }, | ||
| "sign-in-with-apple:default" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
AnthonyRonning marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import React from "react"; | ||
|
|
||
| export function Apple(props: React.SVGProps<SVGSVGElement>) { | ||
| return ( | ||
| <svg | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| width="24" | ||
| height="24" | ||
| viewBox="0 0 384 512" | ||
| fill="currentColor" | ||
| {...props} | ||
| > | ||
| <path d="M318.7 268.7c-.2-36.7 16.4-64.4 50-84.8-18.8-26.9-47.2-41.7-84.7-44.6-35.5-2.8-74.3 20.7-88.5 20.7-15 0-49.4-19.7-76.4-19.7C63.3 141.2 4 184.8 4 273.5q0 39.3 14.4 81.2c12.8 36.7 59 126.7 107.2 125.2 25.2-.6 43-17.9 75.8-17.9 31.8 0 48.3 17.9 76.4 17.9 48.6-.7 90.4-82.5 102.6-119.3-65.2-30.7-61.7-90-61.7-91.9zm-56.6-164.2c27.3-32.4 24.8-61.9 24-72.5-24.1 1.4-52 16.4-67.9 34.9-17.5 19.8-27.8 44.3-25.6 71.9 26.1 2 49.9-11.4 69.5-34.3z" /> | ||
| </svg> | ||
| ); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.