@0xkey-io/react-native-wallet-kit 0.1.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 +201 -0
- package/README.md +93 -0
- package/dist/hooks/use-0xkey.d.ts +3 -0
- package/dist/hooks/use-0xkey.d.ts.map +1 -0
- package/dist/hooks/use-0xkey.js +15 -0
- package/dist/hooks/use-0xkey.js.map +1 -0
- package/dist/hooks/use-0xkey.mjs +13 -0
- package/dist/hooks/use-0xkey.mjs.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +55 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +6 -0
- package/dist/index.mjs.map +1 -0
- package/dist/providers/Types.d.ts +275 -0
- package/dist/providers/Types.d.ts.map +1 -0
- package/dist/providers/Types.js +9 -0
- package/dist/providers/Types.js.map +1 -0
- package/dist/providers/Types.mjs +7 -0
- package/dist/providers/Types.mjs.map +1 -0
- package/dist/providers/ZeroXKeyProvider.d.ts +39 -0
- package/dist/providers/ZeroXKeyProvider.d.ts.map +1 -0
- package/dist/providers/ZeroXKeyProvider.js +1846 -0
- package/dist/providers/ZeroXKeyProvider.js.map +1 -0
- package/dist/providers/ZeroXKeyProvider.mjs +1844 -0
- package/dist/providers/ZeroXKeyProvider.mjs.map +1 -0
- package/dist/providers/index.d.ts +4 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/tests/oauth-test.d.ts +2 -0
- package/dist/tests/oauth-test.d.ts.map +1 -0
- package/dist/typedoc-entry/index.d.ts +5 -0
- package/dist/typedoc-entry/index.d.ts.map +1 -0
- package/dist/types/base.d.ts +137 -0
- package/dist/types/base.d.ts.map +1 -0
- package/dist/types/base.js +48 -0
- package/dist/types/base.js.map +1 -0
- package/dist/types/base.mjs +48 -0
- package/dist/types/base.mjs.map +1 -0
- package/dist/types/method-types.d.ts +102 -0
- package/dist/types/method-types.d.ts.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/oauth.d.ts +240 -0
- package/dist/utils/oauth.d.ts.map +1 -0
- package/dist/utils/oauth.js +340 -0
- package/dist/utils/oauth.js.map +1 -0
- package/dist/utils/oauth.mjs +319 -0
- package/dist/utils/oauth.mjs.map +1 -0
- package/dist/utils/timers.d.ts +73 -0
- package/dist/utils/timers.d.ts.map +1 -0
- package/dist/utils/timers.js +132 -0
- package/dist/utils/timers.js.map +1 -0
- package/dist/utils/timers.mjs +122 -0
- package/dist/utils/timers.mjs.map +1 -0
- package/dist/utils/utils.d.ts +27 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +37 -0
- package/dist/utils/utils.js.map +1 -0
- package/dist/utils/utils.mjs +33 -0
- package/dist/utils/utils.mjs.map +1 -0
- package/package.json +80 -0
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { AuthAction, BaseAuthResult, OAuthProviders } from "@0xkey-io/sdk-types";
|
|
2
|
+
export declare const DISCORD_AUTH_URL = "https://discord.com/oauth2/authorize";
|
|
3
|
+
export declare const X_AUTH_URL = "https://x.com/i/oauth2/authorize";
|
|
4
|
+
export declare const GOOGLE_AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth";
|
|
5
|
+
export declare const APPLE_AUTH_URL = "https://account.apple.com/auth/authorize";
|
|
6
|
+
export declare const APPLE_AUTH_SCRIPT_URL = "https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js";
|
|
7
|
+
export declare const FACEBOOK_AUTH_URL = "https://www.facebook.com/v23.0/dialog/oauth";
|
|
8
|
+
export declare const FACEBOOK_GRAPH_URL = "https://graph.facebook.com/v23.0/oauth/access_token";
|
|
9
|
+
export declare const ZEROXKEY_OAUTH_ORIGIN_URL = "https://oauth-origin.0xkey.com";
|
|
10
|
+
export declare const ZEROXKEY_OAUTH_REDIRECT_URL = "https://oauth-redirect.0xkey.com";
|
|
11
|
+
/**
|
|
12
|
+
* Builds the OAuth state parameter string
|
|
13
|
+
*/
|
|
14
|
+
export declare function buildOAuthState(params: {
|
|
15
|
+
provider: OAuthProviders;
|
|
16
|
+
flow: "redirect";
|
|
17
|
+
publicKey: string;
|
|
18
|
+
nonce?: string;
|
|
19
|
+
additionalState?: Record<string, string> | undefined;
|
|
20
|
+
}): string;
|
|
21
|
+
/**
|
|
22
|
+
* OAuth provider configuration for unified OAuth flow handling
|
|
23
|
+
*/
|
|
24
|
+
export interface OAuthProviderConfig {
|
|
25
|
+
/** The provider identifier */
|
|
26
|
+
provider: OAuthProviders;
|
|
27
|
+
/** The base OAuth authorization URL */
|
|
28
|
+
authUrl: string;
|
|
29
|
+
/** OAuth scopes to request */
|
|
30
|
+
scopes: string;
|
|
31
|
+
/** Whether this provider uses PKCE */
|
|
32
|
+
usesPKCE: boolean;
|
|
33
|
+
/** Response type for the OAuth request */
|
|
34
|
+
responseType: string;
|
|
35
|
+
/** Optional response mode (e.g., 'fragment' for Apple) */
|
|
36
|
+
responseMode?: string;
|
|
37
|
+
/** Whether to include nonce in the URL params (vs state) */
|
|
38
|
+
nonceInParams?: boolean;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Pre-configured OAuth provider settings
|
|
42
|
+
*/
|
|
43
|
+
export declare const OAUTH_PROVIDER_CONFIGS: Record<OAuthProviders, OAuthProviderConfig>;
|
|
44
|
+
/**
|
|
45
|
+
* Parses the OAuth state parameter string into an object
|
|
46
|
+
*/
|
|
47
|
+
export declare function parseStateParam(stateParam: string | null | undefined): {
|
|
48
|
+
sessionKey?: string;
|
|
49
|
+
oauthIntent?: string;
|
|
50
|
+
provider?: string;
|
|
51
|
+
flow?: string;
|
|
52
|
+
publicKey?: string;
|
|
53
|
+
openModal?: string;
|
|
54
|
+
[key: string]: string | undefined;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Result from parsing an OAuth response (both popup and redirect flows)
|
|
58
|
+
*/
|
|
59
|
+
export interface OAuthResponseResult {
|
|
60
|
+
/** The OIDC token (for non-PKCE providers) */
|
|
61
|
+
idToken?: string | null | undefined;
|
|
62
|
+
/** The authorization code (for PKCE providers) */
|
|
63
|
+
authCode?: string | null | undefined;
|
|
64
|
+
/** Session key from state */
|
|
65
|
+
sessionKey?: string | undefined;
|
|
66
|
+
/** The provider from state */
|
|
67
|
+
provider?: string | null;
|
|
68
|
+
/** Flow type from state */
|
|
69
|
+
flow?: string | null;
|
|
70
|
+
/** Public key from state */
|
|
71
|
+
publicKey?: string | null;
|
|
72
|
+
/** Open modal flag from state */
|
|
73
|
+
openModal?: string | null;
|
|
74
|
+
/** OAuth intent from state */
|
|
75
|
+
oauthIntent?: string | null;
|
|
76
|
+
/** Nonce from state */
|
|
77
|
+
nonce?: string | null;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Unified OAuth response parser for both popup and redirect flows.
|
|
81
|
+
* Handles both:
|
|
82
|
+
* - PKCE flows (Facebook, Discord, X): code in search parameters
|
|
83
|
+
* - Non-PKCE flows (Google, Apple): id_token in hash parameters
|
|
84
|
+
* - Apple's non-standard hash format where state parameters are directly embedded
|
|
85
|
+
*
|
|
86
|
+
* @param url - The full URL to parse (from popup or redirect)
|
|
87
|
+
* @param expectedProvider - Optional provider if already known (for popup flows)
|
|
88
|
+
* @returns Parsed OAuth response data including tokens, codes, and state parameters, or null if invalid
|
|
89
|
+
*/
|
|
90
|
+
export declare function parseOAuthResponse(url: string, expectedProvider?: OAuthProviders): OAuthResponseResult | null;
|
|
91
|
+
export declare function generateChallengePair(): Promise<{
|
|
92
|
+
verifier: string;
|
|
93
|
+
codeChallenge: string;
|
|
94
|
+
}>;
|
|
95
|
+
/** Provider type for PKCE-based OAuth */
|
|
96
|
+
export type PKCEProvider = OAuthProviders.FACEBOOK | OAuthProviders.DISCORD | OAuthProviders.X;
|
|
97
|
+
/**
|
|
98
|
+
* Gets the AsyncStorage key name for a PKCE provider's verifier
|
|
99
|
+
*/
|
|
100
|
+
export declare function getPKCEVerifierKey(provider: PKCEProvider): string;
|
|
101
|
+
/**
|
|
102
|
+
* Stores the PKCE verifier in AsyncStorage
|
|
103
|
+
* @param provider - The OAuth provider
|
|
104
|
+
* @param verifier - The verifier string to store
|
|
105
|
+
*/
|
|
106
|
+
export declare function storePKCEVerifier(provider: PKCEProvider, verifier: string): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Retrieves and removes the PKCE verifier from AsyncStorage
|
|
109
|
+
* @param provider - The OAuth provider
|
|
110
|
+
* @returns The verifier string
|
|
111
|
+
* @throws Error if verifier is not found
|
|
112
|
+
*/
|
|
113
|
+
export declare function consumePKCEVerifier(provider: PKCEProvider): Promise<string>;
|
|
114
|
+
/**
|
|
115
|
+
* Checks if a PKCE verifier exists for a provider (without consuming it)
|
|
116
|
+
* @param provider - The OAuth provider
|
|
117
|
+
* @returns true if verifier exists
|
|
118
|
+
*/
|
|
119
|
+
export declare function hasPKCEVerifier(provider: PKCEProvider): Promise<boolean>;
|
|
120
|
+
/**
|
|
121
|
+
* Parameters for building an OAuth URL
|
|
122
|
+
*/
|
|
123
|
+
export interface BuildOAuthUrlParams {
|
|
124
|
+
provider: OAuthProviders;
|
|
125
|
+
clientId: string;
|
|
126
|
+
redirectUri: string;
|
|
127
|
+
publicKey: string;
|
|
128
|
+
nonce: string;
|
|
129
|
+
codeChallenge?: string | undefined;
|
|
130
|
+
additionalState?: Record<string, string> | undefined;
|
|
131
|
+
/** If true, uses direct provider URLs; if false, uses ZeroXKey OAuth proxy */
|
|
132
|
+
useOauthProxyOrigin?: boolean;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Builds the complete OAuth authorization URL for a provider
|
|
136
|
+
* For react-native, can use either:
|
|
137
|
+
* - Direct provider URLs (Discord, X)
|
|
138
|
+
* - ZeroXKey OAuth proxy (Google, Apple, Facebook)
|
|
139
|
+
*/
|
|
140
|
+
export declare function buildOAuthUrl(params: BuildOAuthUrlParams): string;
|
|
141
|
+
/**
|
|
142
|
+
* Parsed result from an InAppBrowser OAuth deep link
|
|
143
|
+
*/
|
|
144
|
+
export interface ParsedInAppBrowserResult {
|
|
145
|
+
/** The OIDC token (for non-PKCE providers) */
|
|
146
|
+
idToken?: string | null;
|
|
147
|
+
/** The authorization code (for PKCE providers) */
|
|
148
|
+
authCode?: string | null;
|
|
149
|
+
/** Session key from state */
|
|
150
|
+
sessionKey?: string | undefined;
|
|
151
|
+
/** The provider from state */
|
|
152
|
+
provider?: string | null;
|
|
153
|
+
/** Public key from state */
|
|
154
|
+
publicKey?: string | null;
|
|
155
|
+
/** Nonce from state */
|
|
156
|
+
nonce?: string | null;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Parses the deep link URL returned from InAppBrowser after OAuth redirect
|
|
160
|
+
* @param deepLinkUrl - The URL from InAppBrowser result (e.g., "myapp://?id_token=...&state=...")
|
|
161
|
+
* @returns Parsed OAuth response data
|
|
162
|
+
*/
|
|
163
|
+
export declare function parseInAppBrowserResult(deepLinkUrl: string): ParsedInAppBrowserResult;
|
|
164
|
+
/**
|
|
165
|
+
* Completion handler callbacks for OAuth flow
|
|
166
|
+
*/
|
|
167
|
+
export interface OAuthCompletionCallbacks {
|
|
168
|
+
/** Called on successful OAuth completion */
|
|
169
|
+
onOauthSuccess?: (params: {
|
|
170
|
+
oidcToken: string;
|
|
171
|
+
providerName: string;
|
|
172
|
+
publicKey: string;
|
|
173
|
+
sessionKey?: string;
|
|
174
|
+
}) => void;
|
|
175
|
+
/** Called when OAuth should redirect */
|
|
176
|
+
onOauthRedirect?: (params: {
|
|
177
|
+
idToken: string;
|
|
178
|
+
publicKey: string;
|
|
179
|
+
sessionKey?: string;
|
|
180
|
+
}) => void;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Parameters for completing an OAuth flow
|
|
184
|
+
*/
|
|
185
|
+
export interface CompleteOAuthFlowParams {
|
|
186
|
+
provider: OAuthProviders;
|
|
187
|
+
publicKey: string;
|
|
188
|
+
oidcToken: string;
|
|
189
|
+
sessionKey?: string;
|
|
190
|
+
callbacks?: OAuthCompletionCallbacks;
|
|
191
|
+
/** Function to complete the OAuth authentication */
|
|
192
|
+
completeOauth: (params: {
|
|
193
|
+
oidcToken: string;
|
|
194
|
+
publicKey: string;
|
|
195
|
+
providerName: string;
|
|
196
|
+
sessionKey?: string;
|
|
197
|
+
}) => Promise<BaseAuthResult & {
|
|
198
|
+
action: AuthAction;
|
|
199
|
+
}>;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Unified OAuth completion handler.
|
|
203
|
+
* Routes to the appropriate completion handler based on params:
|
|
204
|
+
* Priority: callbacks.onOauthSuccess > callbacks.onOauthRedirect > completeOauth
|
|
205
|
+
*
|
|
206
|
+
* This is the core completion logic used by InAppBrowser flows.
|
|
207
|
+
*/
|
|
208
|
+
export declare function completeOAuthFlow(params: CompleteOAuthFlowParams): Promise<void>;
|
|
209
|
+
/**
|
|
210
|
+
* Parameters for the unified PKCE flow handler
|
|
211
|
+
*/
|
|
212
|
+
export interface HandlePKCEFlowParams {
|
|
213
|
+
provider: PKCEProvider;
|
|
214
|
+
publicKey: string;
|
|
215
|
+
authCode: string;
|
|
216
|
+
sessionKey?: string;
|
|
217
|
+
callbacks?: OAuthCompletionCallbacks;
|
|
218
|
+
completeOauth: (params: {
|
|
219
|
+
oidcToken: string;
|
|
220
|
+
publicKey: string;
|
|
221
|
+
providerName: string;
|
|
222
|
+
sessionKey?: string;
|
|
223
|
+
}) => Promise<BaseAuthResult & {
|
|
224
|
+
action: AuthAction;
|
|
225
|
+
}>;
|
|
226
|
+
/** Function to exchange code for token (provider-specific) */
|
|
227
|
+
exchangeCodeForToken: (codeVerifier: string) => Promise<string>;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Unified PKCE flow handler for all PKCE-based OAuth providers.
|
|
231
|
+
* Handles the complete PKCE flow: verifier retrieval, token exchange, and completion routing.
|
|
232
|
+
*
|
|
233
|
+
* @param params - The PKCE flow parameters
|
|
234
|
+
* @returns A promise that resolves when the flow is complete
|
|
235
|
+
*/
|
|
236
|
+
export declare function handlePKCEFlow(params: HandlePKCEFlowParams): Promise<void>;
|
|
237
|
+
export declare function exchangeCodeForToken(clientId: string, redirectUri: string, code: string, codeVerifier: string): Promise<{
|
|
238
|
+
id_token: string;
|
|
239
|
+
}>;
|
|
240
|
+
//# sourceMappingURL=oauth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../src/utils/oauth.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,UAAU,EACV,cAAc,EACd,cAAc,EACf,MAAM,qBAAqB,CAAC;AAO7B,eAAO,MAAM,gBAAgB,yCAAyC,CAAC;AACvE,eAAO,MAAM,UAAU,qCAAqC,CAAC;AAC7D,eAAO,MAAM,eAAe,iDAAiD,CAAC;AAC9E,eAAO,MAAM,cAAc,6CAA6C,CAAC;AACzE,eAAO,MAAM,qBAAqB,yFACsD,CAAC;AACzF,eAAO,MAAM,iBAAiB,gDAAgD,CAAC;AAC/E,eAAO,MAAM,kBAAkB,wDACwB,CAAC;AAExD,eAAO,MAAM,yBAAyB,mCAAmC,CAAC;AAC1E,eAAO,MAAM,2BAA2B,qCAAqC,CAAC;AAM9E;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE;IACtC,QAAQ,EAAE,cAAc,CAAC;IACzB,IAAI,EAAE,UAAU,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;CACtD,GAAG,MAAM,CAkBT;AAMD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,8BAA8B;IAC9B,QAAQ,EAAE,cAAc,CAAC;IACzB,uCAAuC;IACvC,OAAO,EAAE,MAAM,CA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AE,CAAC,CAyB/B"}
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var sha256 = require('@noble/hashes/sha256');
|
|
4
|
+
var encoding = require('@0xkey-io/encoding');
|
|
5
|
+
var sdkTypes = require('@0xkey-io/sdk-types');
|
|
6
|
+
var AsyncStorageModule = require('@react-native-async-storage/async-storage');
|
|
7
|
+
|
|
8
|
+
// some bundlers wrap the module as { default: AsyncStorage } instead of
|
|
9
|
+
// returning AsyncStorage directly. This handles both cases
|
|
10
|
+
const AsyncStorage = AsyncStorageModule.default ?? AsyncStorageModule;
|
|
11
|
+
const DISCORD_AUTH_URL = "https://discord.com/oauth2/authorize";
|
|
12
|
+
const X_AUTH_URL = "https://x.com/i/oauth2/authorize";
|
|
13
|
+
const GOOGLE_AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth";
|
|
14
|
+
const APPLE_AUTH_URL = "https://account.apple.com/auth/authorize";
|
|
15
|
+
const FACEBOOK_AUTH_URL = "https://www.facebook.com/v23.0/dialog/oauth";
|
|
16
|
+
const FACEBOOK_GRAPH_URL = "https://graph.facebook.com/v23.0/oauth/access_token";
|
|
17
|
+
const ZEROXKEY_OAUTH_ORIGIN_URL = "https://oauth-origin.0xkey.com";
|
|
18
|
+
const ZEROXKEY_OAUTH_REDIRECT_URL = "https://oauth-redirect.0xkey.com";
|
|
19
|
+
// ============================================================================
|
|
20
|
+
// OAuth State Building
|
|
21
|
+
// ============================================================================
|
|
22
|
+
/**
|
|
23
|
+
* Builds the OAuth state parameter string
|
|
24
|
+
*/
|
|
25
|
+
function buildOAuthState(params) {
|
|
26
|
+
const { provider, flow, publicKey, nonce, additionalState } = params;
|
|
27
|
+
let state = `provider=${provider}&flow=${flow}&publicKey=${encodeURIComponent(publicKey)}`;
|
|
28
|
+
if (nonce) {
|
|
29
|
+
state += `&nonce=${nonce}`;
|
|
30
|
+
}
|
|
31
|
+
if (additionalState) {
|
|
32
|
+
const extra = Object.entries(additionalState)
|
|
33
|
+
.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
|
|
34
|
+
.join("&");
|
|
35
|
+
if (extra) {
|
|
36
|
+
state += `&${extra}`;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return state;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Pre-configured OAuth provider settings
|
|
43
|
+
*/
|
|
44
|
+
const OAUTH_PROVIDER_CONFIGS = {
|
|
45
|
+
[sdkTypes.OAuthProviders.GOOGLE]: {
|
|
46
|
+
provider: sdkTypes.OAuthProviders.GOOGLE,
|
|
47
|
+
authUrl: GOOGLE_AUTH_URL,
|
|
48
|
+
scopes: "openid email profile",
|
|
49
|
+
usesPKCE: false,
|
|
50
|
+
responseType: "id_token",
|
|
51
|
+
nonceInParams: true,
|
|
52
|
+
},
|
|
53
|
+
[sdkTypes.OAuthProviders.APPLE]: {
|
|
54
|
+
provider: sdkTypes.OAuthProviders.APPLE,
|
|
55
|
+
authUrl: APPLE_AUTH_URL,
|
|
56
|
+
scopes: "",
|
|
57
|
+
usesPKCE: false,
|
|
58
|
+
responseType: "code id_token",
|
|
59
|
+
responseMode: "fragment",
|
|
60
|
+
nonceInParams: true,
|
|
61
|
+
},
|
|
62
|
+
[sdkTypes.OAuthProviders.FACEBOOK]: {
|
|
63
|
+
provider: sdkTypes.OAuthProviders.FACEBOOK,
|
|
64
|
+
authUrl: FACEBOOK_AUTH_URL,
|
|
65
|
+
scopes: "openid",
|
|
66
|
+
usesPKCE: true,
|
|
67
|
+
responseType: "code",
|
|
68
|
+
nonceInParams: true,
|
|
69
|
+
},
|
|
70
|
+
[sdkTypes.OAuthProviders.DISCORD]: {
|
|
71
|
+
provider: sdkTypes.OAuthProviders.DISCORD,
|
|
72
|
+
authUrl: DISCORD_AUTH_URL,
|
|
73
|
+
scopes: "identify email",
|
|
74
|
+
usesPKCE: true,
|
|
75
|
+
responseType: "code",
|
|
76
|
+
nonceInParams: false,
|
|
77
|
+
},
|
|
78
|
+
[sdkTypes.OAuthProviders.X]: {
|
|
79
|
+
provider: sdkTypes.OAuthProviders.X,
|
|
80
|
+
authUrl: X_AUTH_URL,
|
|
81
|
+
scopes: "tweet.read users.read",
|
|
82
|
+
usesPKCE: true,
|
|
83
|
+
responseType: "code",
|
|
84
|
+
nonceInParams: false,
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
// ============================================================================
|
|
88
|
+
// OAuth State Parsing
|
|
89
|
+
// ============================================================================
|
|
90
|
+
/**
|
|
91
|
+
* Parses the OAuth state parameter string into an object
|
|
92
|
+
*/
|
|
93
|
+
function parseStateParam(stateParam) {
|
|
94
|
+
if (!stateParam)
|
|
95
|
+
return {};
|
|
96
|
+
const result = {};
|
|
97
|
+
const pairs = stateParam.split("&");
|
|
98
|
+
for (const pair of pairs) {
|
|
99
|
+
const [key, value] = pair.split("=");
|
|
100
|
+
if (key && value !== undefined) {
|
|
101
|
+
result[key] = decodeURIComponent(value);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
// Function to generate PKCE challenge pair for Facebook OAuth
|
|
107
|
+
async function generateChallengePair() {
|
|
108
|
+
// Generate verifier from 32 random bytes
|
|
109
|
+
const randomBytes = new Uint8Array(32);
|
|
110
|
+
// eslint-disable-next-line no-undef
|
|
111
|
+
crypto.getRandomValues(randomBytes);
|
|
112
|
+
const randomAsBinary = String.fromCharCode(...randomBytes);
|
|
113
|
+
const verifier = encoding.stringToBase64urlString(randomAsBinary);
|
|
114
|
+
// Compute SHA-256 over ASCII(verifier), then base64url encode
|
|
115
|
+
const ascii = new TextEncoder().encode(verifier);
|
|
116
|
+
const digest = sha256.sha256(ascii);
|
|
117
|
+
const digestAsBinary = String.fromCharCode(...digest);
|
|
118
|
+
const codeChallenge = encoding.stringToBase64urlString(digestAsBinary);
|
|
119
|
+
return { verifier, codeChallenge };
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Gets the AsyncStorage key name for a PKCE provider's verifier
|
|
123
|
+
*/
|
|
124
|
+
function getPKCEVerifierKey(provider) {
|
|
125
|
+
return `${provider}_verifier`;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Stores the PKCE verifier in AsyncStorage
|
|
129
|
+
* @param provider - The OAuth provider
|
|
130
|
+
* @param verifier - The verifier string to store
|
|
131
|
+
*/
|
|
132
|
+
async function storePKCEVerifier(provider, verifier) {
|
|
133
|
+
const key = getPKCEVerifierKey(provider);
|
|
134
|
+
await AsyncStorage.setItem(key, verifier);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Retrieves and removes the PKCE verifier from AsyncStorage
|
|
138
|
+
* @param provider - The OAuth provider
|
|
139
|
+
* @returns The verifier string
|
|
140
|
+
* @throws Error if verifier is not found
|
|
141
|
+
*/
|
|
142
|
+
async function consumePKCEVerifier(provider) {
|
|
143
|
+
const key = getPKCEVerifierKey(provider);
|
|
144
|
+
const verifier = await AsyncStorage.getItem(key);
|
|
145
|
+
if (!verifier) {
|
|
146
|
+
throw new Error(`Missing PKCE verifier for ${provider}. OAuth flow may have been interrupted.`);
|
|
147
|
+
}
|
|
148
|
+
await AsyncStorage.removeItem(key);
|
|
149
|
+
return verifier;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Builds the complete OAuth authorization URL for a provider
|
|
153
|
+
* For react-native, can use either:
|
|
154
|
+
* - Direct provider URLs (Discord, X)
|
|
155
|
+
* - ZeroXKey OAuth proxy (Google, Apple, Facebook)
|
|
156
|
+
*/
|
|
157
|
+
function buildOAuthUrl(params) {
|
|
158
|
+
const { provider, clientId, redirectUri, publicKey, nonce, codeChallenge, additionalState, useOauthProxyOrigin = false, } = params;
|
|
159
|
+
const config = OAUTH_PROVIDER_CONFIGS[provider];
|
|
160
|
+
// Build state parameter
|
|
161
|
+
const stateParams = {
|
|
162
|
+
provider,
|
|
163
|
+
flow: "redirect",
|
|
164
|
+
publicKey,
|
|
165
|
+
};
|
|
166
|
+
if (!config.nonceInParams && nonce) {
|
|
167
|
+
stateParams.nonce = nonce;
|
|
168
|
+
}
|
|
169
|
+
if (additionalState) {
|
|
170
|
+
stateParams.additionalState = additionalState;
|
|
171
|
+
}
|
|
172
|
+
const state = buildOAuthState(stateParams);
|
|
173
|
+
// If using ZeroXKey Oauth proxy (for Google, Apple, Facebook)
|
|
174
|
+
if (useOauthProxyOrigin) {
|
|
175
|
+
const url = new URL(ZEROXKEY_OAUTH_ORIGIN_URL);
|
|
176
|
+
url.searchParams.set("provider", provider);
|
|
177
|
+
url.searchParams.set("clientId", clientId);
|
|
178
|
+
url.searchParams.set("redirectUri", redirectUri);
|
|
179
|
+
url.searchParams.set("nonce", nonce);
|
|
180
|
+
if (codeChallenge) {
|
|
181
|
+
url.searchParams.set("codeChallenge", codeChallenge);
|
|
182
|
+
}
|
|
183
|
+
url.searchParams.set("state", state);
|
|
184
|
+
return url.toString();
|
|
185
|
+
}
|
|
186
|
+
// Direct provider URLs (for Discord, X)
|
|
187
|
+
const authUrl = new URL(config.authUrl);
|
|
188
|
+
authUrl.searchParams.set("client_id", clientId);
|
|
189
|
+
authUrl.searchParams.set("redirect_uri", redirectUri);
|
|
190
|
+
authUrl.searchParams.set("response_type", config.responseType);
|
|
191
|
+
if (config.scopes) {
|
|
192
|
+
authUrl.searchParams.set("scope", config.scopes);
|
|
193
|
+
}
|
|
194
|
+
if (config.usesPKCE && codeChallenge) {
|
|
195
|
+
authUrl.searchParams.set("code_challenge", codeChallenge);
|
|
196
|
+
authUrl.searchParams.set("code_challenge_method", "S256");
|
|
197
|
+
}
|
|
198
|
+
authUrl.searchParams.set("state", state);
|
|
199
|
+
return authUrl.toString();
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Parses the deep link URL returned from InAppBrowser after OAuth redirect
|
|
203
|
+
* @param deepLinkUrl - The URL from InAppBrowser result (e.g., "myapp://?id_token=...&state=...")
|
|
204
|
+
* @returns Parsed OAuth response data
|
|
205
|
+
*/
|
|
206
|
+
function parseInAppBrowserResult(deepLinkUrl) {
|
|
207
|
+
const qsIndex = deepLinkUrl.indexOf("?");
|
|
208
|
+
const queryString = qsIndex >= 0 ? deepLinkUrl.substring(qsIndex + 1) : "";
|
|
209
|
+
const urlParams = new URLSearchParams(queryString);
|
|
210
|
+
const idToken = urlParams.get("id_token");
|
|
211
|
+
const authCode = urlParams.get("code");
|
|
212
|
+
const stateParam = urlParams.get("state");
|
|
213
|
+
// Parse state parameter
|
|
214
|
+
const stateData = parseStateParam(stateParam);
|
|
215
|
+
return {
|
|
216
|
+
idToken: idToken ?? null,
|
|
217
|
+
authCode: authCode ?? null,
|
|
218
|
+
sessionKey: stateData.sessionKey,
|
|
219
|
+
provider: stateData.provider ?? null,
|
|
220
|
+
publicKey: stateData.publicKey ?? null,
|
|
221
|
+
nonce: stateData.nonce ?? null,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Unified OAuth completion handler.
|
|
226
|
+
* Routes to the appropriate completion handler based on params:
|
|
227
|
+
* Priority: callbacks.onOauthSuccess > callbacks.onOauthRedirect > completeOauth
|
|
228
|
+
*
|
|
229
|
+
* This is the core completion logic used by InAppBrowser flows.
|
|
230
|
+
*/
|
|
231
|
+
async function completeOAuthFlow(params) {
|
|
232
|
+
const { provider, publicKey, oidcToken, sessionKey, callbacks, completeOauth, } = params;
|
|
233
|
+
const completionParams = {
|
|
234
|
+
oidcToken,
|
|
235
|
+
providerName: provider,
|
|
236
|
+
publicKey,
|
|
237
|
+
...(sessionKey && { sessionKey }),
|
|
238
|
+
};
|
|
239
|
+
if (callbacks?.onOauthSuccess) {
|
|
240
|
+
callbacks.onOauthSuccess(completionParams);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (callbacks?.onOauthRedirect) {
|
|
244
|
+
callbacks.onOauthRedirect({
|
|
245
|
+
idToken: oidcToken,
|
|
246
|
+
publicKey,
|
|
247
|
+
...(sessionKey && { sessionKey }),
|
|
248
|
+
});
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
await completeOauth(completionParams);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Unified PKCE flow handler for all PKCE-based OAuth providers.
|
|
255
|
+
* Handles the complete PKCE flow: verifier retrieval, token exchange, and completion routing.
|
|
256
|
+
*
|
|
257
|
+
* @param params - The PKCE flow parameters
|
|
258
|
+
* @returns A promise that resolves when the flow is complete
|
|
259
|
+
*/
|
|
260
|
+
async function handlePKCEFlow(params) {
|
|
261
|
+
const { provider, publicKey, authCode, sessionKey, callbacks, completeOauth, exchangeCodeForToken, } = params;
|
|
262
|
+
if (!authCode) {
|
|
263
|
+
throw new Error(`Missing authorization code from ${provider} OAuth`);
|
|
264
|
+
}
|
|
265
|
+
// Get and consume the stored verifier
|
|
266
|
+
const verifier = await consumePKCEVerifier(provider);
|
|
267
|
+
try {
|
|
268
|
+
// Exchange code for token
|
|
269
|
+
const oidcToken = await exchangeCodeForToken(verifier);
|
|
270
|
+
if (!oidcToken) {
|
|
271
|
+
throw new Error(`Missing oidcToken from ${provider} OAuth exchange`);
|
|
272
|
+
}
|
|
273
|
+
// Complete the OAuth flow
|
|
274
|
+
const completionParams = {
|
|
275
|
+
provider,
|
|
276
|
+
publicKey,
|
|
277
|
+
oidcToken,
|
|
278
|
+
completeOauth,
|
|
279
|
+
};
|
|
280
|
+
if (sessionKey) {
|
|
281
|
+
completionParams.sessionKey = sessionKey;
|
|
282
|
+
}
|
|
283
|
+
if (callbacks) {
|
|
284
|
+
completionParams.callbacks = callbacks;
|
|
285
|
+
}
|
|
286
|
+
await completeOAuthFlow(completionParams);
|
|
287
|
+
}
|
|
288
|
+
catch (error) {
|
|
289
|
+
// Ensure cleanup even on error
|
|
290
|
+
const key = getPKCEVerifierKey(provider);
|
|
291
|
+
await AsyncStorage.removeItem(key).catch(() => {
|
|
292
|
+
/* ignore cleanup errors */
|
|
293
|
+
});
|
|
294
|
+
throw error;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
// Function to exchange Facebook authorization code for token
|
|
298
|
+
async function exchangeCodeForToken(clientId, redirectUri, code, codeVerifier) {
|
|
299
|
+
const params = new URLSearchParams({
|
|
300
|
+
client_id: clientId,
|
|
301
|
+
redirect_uri: redirectUri,
|
|
302
|
+
code_verifier: codeVerifier,
|
|
303
|
+
code: code,
|
|
304
|
+
grant_type: "authorization_code",
|
|
305
|
+
});
|
|
306
|
+
const response = await fetch(FACEBOOK_GRAPH_URL, {
|
|
307
|
+
method: "POST",
|
|
308
|
+
headers: {
|
|
309
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
310
|
+
},
|
|
311
|
+
body: params.toString(),
|
|
312
|
+
});
|
|
313
|
+
if (!response.ok) {
|
|
314
|
+
const errorData = await response.json();
|
|
315
|
+
throw new Error(`Facebook token exchange failed: ${JSON.stringify(errorData)}`);
|
|
316
|
+
}
|
|
317
|
+
return await response.json();
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
exports.APPLE_AUTH_URL = APPLE_AUTH_URL;
|
|
321
|
+
exports.DISCORD_AUTH_URL = DISCORD_AUTH_URL;
|
|
322
|
+
exports.FACEBOOK_AUTH_URL = FACEBOOK_AUTH_URL;
|
|
323
|
+
exports.FACEBOOK_GRAPH_URL = FACEBOOK_GRAPH_URL;
|
|
324
|
+
exports.GOOGLE_AUTH_URL = GOOGLE_AUTH_URL;
|
|
325
|
+
exports.OAUTH_PROVIDER_CONFIGS = OAUTH_PROVIDER_CONFIGS;
|
|
326
|
+
exports.X_AUTH_URL = X_AUTH_URL;
|
|
327
|
+
exports.ZEROXKEY_OAUTH_ORIGIN_URL = ZEROXKEY_OAUTH_ORIGIN_URL;
|
|
328
|
+
exports.ZEROXKEY_OAUTH_REDIRECT_URL = ZEROXKEY_OAUTH_REDIRECT_URL;
|
|
329
|
+
exports.buildOAuthState = buildOAuthState;
|
|
330
|
+
exports.buildOAuthUrl = buildOAuthUrl;
|
|
331
|
+
exports.completeOAuthFlow = completeOAuthFlow;
|
|
332
|
+
exports.consumePKCEVerifier = consumePKCEVerifier;
|
|
333
|
+
exports.exchangeCodeForToken = exchangeCodeForToken;
|
|
334
|
+
exports.generateChallengePair = generateChallengePair;
|
|
335
|
+
exports.getPKCEVerifierKey = getPKCEVerifierKey;
|
|
336
|
+
exports.handlePKCEFlow = handlePKCEFlow;
|
|
337
|
+
exports.parseInAppBrowserResult = parseInAppBrowserResult;
|
|
338
|
+
exports.parseStateParam = parseStateParam;
|
|
339
|
+
exports.storePKCEVerifier = storePKCEVerifier;
|
|
340
|
+
//# sourceMappingURL=oauth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.js","sources":["../../src/utils/oauth.ts"],"sourcesContent":[null],"names":["OAuthProviders","stringToBase64urlString","sha256"],"mappings":";;;;;;;AASA;AACA;AACA,MAAM,YAAY,GAAI,kBAA0B,CAAC,OAAO,IAAI,kBAAkB;AAEvE,MAAM,gBAAgB,GAAG;AACzB,MAAM,UAAU,GAAG;AACnB,MAAM,eAAe,GAAG;AACxB,MAAM,cAAc,GAAG;AAGvB,MAAM,iBAAiB,GAAG;AAC1B,MAAM,kBAAkB,GAC7B;AAEK,MAAM,yBAAyB,GAAG;AAClC,MAAM,2BAA2B,GAAG;AAE3C;AACA;AACA;AAEA;;AAEG;AACG,SAAU,eAAe,CAAC,MAM/B,EAAA;AACC,IAAA,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,GAAG,MAAM;AACpE,IAAA,IAAI,KAAK,GAAG,CAAA,SAAA,EAAY,QAAQ,CAAA,MAAA,EAAS,IAAI,CAAA,WAAA,EAAc,kBAAkB,CAAC,SAAS,CAAC,CAAA,CAAE;IAE1F,IAAI,KAAK,EAAE;AACT,QAAA,KAAK,IAAI,CAAA,OAAA,EAAU,KAAK,CAAA,CAAE;IAC5B;IAEA,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