@authara/react-native 0.0.0-stage → 0.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 +21 -0
- package/README.md +250 -2
- package/dist/button-appearance.d.ts +43 -0
- package/dist/button-appearance.js +103 -0
- package/dist/button-contract.d.ts +69 -0
- package/dist/button-contract.js +17 -0
- package/dist/button-error.d.ts +40 -0
- package/dist/button-error.js +70 -0
- package/dist/buttons.d.ts +53 -0
- package/dist/buttons.js +195 -0
- package/dist/client.d.ts +65 -0
- package/dist/client.js +190 -0
- package/dist/context.d.ts +12 -0
- package/dist/context.js +16 -0
- package/dist/expo-apple-authentication.d.ts +2 -0
- package/dist/expo-apple-authentication.js +38 -0
- package/dist/expo-microsoft-auth-session.d.ts +7 -0
- package/dist/expo-microsoft-auth-session.js +57 -0
- package/dist/expo-secure-store.d.ts +6 -0
- package/dist/expo-secure-store.js +9 -0
- package/dist/generated/api.d.ts +296 -0
- package/dist/generated/api.js +381 -0
- package/dist/generated/error-codes.d.ts +8 -0
- package/dist/generated/error-codes.js +42 -0
- package/dist/generated/operations.d.ts +1060 -0
- package/dist/generated/operations.js +1128 -0
- package/dist/generated/types.d.ts +355 -0
- package/dist/generated/types.js +2 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +8 -0
- package/dist/native-client.d.ts +43 -0
- package/dist/native-client.js +215 -0
- package/dist/nitro-google-signin.d.ts +5 -0
- package/dist/nitro-google-signin.js +25 -0
- package/dist/storage.d.ts +6 -0
- package/dist/storage.js +14 -0
- package/package.json +114 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Authara
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,251 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @authara/react-native
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Official Authara client for React Native and Expo. It provides the complete
|
|
4
|
+
public/user API generated from Authara Core, token lifecycle management, React
|
|
5
|
+
context/hooks, secure-storage adapters, and provider sign-in buttons without
|
|
6
|
+
forcing users through Authara's browser UI.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @authara/react-native react react-native react-native-svg
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Expo apps can install the native pieces they use:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npx expo install expo-secure-store
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Set up
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
import { AutharaProvider, createAuthara } from "@authara/react-native";
|
|
24
|
+
import { createExpoSecureStore } from "@authara/react-native/expo-secure-store";
|
|
25
|
+
|
|
26
|
+
const authara = createAuthara({
|
|
27
|
+
baseUrl: "https://auth.example.com",
|
|
28
|
+
storage: createExpoSecureStore(),
|
|
29
|
+
providers: {
|
|
30
|
+
google: googleAdapter,
|
|
31
|
+
apple: appleAdapter,
|
|
32
|
+
microsoft: microsoftAdapter,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export function App() {
|
|
37
|
+
return (
|
|
38
|
+
<AutharaProvider client={authara}>
|
|
39
|
+
<Routes />
|
|
40
|
+
</AutharaProvider>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The access token stays in memory. Only the rotating refresh token is persisted
|
|
46
|
+
through `AutharaTokenStorage`. On startup, `AutharaProvider` restores the
|
|
47
|
+
session by rotating that token. Concurrent 401 responses share one refresh,
|
|
48
|
+
then each request retries once with `Authorization: Bearer …`.
|
|
49
|
+
|
|
50
|
+
## Native provider adapters
|
|
51
|
+
|
|
52
|
+
Authara accepts small adapters so applications can control their native setup,
|
|
53
|
+
provider versions, and branding-compliant controls. The package also ships
|
|
54
|
+
optional Expo adapters for the common iOS setup:
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import { createExpoAppleAuthentication } from "@authara/react-native/expo-apple-authentication";
|
|
58
|
+
import { createExpoMicrosoftAuthSession } from "@authara/react-native/expo-microsoft-auth-session";
|
|
59
|
+
import { createNitroGoogleSignIn } from "@authara/react-native/nitro-google-signin";
|
|
60
|
+
|
|
61
|
+
const providers = {
|
|
62
|
+
apple: createExpoAppleAuthentication(),
|
|
63
|
+
google: createNitroGoogleSignIn({ iosClientId: GOOGLE_IOS_CLIENT_ID }),
|
|
64
|
+
microsoft: createExpoMicrosoftAuthSession({ scheme: "my-app" }),
|
|
65
|
+
};
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Install only the provider packages the application uses. Apple and Google use
|
|
69
|
+
their native iOS SDK surfaces. Microsoft uses the secure system authentication
|
|
70
|
+
sheet for general Microsoft work and personal accounts.
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import type { GoogleNativeAdapter } from "@authara/react-native";
|
|
74
|
+
|
|
75
|
+
export const googleAdapter: GoogleNativeAdapter = {
|
|
76
|
+
async authorize({ client_id, nonce }) {
|
|
77
|
+
// Configure/invoke your native Google SDK with Authara's nonce.
|
|
78
|
+
const result = await nativeGoogleSignIn({ clientId: client_id, nonce });
|
|
79
|
+
return { credential: result.idToken };
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The contract is equivalent for Apple (`code`) and Microsoft (`credential`).
|
|
85
|
+
Authara supplies a database-backed one-time `challenge_id`, state, and nonce;
|
|
86
|
+
the client returns them with the provider proof. No Authara cookie is involved.
|
|
87
|
+
|
|
88
|
+
## Buttons and hooks
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
import {
|
|
92
|
+
AppleButton,
|
|
93
|
+
GoogleButton,
|
|
94
|
+
MicrosoftButton,
|
|
95
|
+
useAuthara,
|
|
96
|
+
} from "@authara/react-native";
|
|
97
|
+
|
|
98
|
+
function Login() {
|
|
99
|
+
const { status, user } = useAuthara();
|
|
100
|
+
if (status === "authenticated") return <Home user={user} />;
|
|
101
|
+
return (
|
|
102
|
+
<>
|
|
103
|
+
<GoogleButton />
|
|
104
|
+
<AppleButton />
|
|
105
|
+
<MicrosoftButton />
|
|
106
|
+
</>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
The included buttons render their provider icon, loading state, and an
|
|
112
|
+
accessible inline error directly below the failed control. This feedback is
|
|
113
|
+
enabled by default, so a provider configuration error cannot disappear below
|
|
114
|
+
the rest of a sign-in form. Use `showError={false}` with `onError` when the
|
|
115
|
+
application deliberately owns error presentation.
|
|
116
|
+
|
|
117
|
+
The public button contract mirrors `@authara/react`: `action` supports `login`,
|
|
118
|
+
`link`, `reauthenticate`, and `recover`; `variant` accepts `text`, `provider`,
|
|
119
|
+
or `icon`; `size` accepts `small`, `medium`, or `large`; `label` accepts
|
|
120
|
+
`sign-in`, `sign-up`, or `continue`; and `mode` accepts `light`, `dark`, or
|
|
121
|
+
`system`. Success callbacks receive `{ action, provider, session? }`, and
|
|
122
|
+
`onError` receives a structured `AutharaButtonError`.
|
|
123
|
+
|
|
124
|
+
```tsx
|
|
125
|
+
<GoogleButton
|
|
126
|
+
action="login"
|
|
127
|
+
mode="system"
|
|
128
|
+
size="large"
|
|
129
|
+
shape="rectangular"
|
|
130
|
+
logoAlignment="left"
|
|
131
|
+
/>
|
|
132
|
+
<AppleButton
|
|
133
|
+
action="link"
|
|
134
|
+
variant="provider"
|
|
135
|
+
color="black"
|
|
136
|
+
borderRadius={12}
|
|
137
|
+
/>
|
|
138
|
+
<MicrosoftButton
|
|
139
|
+
action="reauthenticate"
|
|
140
|
+
authenticationChallengeId={challenge.id}
|
|
141
|
+
variant="icon"
|
|
142
|
+
accessibilityLabel="Use Microsoft"
|
|
143
|
+
/>
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Text-button heights are 30, 36, and 44 points; icon buttons are 36, 44, and
|
|
147
|
+
52 points. Google additionally exposes `theme`, `border`, `shape`, and
|
|
148
|
+
`logoAlignment`; Apple exposes `color`, `border`, `borderRadius`, and `align`;
|
|
149
|
+
Microsoft exposes `border` and `align`. All three accept `buttonText`, `width`,
|
|
150
|
+
`fallback`, `onUnavailable`, and normal React Native `Pressable` properties.
|
|
151
|
+
Apple and Microsoft cancellation calls `onCancel`, not `onError`.
|
|
152
|
+
|
|
153
|
+
Google and Microsoft use their full-color SVG marks on white surfaces. Their
|
|
154
|
+
defaults have grey borders in light mode and no borders in dark mode. Explicit
|
|
155
|
+
Google `theme` or either component's `border` property overrides those
|
|
156
|
+
defaults.
|
|
157
|
+
|
|
158
|
+
Every control invokes the configured native adapter and then completes the
|
|
159
|
+
Authara token flow. Applications can style the exported component, but do not
|
|
160
|
+
need to recreate its icon, pending state, or error handling.
|
|
161
|
+
|
|
162
|
+
### Account collisions and safe linking
|
|
163
|
+
|
|
164
|
+
Provider login can return `account_link_required` when its verified email is
|
|
165
|
+
already owned by another authentication method. The structured button error
|
|
166
|
+
contains a short-lived recovery link and the existing methods that may prove
|
|
167
|
+
account ownership. Never link from an email match alone.
|
|
168
|
+
|
|
169
|
+
```tsx
|
|
170
|
+
const [recovery, setRecovery] = useState<AutharaAccountRecoveryLink>();
|
|
171
|
+
|
|
172
|
+
const onError = (error: AutharaButtonError) => {
|
|
173
|
+
if (error.code === "account_link_required" && error.recovery) {
|
|
174
|
+
setRecovery(error.recovery);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
return recovery?.proof_methods.includes("google") ? (
|
|
179
|
+
<GoogleButton
|
|
180
|
+
action="recover"
|
|
181
|
+
recoveryLinkId={recovery.link_id}
|
|
182
|
+
onSuccess={() => setRecovery(undefined)}
|
|
183
|
+
onError={onError}
|
|
184
|
+
/>
|
|
185
|
+
) : (
|
|
186
|
+
<MicrosoftButton onError={onError} />
|
|
187
|
+
);
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
The included iOS playground implements the complete version of this flow,
|
|
191
|
+
including Apple, Google, Microsoft, and password proof.
|
|
192
|
+
|
|
193
|
+
## Password and full API
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
await authara.signInWithPassword(email, password);
|
|
197
|
+
const account = await authara.getCurrentAccount();
|
|
198
|
+
await authara.changeCurrentUsername({ body: { username: "new-name" } });
|
|
199
|
+
await authara.signOut();
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Every generated public/user operation is available directly on the client.
|
|
203
|
+
Session-creating calls use `session_transport=token`; protected calls use the
|
|
204
|
+
in-memory bearer token. `signOut()` attempts `/tokens/revoke` and always removes
|
|
205
|
+
local credentials, including while offline.
|
|
206
|
+
|
|
207
|
+
## What the application still configures
|
|
208
|
+
|
|
209
|
+
- iOS bundle ID, Sign in with Apple entitlement, URL schemes, and provider IDs
|
|
210
|
+
- Android application ID, signing certificate fingerprints, and intent filters
|
|
211
|
+
- Google/Apple/Microsoft native SDK installation and provider console settings
|
|
212
|
+
- navigation after authentication and deletion of app-owned cached user data
|
|
213
|
+
- platform keychain/keystore accessibility policy when constructing storage
|
|
214
|
+
|
|
215
|
+
Do not put OAuth client secrets in the mobile application.
|
|
216
|
+
|
|
217
|
+
## Local iOS simulator
|
|
218
|
+
|
|
219
|
+
The repository includes a native Expo development app that runs against the
|
|
220
|
+
real Authara Core Docker stack. From the SDK root:
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
cp .env.example .env
|
|
224
|
+
npm run example:ios
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
This builds the local SDK, starts the repository-owned Compose stack and
|
|
228
|
+
Cloudflare tunnel from pinned Authara images, uses
|
|
229
|
+
`https://playground.authara.org`, installs the example dependencies on first
|
|
230
|
+
run, and launches an iOS Simulator build with all three provider buttons. Set
|
|
231
|
+
`AUTHARA_EXAMPLE_CORE_DIR=/path/to/authara-core` to build an unreleased local
|
|
232
|
+
Core checkout with the repository-owned Compose override.
|
|
233
|
+
|
|
234
|
+
The app is structured like a real account product rather than an endpoint
|
|
235
|
+
console. Its Profile, Workspaces, and Security areas cover account details,
|
|
236
|
+
sessions, provider linking, reauthentication, email and password changes,
|
|
237
|
+
organizations, members, roles, invitations, password reset, and account-link
|
|
238
|
+
recovery. Browser-cookie internals and operations that require a native
|
|
239
|
+
WebAuthn adapter are intentionally not presented as user-facing controls.
|
|
240
|
+
|
|
241
|
+
The ignored root `.env` is the repository's single source for playground and
|
|
242
|
+
native-provider configuration; the React Native project does not read another
|
|
243
|
+
SDK's environment file.
|
|
244
|
+
See [`examples/ios-simulator/README.md`](examples/ios-simulator/README.md) for
|
|
245
|
+
Xcode prerequisites, provider registrations, Mailpit verification, and Expo Go.
|
|
246
|
+
|
|
247
|
+
## Contract provenance
|
|
248
|
+
|
|
249
|
+
`src/generated` is generated from Authara Core's canonical OpenAPI contract.
|
|
250
|
+
Publishing is blocked until `.codegen/manifest.json` identifies an immutable
|
|
251
|
+
Core release tag and exact commit.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { DimensionValue, TextStyle } from "react-native";
|
|
2
|
+
import type { AutharaButtonLabel, AutharaButtonSize, AutharaButtonVariant } from "./buttons.js";
|
|
3
|
+
export type ButtonAppearance = {
|
|
4
|
+
height: number;
|
|
5
|
+
width: DimensionValue;
|
|
6
|
+
fill: string;
|
|
7
|
+
text: string;
|
|
8
|
+
border: string;
|
|
9
|
+
borderRadius: number;
|
|
10
|
+
borderWidth: number;
|
|
11
|
+
fontFamily: string;
|
|
12
|
+
fontWeight: TextStyle["fontWeight"];
|
|
13
|
+
horizontalPadding: number;
|
|
14
|
+
iconLeft?: number;
|
|
15
|
+
};
|
|
16
|
+
export declare function autharaButtonLabel(label: AutharaButtonLabel, provider: string): string;
|
|
17
|
+
export declare function googleButtonAppearance(options: {
|
|
18
|
+
variant: AutharaButtonVariant;
|
|
19
|
+
size: AutharaButtonSize;
|
|
20
|
+
width?: DimensionValue;
|
|
21
|
+
mode: "light" | "dark";
|
|
22
|
+
theme?: "light" | "dark" | "neutral";
|
|
23
|
+
border?: boolean;
|
|
24
|
+
shape: "pill" | "circle" | "square" | "rectangular";
|
|
25
|
+
logoAlignment: "left" | "center";
|
|
26
|
+
}): ButtonAppearance;
|
|
27
|
+
export declare function appleButtonAppearance(options: {
|
|
28
|
+
variant: AutharaButtonVariant;
|
|
29
|
+
size: AutharaButtonSize;
|
|
30
|
+
width?: DimensionValue;
|
|
31
|
+
color: "black" | "white";
|
|
32
|
+
border: boolean;
|
|
33
|
+
borderRadius: number;
|
|
34
|
+
align: "left" | "center";
|
|
35
|
+
}): ButtonAppearance;
|
|
36
|
+
export declare function microsoftButtonAppearance(options: {
|
|
37
|
+
variant: AutharaButtonVariant;
|
|
38
|
+
size: AutharaButtonSize;
|
|
39
|
+
width?: DimensionValue;
|
|
40
|
+
mode: "light" | "dark";
|
|
41
|
+
border?: boolean;
|
|
42
|
+
align: "left" | "center";
|
|
43
|
+
}): ButtonAppearance;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
const textButtonHeights = {
|
|
2
|
+
small: 30,
|
|
3
|
+
medium: 36,
|
|
4
|
+
large: 44,
|
|
5
|
+
};
|
|
6
|
+
const iconButtonSizes = {
|
|
7
|
+
small: 36,
|
|
8
|
+
medium: 44,
|
|
9
|
+
large: 52,
|
|
10
|
+
};
|
|
11
|
+
export function autharaButtonLabel(label, provider) {
|
|
12
|
+
switch (label) {
|
|
13
|
+
case "sign-in":
|
|
14
|
+
return `Sign in with ${provider}`;
|
|
15
|
+
case "sign-up":
|
|
16
|
+
return `Sign up with ${provider}`;
|
|
17
|
+
case "continue":
|
|
18
|
+
return `Continue with ${provider}`;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function dimensions(variant, size, width) {
|
|
22
|
+
const height = variant === "icon" ? iconButtonSizes[size] : textButtonHeights[size];
|
|
23
|
+
return { height, width: width ?? (variant === "icon" ? height : "100%") };
|
|
24
|
+
}
|
|
25
|
+
export function googleButtonAppearance(options) {
|
|
26
|
+
const { height, width } = dimensions(options.variant, options.size, options.width);
|
|
27
|
+
const resolvedTheme = options.theme ?? "light";
|
|
28
|
+
const palette = {
|
|
29
|
+
light: { fill: "#ffffff", text: "#1f1f1f", border: "#747775" },
|
|
30
|
+
dark: { fill: "#131314", text: "#e3e3e3", border: "#8e918f" },
|
|
31
|
+
neutral: {
|
|
32
|
+
fill: "#f2f2f2",
|
|
33
|
+
text: "#1f1f1f",
|
|
34
|
+
border: "transparent",
|
|
35
|
+
},
|
|
36
|
+
}[resolvedTheme];
|
|
37
|
+
const borderRadius = options.shape === "circle" || options.shape === "pill"
|
|
38
|
+
? height / 2
|
|
39
|
+
: options.shape === "square"
|
|
40
|
+
? 6
|
|
41
|
+
: 12;
|
|
42
|
+
const showBorder = options.border ??
|
|
43
|
+
(options.theme === undefined
|
|
44
|
+
? options.mode === "light"
|
|
45
|
+
: resolvedTheme !== "neutral");
|
|
46
|
+
return {
|
|
47
|
+
height,
|
|
48
|
+
width,
|
|
49
|
+
fill: palette.fill,
|
|
50
|
+
text: palette.text,
|
|
51
|
+
border: showBorder ? palette.border : "transparent",
|
|
52
|
+
borderRadius,
|
|
53
|
+
borderWidth: showBorder ? 1 : 0,
|
|
54
|
+
fontFamily: "Arial",
|
|
55
|
+
fontWeight: "500",
|
|
56
|
+
horizontalPadding: 12,
|
|
57
|
+
iconLeft: options.variant !== "icon" && options.logoAlignment === "left"
|
|
58
|
+
? 12
|
|
59
|
+
: undefined,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export function appleButtonAppearance(options) {
|
|
63
|
+
if (!Number.isFinite(options.borderRadius) ||
|
|
64
|
+
options.borderRadius < 0 ||
|
|
65
|
+
options.borderRadius > 50) {
|
|
66
|
+
throw new RangeError("Apple button borderRadius must be between 0 and 50.");
|
|
67
|
+
}
|
|
68
|
+
const { height, width } = dimensions(options.variant, options.size, options.width);
|
|
69
|
+
return {
|
|
70
|
+
height,
|
|
71
|
+
width,
|
|
72
|
+
fill: options.color === "black" ? "#000000" : "#ffffff",
|
|
73
|
+
text: options.color === "black" ? "#ffffff" : "#202124",
|
|
74
|
+
border: options.border && options.color === "black"
|
|
75
|
+
? "#000000"
|
|
76
|
+
: options.border
|
|
77
|
+
? "#9aa0a6"
|
|
78
|
+
: "transparent",
|
|
79
|
+
borderRadius: options.borderRadius,
|
|
80
|
+
borderWidth: 1,
|
|
81
|
+
fontFamily: "Arial",
|
|
82
|
+
fontWeight: "500",
|
|
83
|
+
horizontalPadding: 14,
|
|
84
|
+
iconLeft: options.variant !== "icon" && options.align === "left" ? 14 : undefined,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
export function microsoftButtonAppearance(options) {
|
|
88
|
+
const { height, width } = dimensions(options.variant, options.size, options.width);
|
|
89
|
+
const showBorder = options.border ?? options.mode === "light";
|
|
90
|
+
return {
|
|
91
|
+
height,
|
|
92
|
+
width,
|
|
93
|
+
fill: "#ffffff",
|
|
94
|
+
text: "#1f1f1f",
|
|
95
|
+
border: showBorder ? "#8c8c8c" : "transparent",
|
|
96
|
+
borderRadius: 12,
|
|
97
|
+
borderWidth: showBorder ? 1 : 0,
|
|
98
|
+
fontFamily: "Arial",
|
|
99
|
+
fontWeight: "600",
|
|
100
|
+
horizontalPadding: 12,
|
|
101
|
+
iconLeft: options.variant !== "icon" && options.align === "left" ? 12 : undefined,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { AutharaAudience } from "./client.js";
|
|
2
|
+
import type { AutharaButtonError, AutharaLinkErrorCode, AutharaLoginErrorCode, AutharaRecoveryErrorCode, AutharaReauthenticationErrorCode } from "./button-error.js";
|
|
3
|
+
import type { AccountRecoveryLink, AuthSession } from "./generated/types.js";
|
|
4
|
+
export type MaybePromise<T> = T | Promise<T>;
|
|
5
|
+
export type AutharaAction = "login" | "link" | "reauthenticate" | "recover";
|
|
6
|
+
export type AutharaProviderName = "apple" | "google" | "microsoft";
|
|
7
|
+
export type AutharaAccountRecoveryLink = AccountRecoveryLink;
|
|
8
|
+
export type AutharaLoginSuccess<P extends AutharaProviderName> = {
|
|
9
|
+
action: "login";
|
|
10
|
+
provider: P;
|
|
11
|
+
session: AuthSession;
|
|
12
|
+
};
|
|
13
|
+
export type AutharaLinkSuccess<P extends AutharaProviderName> = {
|
|
14
|
+
action: "link";
|
|
15
|
+
provider: P;
|
|
16
|
+
};
|
|
17
|
+
export type AutharaReauthenticationSuccess<P extends AutharaProviderName> = {
|
|
18
|
+
action: "reauthenticate";
|
|
19
|
+
provider: P;
|
|
20
|
+
};
|
|
21
|
+
export type AutharaRecoverySuccess<P extends AutharaProviderName> = {
|
|
22
|
+
action: "recover";
|
|
23
|
+
provider: P;
|
|
24
|
+
session: AuthSession;
|
|
25
|
+
};
|
|
26
|
+
export type AutharaActionSuccess<P extends AutharaProviderName> = AutharaLoginSuccess<P> | AutharaLinkSuccess<P> | AutharaReauthenticationSuccess<P> | AutharaRecoverySuccess<P>;
|
|
27
|
+
export type AutharaActionProps<P extends AutharaProviderName> = {
|
|
28
|
+
action?: "login";
|
|
29
|
+
audience?: AutharaAudience;
|
|
30
|
+
authenticationChallengeId?: never;
|
|
31
|
+
recoveryLinkId?: never;
|
|
32
|
+
onSuccess?: (result: AutharaLoginSuccess<P>) => MaybePromise<void>;
|
|
33
|
+
onError?: (error: AutharaButtonError<AutharaLoginErrorCode>) => void;
|
|
34
|
+
} | {
|
|
35
|
+
action: "link";
|
|
36
|
+
audience?: never;
|
|
37
|
+
authenticationChallengeId?: never;
|
|
38
|
+
recoveryLinkId?: never;
|
|
39
|
+
onSuccess?: (result: AutharaLinkSuccess<P>) => MaybePromise<void>;
|
|
40
|
+
onError?: (error: AutharaButtonError<AutharaLinkErrorCode>) => void;
|
|
41
|
+
} | {
|
|
42
|
+
action: "reauthenticate";
|
|
43
|
+
audience?: never;
|
|
44
|
+
authenticationChallengeId: string;
|
|
45
|
+
recoveryLinkId?: never;
|
|
46
|
+
onSuccess?: (result: AutharaReauthenticationSuccess<P>) => MaybePromise<void>;
|
|
47
|
+
onError?: (error: AutharaButtonError<AutharaReauthenticationErrorCode>) => void;
|
|
48
|
+
} | {
|
|
49
|
+
action: "recover";
|
|
50
|
+
audience?: "app";
|
|
51
|
+
authenticationChallengeId?: never;
|
|
52
|
+
recoveryLinkId: AccountRecoveryLink["link_id"];
|
|
53
|
+
onSuccess?: (result: AutharaRecoverySuccess<P>) => MaybePromise<void>;
|
|
54
|
+
onError?: (error: AutharaButtonError<AutharaRecoveryErrorCode>) => void;
|
|
55
|
+
};
|
|
56
|
+
export type ResolvedAutharaAction = {
|
|
57
|
+
action: "login";
|
|
58
|
+
audience: AutharaAudience;
|
|
59
|
+
} | {
|
|
60
|
+
action: "link";
|
|
61
|
+
} | {
|
|
62
|
+
action: "reauthenticate";
|
|
63
|
+
authenticationChallengeId: string;
|
|
64
|
+
} | {
|
|
65
|
+
action: "recover";
|
|
66
|
+
audience: "app";
|
|
67
|
+
recoveryLinkId: string;
|
|
68
|
+
};
|
|
69
|
+
export declare function resolveAutharaAction(action: AutharaAction | undefined, audience: AutharaAudience | undefined, authenticationChallengeId: string | undefined, recoveryLinkId: string | undefined): ResolvedAutharaAction;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function resolveAutharaAction(action, audience, authenticationChallengeId, recoveryLinkId) {
|
|
2
|
+
if (action === "link")
|
|
3
|
+
return { action };
|
|
4
|
+
if (action === "reauthenticate") {
|
|
5
|
+
if (!authenticationChallengeId) {
|
|
6
|
+
throw new Error("authenticationChallengeId is required for reauthentication.");
|
|
7
|
+
}
|
|
8
|
+
return { action, authenticationChallengeId };
|
|
9
|
+
}
|
|
10
|
+
if (action === "recover") {
|
|
11
|
+
if (!recoveryLinkId) {
|
|
12
|
+
throw new Error("recoveryLinkId is required for account recovery.");
|
|
13
|
+
}
|
|
14
|
+
return { action, audience: "app", recoveryLinkId };
|
|
15
|
+
}
|
|
16
|
+
return { action: "login", audience: audience ?? "app" };
|
|
17
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type AutharaContractErrorCode } from "./generated/error-codes.js";
|
|
2
|
+
import type { AccountRecoveryLink } from "./generated/types.js";
|
|
3
|
+
export type AutharaButtonErrorSource = "authara" | "provider" | "configuration" | "consumer";
|
|
4
|
+
export type AutharaLocalErrorCode = "unknown_authara_error";
|
|
5
|
+
export type AutharaLoginErrorCode = AutharaContractErrorCode<"login"> | AutharaLocalErrorCode;
|
|
6
|
+
export type AutharaLinkErrorCode = AutharaContractErrorCode<"link"> | AutharaLocalErrorCode;
|
|
7
|
+
export type AutharaReauthenticationErrorCode = AutharaContractErrorCode<"reauthenticate"> | AutharaLocalErrorCode;
|
|
8
|
+
export type AutharaRecoveryErrorCode = AutharaContractErrorCode<"recover"> | AutharaLocalErrorCode;
|
|
9
|
+
export type AutharaButtonErrorCode = AutharaLoginErrorCode | AutharaLinkErrorCode | AutharaReauthenticationErrorCode | AutharaRecoveryErrorCode;
|
|
10
|
+
export declare class AutharaButtonError<Code extends string = AutharaButtonErrorCode> extends Error {
|
|
11
|
+
readonly source: AutharaButtonErrorSource;
|
|
12
|
+
readonly code?: Code;
|
|
13
|
+
readonly serverCode?: string;
|
|
14
|
+
readonly status?: number;
|
|
15
|
+
readonly authenticationChallenge?: {
|
|
16
|
+
id: string;
|
|
17
|
+
expires_at: string;
|
|
18
|
+
};
|
|
19
|
+
readonly reauthenticateUrl?: string;
|
|
20
|
+
readonly recovery?: AccountRecoveryLink;
|
|
21
|
+
readonly originalError: unknown;
|
|
22
|
+
constructor(message: string, source: AutharaButtonErrorSource, originalError: unknown, metadata?: {
|
|
23
|
+
code?: string;
|
|
24
|
+
serverCode?: string;
|
|
25
|
+
status?: number;
|
|
26
|
+
authenticationChallenge?: {
|
|
27
|
+
id: string;
|
|
28
|
+
expires_at: string;
|
|
29
|
+
};
|
|
30
|
+
reauthenticateUrl?: string;
|
|
31
|
+
recovery?: AccountRecoveryLink;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
export declare class AutharaProviderCancellationError extends Error {
|
|
35
|
+
constructor(provider: string);
|
|
36
|
+
}
|
|
37
|
+
export declare function isAutharaButtonError(error: unknown): error is AutharaButtonError;
|
|
38
|
+
export declare function isAutharaProviderCancellation(error: unknown): error is AutharaProviderCancellationError;
|
|
39
|
+
export declare function toAutharaButtonError(error: unknown, fallback: string, source: AutharaButtonErrorSource): AutharaButtonError;
|
|
40
|
+
export declare function autharaButtonErrorMessage(error: unknown): string;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { AutharaApiError } from "./client.js";
|
|
2
|
+
import { autharaActionErrorCodes, } from "./generated/error-codes.js";
|
|
3
|
+
const knownAutharaErrorCodes = new Set([
|
|
4
|
+
...autharaActionErrorCodes.login,
|
|
5
|
+
...autharaActionErrorCodes.link,
|
|
6
|
+
...autharaActionErrorCodes.reauthenticate,
|
|
7
|
+
...autharaActionErrorCodes.recover,
|
|
8
|
+
]);
|
|
9
|
+
export class AutharaButtonError extends Error {
|
|
10
|
+
source;
|
|
11
|
+
code;
|
|
12
|
+
serverCode;
|
|
13
|
+
status;
|
|
14
|
+
authenticationChallenge;
|
|
15
|
+
reauthenticateUrl;
|
|
16
|
+
recovery;
|
|
17
|
+
originalError;
|
|
18
|
+
constructor(message, source, originalError, metadata = {}) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = "AutharaButtonError";
|
|
21
|
+
this.source = source;
|
|
22
|
+
this.originalError = originalError;
|
|
23
|
+
this.code = metadata.code;
|
|
24
|
+
this.serverCode = metadata.serverCode;
|
|
25
|
+
this.status = metadata.status;
|
|
26
|
+
this.authenticationChallenge = metadata.authenticationChallenge;
|
|
27
|
+
this.reauthenticateUrl = metadata.reauthenticateUrl;
|
|
28
|
+
this.recovery = metadata.recovery;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export class AutharaProviderCancellationError extends Error {
|
|
32
|
+
constructor(provider) {
|
|
33
|
+
super(`${provider} sign-in was cancelled`);
|
|
34
|
+
this.name = "AutharaProviderCancellationError";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function isAutharaButtonError(error) {
|
|
38
|
+
return error instanceof AutharaButtonError;
|
|
39
|
+
}
|
|
40
|
+
export function isAutharaProviderCancellation(error) {
|
|
41
|
+
return error instanceof AutharaProviderCancellationError;
|
|
42
|
+
}
|
|
43
|
+
export function toAutharaButtonError(error, fallback, source) {
|
|
44
|
+
if (error instanceof AutharaButtonError)
|
|
45
|
+
return error;
|
|
46
|
+
const message = error instanceof Error && error.message.trim()
|
|
47
|
+
? error.message
|
|
48
|
+
: typeof error === "object" &&
|
|
49
|
+
error !== null &&
|
|
50
|
+
"message" in error &&
|
|
51
|
+
typeof error.message === "string" &&
|
|
52
|
+
error.message.trim()
|
|
53
|
+
? error.message.trim()
|
|
54
|
+
: fallback;
|
|
55
|
+
if (error instanceof AutharaApiError) {
|
|
56
|
+
const knownCode = error.code !== undefined && knownAutharaErrorCodes.has(error.code);
|
|
57
|
+
return new AutharaButtonError(message, "authara", error, {
|
|
58
|
+
code: knownCode ? error.code : "unknown_authara_error",
|
|
59
|
+
serverCode: knownCode ? undefined : error.code,
|
|
60
|
+
status: error.status,
|
|
61
|
+
authenticationChallenge: error.details?.authentication_challenge,
|
|
62
|
+
reauthenticateUrl: error.details?.reauthenticate_url,
|
|
63
|
+
recovery: error.details?.recovery,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return new AutharaButtonError(message, source, error);
|
|
67
|
+
}
|
|
68
|
+
export function autharaButtonErrorMessage(error) {
|
|
69
|
+
return error instanceof Error ? error.message : String(error);
|
|
70
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type DimensionValue, type PressableProps, type StyleProp, type TextStyle, type ViewStyle } from "react-native";
|
|
3
|
+
import { type AutharaActionProps } from "./button-contract.js";
|
|
4
|
+
export type AutharaButtonVariant = "icon" | "provider" | "text";
|
|
5
|
+
export type AutharaButtonLabel = "continue" | "sign-in" | "sign-up";
|
|
6
|
+
export type AutharaButtonSize = "small" | "medium" | "large";
|
|
7
|
+
export type AutharaColorMode = "light" | "dark" | "system";
|
|
8
|
+
export type AutharaButtonMode = AutharaColorMode;
|
|
9
|
+
interface AutharaNativeControlProps extends Omit<PressableProps, "children" | "style"> {
|
|
10
|
+
buttonText?: string;
|
|
11
|
+
width?: DimensionValue;
|
|
12
|
+
style?: StyleProp<ViewStyle>;
|
|
13
|
+
textStyle?: StyleProp<TextStyle>;
|
|
14
|
+
errorTextStyle?: StyleProp<TextStyle>;
|
|
15
|
+
fallback?: ReactNode;
|
|
16
|
+
showError?: boolean;
|
|
17
|
+
onUnavailable?: () => void;
|
|
18
|
+
}
|
|
19
|
+
interface AutharaButtonVisualProps extends AutharaNativeControlProps {
|
|
20
|
+
variant?: AutharaButtonVariant;
|
|
21
|
+
size?: AutharaButtonSize;
|
|
22
|
+
label?: AutharaButtonLabel;
|
|
23
|
+
mode?: AutharaColorMode;
|
|
24
|
+
}
|
|
25
|
+
export interface GoogleButtonVisualProps extends AutharaButtonVisualProps {
|
|
26
|
+
locale?: string;
|
|
27
|
+
theme?: "light" | "dark" | "neutral";
|
|
28
|
+
border?: boolean;
|
|
29
|
+
shape?: "pill" | "circle" | "square" | "rectangular";
|
|
30
|
+
logoAlignment?: "left" | "center";
|
|
31
|
+
}
|
|
32
|
+
export interface AppleButtonVisualProps extends AutharaButtonVisualProps {
|
|
33
|
+
locale?: string;
|
|
34
|
+
color?: "black" | "white";
|
|
35
|
+
border?: boolean;
|
|
36
|
+
borderRadius?: number;
|
|
37
|
+
align?: "center" | "left";
|
|
38
|
+
onCancel?: () => void;
|
|
39
|
+
}
|
|
40
|
+
export interface MicrosoftButtonVisualProps extends AutharaButtonVisualProps {
|
|
41
|
+
border?: boolean;
|
|
42
|
+
align?: "center" | "left";
|
|
43
|
+
onCancel?: () => void;
|
|
44
|
+
}
|
|
45
|
+
export type GoogleButtonProps = GoogleButtonVisualProps & AutharaActionProps<"google">;
|
|
46
|
+
export type AppleButtonProps = AppleButtonVisualProps & AutharaActionProps<"apple">;
|
|
47
|
+
export type MicrosoftButtonProps = MicrosoftButtonVisualProps & AutharaActionProps<"microsoft">;
|
|
48
|
+
/** @deprecated Prefer the provider-specific button prop type. */
|
|
49
|
+
export type AutharaButtonProps = GoogleButtonProps | AppleButtonProps | MicrosoftButtonProps;
|
|
50
|
+
export declare function GoogleButton(props: GoogleButtonProps): import("react").JSX.Element;
|
|
51
|
+
export declare function AppleButton(props: AppleButtonProps): import("react").JSX.Element;
|
|
52
|
+
export declare function MicrosoftButton(props: MicrosoftButtonProps): import("react").JSX.Element;
|
|
53
|
+
export {};
|