@symbiote-native/auth-session 0.0.0-stage → 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 +21 -0
- package/README.md +157 -2
- package/build/angular/index.d.ts +2 -0
- package/build/angular/index.js +3 -0
- package/build/angular/use-auth-request.d.ts +7 -0
- package/build/angular/use-auth-request.js +11 -0
- package/build/core/auth-request-controllers.d.ts +44 -0
- package/build/core/auth-request-controllers.js +122 -0
- package/build/core/auth-request-hooks.d.ts +67 -0
- package/build/core/auth-request-hooks.js +75 -0
- package/build/core/auth-request.d.ts +29 -0
- package/build/core/auth-request.js +161 -0
- package/build/core/auth-request.types.d.ts +46 -0
- package/build/core/auth-request.types.js +23 -0
- package/build/core/auth-session.d.ts +10 -0
- package/build/core/auth-session.js +37 -0
- package/build/core/auth-session.types.d.ts +27 -0
- package/build/core/auth-session.types.js +1 -0
- package/build/core/base64.d.ts +1 -0
- package/build/core/base64.js +28 -0
- package/build/core/discovery.d.ts +57 -0
- package/build/core/discovery.js +29 -0
- package/build/core/errors.d.ts +29 -0
- package/build/core/errors.js +74 -0
- package/build/core/fetch.d.ts +15 -0
- package/build/core/fetch.js +40 -0
- package/build/core/index.d.ts +24 -0
- package/build/core/index.js +14 -0
- package/build/core/pkce.d.ts +9 -0
- package/build/core/pkce.js +41 -0
- package/build/core/prompt-string.d.ts +2 -0
- package/build/core/prompt-string.js +5 -0
- package/build/core/providers/facebook.d.ts +16 -0
- package/build/core/providers/facebook.js +43 -0
- package/build/core/providers/google-exchange-controller.d.ts +10 -0
- package/build/core/providers/google-exchange-controller.js +73 -0
- package/build/core/providers/google.d.ts +22 -0
- package/build/core/providers/google.js +52 -0
- package/build/core/providers/provider-hook-setup.d.ts +19 -0
- package/build/core/providers/provider-hook-setup.js +78 -0
- package/build/core/providers/provider-utils.d.ts +2 -0
- package/build/core/providers/provider-utils.js +8 -0
- package/build/core/providers/provider.types.d.ts +5 -0
- package/build/core/providers/provider.types.js +1 -0
- package/build/core/query-params.d.ts +5 -0
- package/build/core/query-params.js +12 -0
- package/build/core/session-result.d.ts +6 -0
- package/build/core/session-result.js +4 -0
- package/build/core/token-request.d.ts +89 -0
- package/build/core/token-request.js +328 -0
- package/build/core/token-request.types.d.ts +52 -0
- package/build/core/token-request.types.js +14 -0
- package/build/react/index.d.ts +3 -0
- package/build/react/index.js +2 -0
- package/build/react/use-auth-request.d.ts +20 -0
- package/build/react/use-auth-request.js +52 -0
- package/build/solid/index.d.ts +2 -0
- package/build/solid/index.js +2 -0
- package/build/solid/use-auth-request.d.ts +6 -0
- package/build/solid/use-auth-request.js +10 -0
- package/build/svelte/index.d.ts +2 -0
- package/build/svelte/index.js +2 -0
- package/build/svelte/use-auth-request.svelte.d.ts +28 -0
- package/build/svelte/use-auth-request.svelte.js +11 -0
- package/build/vue/index.d.ts +2 -0
- package/build/vue/index.js +2 -0
- package/build/vue/use-auth-request.d.ts +7 -0
- package/build/vue/use-auth-request.js +12 -0
- package/build-ngc/angular/index.d.ts +2 -0
- package/build-ngc/angular/index.js +4 -0
- package/build-ngc/angular/index.js.map +1 -0
- package/build-ngc/angular/use-auth-request.d.ts +7 -0
- package/build-ngc/angular/use-auth-request.js +12 -0
- package/build-ngc/angular/use-auth-request.js.map +1 -0
- package/build-ngc/core/auth-request-controllers.d.ts +44 -0
- package/build-ngc/core/auth-request-controllers.js +123 -0
- package/build-ngc/core/auth-request-controllers.js.map +1 -0
- package/build-ngc/core/auth-request-hooks.d.ts +67 -0
- package/build-ngc/core/auth-request-hooks.js +76 -0
- package/build-ngc/core/auth-request-hooks.js.map +1 -0
- package/build-ngc/core/auth-request.d.ts +29 -0
- package/build-ngc/core/auth-request.js +162 -0
- package/build-ngc/core/auth-request.js.map +1 -0
- package/build-ngc/core/auth-request.types.d.ts +46 -0
- package/build-ngc/core/auth-request.types.js +24 -0
- package/build-ngc/core/auth-request.types.js.map +1 -0
- package/build-ngc/core/auth-session.d.ts +10 -0
- package/build-ngc/core/auth-session.js +38 -0
- package/build-ngc/core/auth-session.js.map +1 -0
- package/build-ngc/core/auth-session.types.d.ts +27 -0
- package/build-ngc/core/auth-session.types.js +2 -0
- package/build-ngc/core/auth-session.types.js.map +1 -0
- package/build-ngc/core/base64.d.ts +1 -0
- package/build-ngc/core/base64.js +29 -0
- package/build-ngc/core/base64.js.map +1 -0
- package/build-ngc/core/discovery.d.ts +57 -0
- package/build-ngc/core/discovery.js +30 -0
- package/build-ngc/core/discovery.js.map +1 -0
- package/build-ngc/core/errors.d.ts +29 -0
- package/build-ngc/core/errors.js +75 -0
- package/build-ngc/core/errors.js.map +1 -0
- package/build-ngc/core/fetch.d.ts +15 -0
- package/build-ngc/core/fetch.js +41 -0
- package/build-ngc/core/fetch.js.map +1 -0
- package/build-ngc/core/index.d.ts +24 -0
- package/build-ngc/core/index.js +15 -0
- package/build-ngc/core/index.js.map +1 -0
- package/build-ngc/core/pkce.d.ts +9 -0
- package/build-ngc/core/pkce.js +42 -0
- package/build-ngc/core/pkce.js.map +1 -0
- package/build-ngc/core/prompt-string.d.ts +2 -0
- package/build-ngc/core/prompt-string.js +6 -0
- package/build-ngc/core/prompt-string.js.map +1 -0
- package/build-ngc/core/providers/facebook.d.ts +16 -0
- package/build-ngc/core/providers/facebook.js +44 -0
- package/build-ngc/core/providers/facebook.js.map +1 -0
- package/build-ngc/core/providers/google-exchange-controller.d.ts +10 -0
- package/build-ngc/core/providers/google-exchange-controller.js +74 -0
- package/build-ngc/core/providers/google-exchange-controller.js.map +1 -0
- package/build-ngc/core/providers/google.d.ts +22 -0
- package/build-ngc/core/providers/google.js +53 -0
- package/build-ngc/core/providers/google.js.map +1 -0
- package/build-ngc/core/providers/provider-hook-setup.d.ts +19 -0
- package/build-ngc/core/providers/provider-hook-setup.js +79 -0
- package/build-ngc/core/providers/provider-hook-setup.js.map +1 -0
- package/build-ngc/core/providers/provider-utils.d.ts +2 -0
- package/build-ngc/core/providers/provider-utils.js +9 -0
- package/build-ngc/core/providers/provider-utils.js.map +1 -0
- package/build-ngc/core/providers/provider.types.d.ts +5 -0
- package/build-ngc/core/providers/provider.types.js +2 -0
- package/build-ngc/core/providers/provider.types.js.map +1 -0
- package/build-ngc/core/query-params.d.ts +5 -0
- package/build-ngc/core/query-params.js +13 -0
- package/build-ngc/core/query-params.js.map +1 -0
- package/build-ngc/core/session-result.d.ts +6 -0
- package/build-ngc/core/session-result.js +5 -0
- package/build-ngc/core/session-result.js.map +1 -0
- package/build-ngc/core/token-request.d.ts +89 -0
- package/build-ngc/core/token-request.js +329 -0
- package/build-ngc/core/token-request.js.map +1 -0
- package/build-ngc/core/token-request.types.d.ts +52 -0
- package/build-ngc/core/token-request.types.js +15 -0
- package/build-ngc/core/token-request.types.js.map +1 -0
- package/package.json +151 -3
- package/src/angular/index.ts +11 -0
- package/src/angular/use-auth-request.ts +30 -0
- package/src/core/auth-request-controllers.ts +233 -0
- package/src/core/auth-request-hooks.ts +342 -0
- package/src/core/auth-request.ts +199 -0
- package/src/core/auth-request.types.ts +55 -0
- package/src/core/auth-session.ts +63 -0
- package/src/core/auth-session.types.ts +29 -0
- package/src/core/base64.ts +33 -0
- package/src/core/discovery.ts +102 -0
- package/src/core/errors.ts +102 -0
- package/src/core/fetch.ts +71 -0
- package/src/core/index.ts +97 -0
- package/src/core/pkce.ts +60 -0
- package/src/core/prompt-string.ts +8 -0
- package/src/core/providers/facebook.ts +66 -0
- package/src/core/providers/google-exchange-controller.ts +117 -0
- package/src/core/providers/google.ts +81 -0
- package/src/core/providers/provider-hook-setup.ts +117 -0
- package/src/core/providers/provider-utils.ts +18 -0
- package/src/core/providers/provider.types.ts +6 -0
- package/src/core/query-params.ts +20 -0
- package/src/core/session-result.ts +15 -0
- package/src/core/token-request.ts +452 -0
- package/src/core/token-request.types.ts +60 -0
- package/src/react/index.ts +11 -0
- package/src/react/use-auth-request.ts +151 -0
- package/src/solid/index.ts +10 -0
- package/src/solid/use-auth-request.ts +24 -0
- package/src/svelte/index.ts +10 -0
- package/src/svelte/svelte-ambient.d.ts +3 -0
- package/src/svelte/svelte-compile.test-helper.ts +7 -0
- package/src/svelte/use-auth-request.svelte.ts +22 -0
- package/src/vue/index.ts +10 -0
- package/src/vue/use-auth-request.ts +38 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
import { dismissAuthSession } from '@symbiote-native/web-browser';
|
|
3
|
+
import { AuthRequest } from './auth-request';
|
|
4
|
+
import { resolveDiscoveryAsync } from './discovery';
|
|
5
|
+
const IPV4_PATTERN = /\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/;
|
|
6
|
+
/** Cancels an active `AuthSession`, if there is one. */
|
|
7
|
+
export function dismiss() {
|
|
8
|
+
dismissAuthSession();
|
|
9
|
+
}
|
|
10
|
+
/** Unlike upstream, never reads an app manifest - pass `native` or `scheme` explicitly. */
|
|
11
|
+
export function makeRedirectUri({ native, scheme, isTripleSlashed = false, queryParams = {}, path = '', preferLocalhost = false, } = {}) {
|
|
12
|
+
if (Platform.OS !== 'web' && native) {
|
|
13
|
+
return native;
|
|
14
|
+
}
|
|
15
|
+
if (!scheme) {
|
|
16
|
+
throw new Error('makeRedirectUri() requires a `scheme` (or a `native` URI on non-web platforms) - there is no app manifest to infer one from.');
|
|
17
|
+
}
|
|
18
|
+
const cleanedPath = path.replace(/^\//, '');
|
|
19
|
+
const query = new URLSearchParams(Object.entries(queryParams).filter((entry) => entry[1] != null)).toString();
|
|
20
|
+
const slashes = isTripleSlashed ? '///' : '//';
|
|
21
|
+
const url = `${scheme}:${slashes}${cleanedPath}${query ? `?${query}` : ''}`;
|
|
22
|
+
if (preferLocalhost) {
|
|
23
|
+
const ipAddress = url.match(IPV4_PATTERN);
|
|
24
|
+
if (ipAddress?.length) {
|
|
25
|
+
const [protocol, rest] = url.split(ipAddress[0]);
|
|
26
|
+
return `${protocol}localhost${rest}`;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return url;
|
|
30
|
+
}
|
|
31
|
+
/** Builds an `AuthRequest` and loads its authorization URL before returning it. */
|
|
32
|
+
export async function loadAsync(config, issuerOrDiscovery) {
|
|
33
|
+
const request = new AuthRequest(config);
|
|
34
|
+
const discovery = await resolveDiscoveryAsync(issuerOrDiscovery);
|
|
35
|
+
await request.makeAuthUrlAsync(discovery);
|
|
36
|
+
return request;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=auth-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-session.js","sourceRoot":"","sources":["../../src/core/auth-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEpD,MAAM,YAAY,GAChB,oKAAoK,CAAC;AAEvK,wDAAwD;AACxD,MAAM,UAAU,OAAO;IACrB,kBAAkB,EAAE,CAAC;AACvB,CAAC;AAED,2FAA2F;AAC3F,MAAM,UAAU,eAAe,CAAC,EAC9B,MAAM,EACN,MAAM,EACN,eAAe,GAAG,KAAK,EACvB,WAAW,GAAG,EAAE,EAChB,IAAI,GAAG,EAAE,EACT,eAAe,GAAG,KAAK,MACW,EAAE;IACpC,IAAI,QAAQ,CAAC,EAAE,KAAK,KAAK,IAAI,MAAM,EAAE,CAAC;QACpC,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,8HAA8H,CAC/H,CAAC;IACJ,CAAC;IAED,MAA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ponse } from './token-request';
|
|
3
|
+
/** cancel/dismiss/opened/locked carry no extra data; error/success carry params + any token. */
|
|
4
|
+
export type IAuthSessionResult = {
|
|
5
|
+
type: 'cancel' | 'dismiss' | 'opened' | 'locked';
|
|
6
|
+
} | {
|
|
7
|
+
type: 'error' | 'success';
|
|
8
|
+
/** @deprecated legacy error-code query param, use `error` instead. */
|
|
9
|
+
errorCode: string | null;
|
|
10
|
+
error?: AuthError | null;
|
|
11
|
+
params: Record<string, string>;
|
|
12
|
+
authentication: TokenResponse | null;
|
|
13
|
+
url: string;
|
|
14
|
+
};
|
|
15
|
+
export type IAuthSessionRedirectUriOptions = {
|
|
16
|
+
/** Appended to `scheme`; not applied when `native` is used. */
|
|
17
|
+
path?: string;
|
|
18
|
+
/** URI protocol `<scheme>://` built into the native app. Ignored if `native` is set. */
|
|
19
|
+
scheme?: string;
|
|
20
|
+
queryParams?: Record<string, string | undefined>;
|
|
21
|
+
/** `scheme:///path` when `true`, `scheme://path` otherwise. @default false */
|
|
22
|
+
isTripleSlashed?: boolean;
|
|
23
|
+
/** Rewrites a matched IPv4 host to `localhost` (iOS simulator convenience). @default false */
|
|
24
|
+
preferLocalhost?: boolean;
|
|
25
|
+
/** Manual scheme for a production build; takes precedence over every other option. */
|
|
26
|
+
native?: string;
|
|
27
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-session.types.js","sourceRoot":"","sources":["../../src/core/auth-session.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function encodeNoWrap(input: string): string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const KEYSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
2
|
+
export function encodeNoWrap(input) {
|
|
3
|
+
let output = '';
|
|
4
|
+
let i = 0;
|
|
5
|
+
do {
|
|
6
|
+
const chr1 = input.charCodeAt(i++);
|
|
7
|
+
const chr2 = input.charCodeAt(i++);
|
|
8
|
+
const chr3 = input.charCodeAt(i++);
|
|
9
|
+
const enc1 = chr1 >> 2;
|
|
10
|
+
const enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
|
|
11
|
+
let enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
|
|
12
|
+
let enc4 = chr3 & 63;
|
|
13
|
+
if (isNaN(chr2)) {
|
|
14
|
+
enc3 = 64;
|
|
15
|
+
enc4 = 64;
|
|
16
|
+
}
|
|
17
|
+
else if (isNaN(chr3)) {
|
|
18
|
+
enc4 = 64;
|
|
19
|
+
}
|
|
20
|
+
output =
|
|
21
|
+
output +
|
|
22
|
+
KEYSET.charAt(enc1) +
|
|
23
|
+
KEYSET.charAt(enc2) +
|
|
24
|
+
KEYSET.charAt(enc3) +
|
|
25
|
+
KEYSET.charAt(enc4);
|
|
26
|
+
} while (i < input.length);
|
|
27
|
+
return output;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=base64.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64.js","sourceRoot":"","sources":["../../src/core/base64.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GACV,mEAAmE,CAAC;AAEtE,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,CAAC,GAAG,CAAC,CAAC;IAEV,GAAG,CAAC;QACF,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC;QACnC,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC;QACnC,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC;QAEnC,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC;QACvB,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC;QAC7C,IAAI,IAAI,GAAG,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC;QAC5C,IAAI,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC;QACrB,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YAChB,IAAI,GAAG,EAAE,CAAC;YACV,IAAI,GAAG,EAAE,CAAC;QACZ,CAAC;aAAM,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YACvB,IAAI,GAAG,EAAE,CAAC;QACZ,CAAC;QAED,MAAM;YACJ,MAAM;gBACN,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;gBACnB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;gBACnB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;gBACnB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE;IAE3B,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ICodeChallengeMethod } from './auth-request.types';
|
|
2
|
+
/** URL using the `https` scheme with no query or fragment, asserted by the OP as its issuer. */
|
|
3
|
+
export type IIssuer = string;
|
|
4
|
+
export type IProviderMetadataEndpoints = {
|
|
5
|
+
issuer?: IIssuer;
|
|
6
|
+
authorization_endpoint: string;
|
|
7
|
+
token_endpoint: string;
|
|
8
|
+
userinfo_endpoint?: string;
|
|
9
|
+
revocation_endpoint?: string;
|
|
10
|
+
registration_endpoint?: string;
|
|
11
|
+
end_session_endpoint?: string;
|
|
12
|
+
introspection_endpoint?: string;
|
|
13
|
+
device_authorization_endpoint?: string;
|
|
14
|
+
};
|
|
15
|
+
export type IProviderMetadata = Record<string, string | boolean | string[]> & IProviderMetadataEndpoints & {
|
|
16
|
+
jwks_uri?: string;
|
|
17
|
+
scopes_supported?: string[];
|
|
18
|
+
response_types_supported?: string[];
|
|
19
|
+
response_modes_supported?: string[];
|
|
20
|
+
grant_types_supported?: string[];
|
|
21
|
+
id_token_signing_alg_values_supported?: string[];
|
|
22
|
+
subject_types_supported?: string[];
|
|
23
|
+
token_endpoint_auth_methods_supported?: string[];
|
|
24
|
+
display_values_supported?: string[];
|
|
25
|
+
claim_types_supported?: string[];
|
|
26
|
+
claims_supported?: string[];
|
|
27
|
+
service_documentation?: string;
|
|
28
|
+
claims_locales_supported?: string[];
|
|
29
|
+
ui_locales_supported?: string[];
|
|
30
|
+
claims_parameter_supported?: boolean;
|
|
31
|
+
request_parameter_supported?: boolean;
|
|
32
|
+
request_uri_parameter_supported?: boolean;
|
|
33
|
+
require_request_uri_registration?: boolean;
|
|
34
|
+
op_policy_uri?: string;
|
|
35
|
+
op_tos_uri?: string;
|
|
36
|
+
code_challenge_methods_supported?: ICodeChallengeMethod[];
|
|
37
|
+
check_session_iframe?: string;
|
|
38
|
+
backchannel_logout_supported?: boolean;
|
|
39
|
+
backchannel_logout_session_supported?: boolean;
|
|
40
|
+
frontchannel_logout_supported?: boolean;
|
|
41
|
+
frontchannel_logout_session_supported?: boolean;
|
|
42
|
+
};
|
|
43
|
+
export type IDiscoveryDocument = {
|
|
44
|
+
authorizationEndpoint?: string;
|
|
45
|
+
tokenEndpoint?: string;
|
|
46
|
+
/** Some providers (e.g. Spotify) don't expose one despite the spec requiring it. */
|
|
47
|
+
revocationEndpoint?: string;
|
|
48
|
+
userInfoEndpoint?: string;
|
|
49
|
+
endSessionEndpoint?: string;
|
|
50
|
+
registrationEndpoint?: string;
|
|
51
|
+
discoveryDocument?: IProviderMetadata;
|
|
52
|
+
};
|
|
53
|
+
export type IIssuerOrDiscovery = IIssuer | IDiscoveryDocument;
|
|
54
|
+
/** https://tools.ietf.org/html/rfc5785 */
|
|
55
|
+
export declare function issuerWithWellKnownUrl(issuer: IIssuer): string;
|
|
56
|
+
export declare function fetchDiscoveryAsync(issuer: IIssuer): Promise<IDiscoveryDocument>;
|
|
57
|
+
export declare function resolveDiscoveryAsync(issuerOrDiscovery: IIssuerOrDiscovery): Promise<IDiscoveryDocument>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import invariant from 'invariant';
|
|
2
|
+
import { requestAsync } from './fetch';
|
|
3
|
+
/** https://tools.ietf.org/html/rfc5785 */
|
|
4
|
+
export function issuerWithWellKnownUrl(issuer) {
|
|
5
|
+
return `${issuer}/.well-known/openid-configuration`;
|
|
6
|
+
}
|
|
7
|
+
export async function fetchDiscoveryAsync(issuer) {
|
|
8
|
+
const json = await requestAsync(issuerWithWellKnownUrl(issuer), {
|
|
9
|
+
dataType: 'json',
|
|
10
|
+
method: 'GET',
|
|
11
|
+
});
|
|
12
|
+
return {
|
|
13
|
+
discoveryDocument: json,
|
|
14
|
+
authorizationEndpoint: json.authorization_endpoint,
|
|
15
|
+
tokenEndpoint: json.token_endpoint,
|
|
16
|
+
revocationEndpoint: json.revocation_endpoint,
|
|
17
|
+
userInfoEndpoint: json.userinfo_endpoint,
|
|
18
|
+
endSessionEndpoint: json.end_session_endpoint,
|
|
19
|
+
registrationEndpoint: json.registration_endpoint,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export async function resolveDiscoveryAsync(issuerOrDiscovery) {
|
|
23
|
+
invariant(issuerOrDiscovery &&
|
|
24
|
+
!['number', 'boolean'].includes(typeof issuerOrDiscovery), 'Expected a valid discovery object or issuer URL');
|
|
25
|
+
if (typeof issuerOrDiscovery === 'string') {
|
|
26
|
+
return await fetchDiscoveryAsync(issuerOrDiscovery);
|
|
27
|
+
}
|
|
28
|
+
return issuerOrDiscovery;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=discovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../src/core/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AA4DvC,0CAA0C;AAC1C,MAAM,UAAU,sBAAsB,CAAC,MAAe;IACpD,OAAO,GAAG,MAAM,mCAAmC,CAAC;AACtD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,MAAe;IAEf,MAAM,IAAI,GAAG,MAAM,YAAY,CAC7B,sBAAsB,CAAC,MAAM,CAAC,EAC9B;QACE,QAAQ,EAAE,MAAM;QAChB,MAAM,EAAE,KAAK;KACd,CACF,CAAC;IAEF,OAAO;QACL,iBAAiB,EAAE,IAAI;QACvB,qBAAqB,EAAE,IAAI,CAAC,sBAAsB;QAClD,aAAa,EAAE,IAAI,CAAC,cAAc;QAClC,kBAAkB,EAAE,IAAI,CAAC,mBAAmB;QAC5C,gBAAgB,EAAE,IAAI,CAAC,iBAAiB;QACxC,kBAAkB,EAAE,IAAI,CAAC,oBAAoB;QAC7C,oBAAoB,EAAE,IAAI,CAAC,qBAAqB;KACjD,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,iBAAqC;IAErC,SAAS,CACP,iBAAiB;QACf,CAAC,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,OAAO,iBAAiB,CAAC,EAC3D,iDAAiD,CAClD,CAAC;IACF,IAAI,OAAO,iBAAiB,KAAK,QAAQ,EAAE,CAAC;QAC1C,OAAO,MAAM,mBAAmB,CAAC,iBAAiB,CAAC,CAAC;IACtD,CAAC;IACD,OAAO,iBAAiB,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
declare class CodedError extends Error {
|
|
2
|
+
code: string;
|
|
3
|
+
constructor(code: string, message: string);
|
|
4
|
+
}
|
|
5
|
+
export type IResponseErrorConfig = Record<string, unknown> & {
|
|
6
|
+
error: string;
|
|
7
|
+
error_description?: string;
|
|
8
|
+
error_uri?: string;
|
|
9
|
+
};
|
|
10
|
+
export type IAuthErrorConfig = IResponseErrorConfig & {
|
|
11
|
+
/** Required only if `state` was used in the initial request. */
|
|
12
|
+
state?: string;
|
|
13
|
+
};
|
|
14
|
+
/** https://tools.ietf.org/html/rfc6749#section-4.1.2.1 */
|
|
15
|
+
export declare class ResponseError extends CodedError {
|
|
16
|
+
description?: string;
|
|
17
|
+
uri?: string;
|
|
18
|
+
params: Record<string, unknown>;
|
|
19
|
+
constructor(params: IResponseErrorConfig, errorCodeType: 'auth' | 'token');
|
|
20
|
+
}
|
|
21
|
+
/** https://tools.ietf.org/html/rfc6749#section-5.2 */
|
|
22
|
+
export declare class AuthError extends ResponseError {
|
|
23
|
+
state?: string;
|
|
24
|
+
constructor(response: IAuthErrorConfig);
|
|
25
|
+
}
|
|
26
|
+
export declare class TokenError extends ResponseError {
|
|
27
|
+
constructor(response: IResponseErrorConfig);
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Hand-ported from expo-modules-core's CodedError (src/errors/CodedError.ts) - this package
|
|
2
|
+
// depends on none of the rest of expo-modules-core, so a single small class is copied rather
|
|
3
|
+
// than pulling in the whole native-module runtime as a dependency.
|
|
4
|
+
class CodedError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
constructor(code, message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.code = code;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const AUTH_ERROR_MESSAGES = {
|
|
12
|
+
invalid_request: `The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed.`,
|
|
13
|
+
unauthorized_client: `The client is not authorized to request an authorization code using this method.`,
|
|
14
|
+
access_denied: `The resource owner or authorization server denied the request.`,
|
|
15
|
+
unsupported_response_type: `The authorization server does not support obtaining an authorization code using this method.`,
|
|
16
|
+
invalid_scope: 'The requested scope is invalid, unknown, or malformed.',
|
|
17
|
+
server_error: 'The authorization server encountered an unexpected condition that prevented it from fulfilling the request.',
|
|
18
|
+
temporarily_unavailable: 'The authorization server is currently unable to handle the request due to a temporary overloading or maintenance of the server.',
|
|
19
|
+
interaction_required: 'Auth server requires user interaction of some form to proceed.',
|
|
20
|
+
login_required: 'Auth server requires user authentication.',
|
|
21
|
+
account_selection_required: 'User is required to select a session at the auth server.',
|
|
22
|
+
consent_required: 'Auth server requires user consent.',
|
|
23
|
+
invalid_request_uri: 'The `request_uri` in the auth request returns an error or contains invalid data.',
|
|
24
|
+
invalid_request_object: 'The request parameter contains an invalid request object.',
|
|
25
|
+
request_not_supported: 'The OP does not support use of the `request` parameter.',
|
|
26
|
+
request_uri_not_supported: 'The OP does not support use of the `request_uri` parameter.',
|
|
27
|
+
registration_not_supported: 'The OP does not support use of the `registration` parameter.',
|
|
28
|
+
};
|
|
29
|
+
const TOKEN_ERROR_MESSAGES = {
|
|
30
|
+
invalid_request: `The request is missing a required parameter, includes an unsupported parameter value (other than grant type), repeats a parameter, includes multiple credentials, utilizes more than one mechanism for authenticating the client, or is otherwise malformed.`,
|
|
31
|
+
invalid_client: `Client authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method).`,
|
|
32
|
+
invalid_grant: `The provided authorization grant (e.g., authorization code, resource owner credentials) or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.`,
|
|
33
|
+
unauthorized_client: `The authenticated client is not authorized to use this authorization grant type.`,
|
|
34
|
+
unsupported_grant_type: `The authorization grant type is not supported by the authorization server.`,
|
|
35
|
+
};
|
|
36
|
+
/** https://tools.ietf.org/html/rfc6749#section-4.1.2.1 */
|
|
37
|
+
export class ResponseError extends CodedError {
|
|
38
|
+
description;
|
|
39
|
+
uri;
|
|
40
|
+
params;
|
|
41
|
+
constructor(params, errorCodeType) {
|
|
42
|
+
const { error, error_description, error_uri } = params;
|
|
43
|
+
const message = (errorCodeType === 'auth' ? AUTH_ERROR_MESSAGES : TOKEN_ERROR_MESSAGES)[error];
|
|
44
|
+
let errorMessage;
|
|
45
|
+
if (message) {
|
|
46
|
+
errorMessage =
|
|
47
|
+
message +
|
|
48
|
+
(error_description ? `\nMore info: ${error_description}` : '');
|
|
49
|
+
}
|
|
50
|
+
else if (error_description) {
|
|
51
|
+
errorMessage = error_description;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
errorMessage = 'An unknown error occurred';
|
|
55
|
+
}
|
|
56
|
+
super(error, errorMessage);
|
|
57
|
+
this.description = error_description ?? message;
|
|
58
|
+
this.uri = error_uri;
|
|
59
|
+
this.params = params;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** https://tools.ietf.org/html/rfc6749#section-5.2 */
|
|
63
|
+
export class AuthError extends ResponseError {
|
|
64
|
+
state;
|
|
65
|
+
constructor(response) {
|
|
66
|
+
super(response, 'auth');
|
|
67
|
+
this.state = response.state;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export class TokenError extends ResponseError {
|
|
71
|
+
constructor(response) {
|
|
72
|
+
super(response, 'token');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,6FAA6F;AAC7F,mEAAmE;AACnE,MAAM,UAAW,SAAQ,KAAK;IAC5B,IAAI,CAAS;IAEb,YAAY,IAAY,EAAE,OAAe;QACvC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAaD,MAAM,mBAAmB,GAA2B;IAClD,eAAe,EAAE,mJAAmJ;IACpK,mBAAmB,EAAE,kFAAkF;IACvG,aAAa,EAAE,gEAAgE;IAC/E,yBAAyB,EAAE,8FAA8F;IACzH,aAAa,EAAE,wDAAwD;IACvE,YAAY,EACV,6GAA6G;IAC/G,uBAAuB,EACrB,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,CAAC;QAChD,IAAI,CAAC,GAAG,GAAG,SAAS,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED,sDAAsD;AACtD,MAAM,OAAO,SAAU,SAAQ,aAAa;IAC1C,KAAK,CAAU;IAEf,YAAY,QAA0B;QACpC,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;IAC9B,CAAC;CACF;AAED,MAAM,OAAO,UAAW,SAAQ,aAAa;IAC3C,YAAY,QAA8B;QACxC,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC3B,CAAC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type IFetchHeaders = Record<string, string> & {
|
|
2
|
+
'Content-Type': string;
|
|
3
|
+
Authorization?: string;
|
|
4
|
+
Accept?: string;
|
|
5
|
+
};
|
|
6
|
+
export type IFetchRequest = {
|
|
7
|
+
headers?: IFetchHeaders;
|
|
8
|
+
body?: Record<string, string>;
|
|
9
|
+
dataType?: string;
|
|
10
|
+
method?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare function requestAsync<T>(requestUrl: string, fetchRequest: IFetchRequest & {
|
|
13
|
+
dataType: 'json';
|
|
14
|
+
}): Promise<T>;
|
|
15
|
+
export declare function requestAsync(requestUrl: string, fetchRequest: IFetchRequest): Promise<string>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export async function requestAsync(requestUrl, fetchRequest) {
|
|
2
|
+
const url = new URL(requestUrl);
|
|
3
|
+
const headers = {};
|
|
4
|
+
const request = {
|
|
5
|
+
body: undefined,
|
|
6
|
+
method: fetchRequest.method,
|
|
7
|
+
mode: 'cors',
|
|
8
|
+
headers,
|
|
9
|
+
};
|
|
10
|
+
const isJsonDataType = fetchRequest.dataType?.toLowerCase() === 'json';
|
|
11
|
+
if (fetchRequest.headers) {
|
|
12
|
+
for (const key in fetchRequest.headers) {
|
|
13
|
+
const header = fetchRequest.headers[key];
|
|
14
|
+
if (header != null) {
|
|
15
|
+
headers[key] = header;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (fetchRequest.body) {
|
|
20
|
+
if (fetchRequest.method?.toUpperCase() === 'POST') {
|
|
21
|
+
request.body = new URLSearchParams(fetchRequest.body).toString();
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
for (const [key, value] of Object.entries(fetchRequest.body)) {
|
|
25
|
+
url.searchParams.append(key, value);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (isJsonDataType && !headers.Accept && !headers.accept) {
|
|
30
|
+
headers['Accept'] = 'application/json, text/javascript; q=0.01';
|
|
31
|
+
}
|
|
32
|
+
// React Native's URL implementation adds a trailing slash that the server doesn't expect.
|
|
33
|
+
const correctedUrl = url.toString().replace(/\/$/, '');
|
|
34
|
+
const response = await fetch(correctedUrl, request);
|
|
35
|
+
const contentType = response.headers.get('content-type');
|
|
36
|
+
if (isJsonDataType || contentType?.includes('application/json')) {
|
|
37
|
+
return response.json();
|
|
38
|
+
}
|
|
39
|
+
return response.text();
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../src/core/fetch.ts"],"names":[],"mappings":"AAqBA,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,UAAkB,EAClB,YAA2B;IAE3B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC;IAEhC,MAAM,OAAO,GAA2B,EAAE,CAAC;IAC3C,MAAM,OAAO,GAAgB;QAC3B,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,YAAY,CAAC,MAAM;QAC3B,IAAI,EAAE,MAAM;QACZ,OAAO;KACR,CAAC;IAEF,MAAM,cAAc,GAAG,YAAY,CA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Ac,IAAI,WAAW,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;QAChE,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export { AuthRequest } from './auth-request';
|
|
2
|
+
export { CodeChallengeMethod, Prompt, ResponseType, type IAuthDiscoveryDocument, type IAuthRequestConfig, type IAuthRequestPromptOptions, type ICodeChallengeMethod, } from './auth-request.types';
|
|
3
|
+
export { dismiss, loadAsync, makeRedirectUri } from './auth-session';
|
|
4
|
+
export type { IAuthSessionRedirectUriOptions, IAuthSessionResult, } from './auth-session.types';
|
|
5
|
+
export type { IDiscoveryDocument, IIssuer, IIssuerOrDiscovery, IProviderMetadata, } from './discovery';
|
|
6
|
+
export { fetchDiscoveryAsync, issuerWithWellKnownUrl, resolveDiscoveryAsync, } from './discovery';
|
|
7
|
+
export { AuthError, ResponseError, TokenError } from './errors';
|
|
8
|
+
export type { IAuthErrorConfig, IResponseErrorConfig } from './errors';
|
|
9
|
+
export { requestAsync } from './fetch';
|
|
10
|
+
export type { IFetchHeaders, IFetchRequest } from './fetch';
|
|
11
|
+
export { AccessTokenRequest, RefreshTokenRequest, RevokeTokenRequest, TokenRequest, TokenResponse, exchangeCodeAsync, fetchUserInfoAsync, getCurrentTimeInSeconds, refreshAsync, revokeAsync, } from './token-request';
|
|
12
|
+
export { GrantType, TokenTypeHint, type IAccessTokenRequestConfig, type IRefreshTokenRequestConfig, type IRevokeTokenRequestConfig, type IServerTokenResponseConfig, type ITokenRequestConfig, type ITokenResponseConfig, type ITokenType, } from './token-request.types';
|
|
13
|
+
export { AUTH_CELL_CHANGE, createAutoDiscoveryController, createLoadedRequestController, createRequestResultController, } from './auth-request-controllers';
|
|
14
|
+
export type { IAuthCell, IAuthRequestClass, ILoadableRequest, IPromptMethod, IRequestResultHolder, } from './auth-request-controllers';
|
|
15
|
+
export { GETTER_ARGS, createAuthRequestHooks } from './auth-request-hooks';
|
|
16
|
+
export type { IApply, IAuthHooksKit, IAuthRequestHooks, IAuthResourceController, IBoxedKind, IGetterKind, IHkt, } from './auth-request-hooks';
|
|
17
|
+
export { createGoogleExchangeController } from './providers/google-exchange-controller';
|
|
18
|
+
export { resolveFacebookRequestSetup, resolveGoogleRequestSetup, toGoogleIdTokenConfig, } from './providers/provider-hook-setup';
|
|
19
|
+
export type { IGoogleExchangeParams, IGoogleRequestSetup, } from './providers/provider-hook-setup';
|
|
20
|
+
export type { IProviderAuthRequestConfig } from './providers/provider.types';
|
|
21
|
+
export { FacebookAuthRequest, discovery as facebookDiscovery, } from './providers/facebook';
|
|
22
|
+
export type { IFacebookAuthRequestConfig } from './providers/facebook';
|
|
23
|
+
export { GoogleAuthRequest, discovery as googleDiscovery, } from './providers/google';
|
|
24
|
+
export type { IGoogleAuthRequestConfig } from './providers/google';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { AuthRequest } from './auth-request';
|
|
2
|
+
export { CodeChallengeMethod, Prompt, ResponseType, } from './auth-request.types';
|
|
3
|
+
export { dismiss, loadAsync, makeRedirectUri } from './auth-session';
|
|
4
|
+
export { fetchDiscoveryAsync, issuerWithWellKnownUrl, resolveDiscoveryAsync, } from './discovery';
|
|
5
|
+
export { AuthError, ResponseError, TokenError } from './errors';
|
|
6
|
+
export { requestAsync } from './fetch';
|
|
7
|
+
export { AccessTokenRequest, RefreshTokenRequest, RevokeTokenRequest, TokenRequest, TokenResponse, exchangeCodeAsync, fetchUserInfoAsync, getCurrentTimeInSeconds, refreshAsync, revokeAsync, } from './token-request';
|
|
8
|
+
export { GrantType, TokenTypeHint, } from './token-request.types';
|
|
9
|
+
export { AUTH_CELL_CHANGE, createAutoDiscoveryController, createLoadedRequestController, createRequestResultController, } from './auth-request-controllers';
|
|
10
|
+
export { GETTER_ARGS, createAuthRequestHooks } from './auth-request-hooks';
|
|
11
|
+
export { createGoogleExchangeController } from './providers/google-exchange-controller';
|
|
12
|
+
export { resolveFacebookRequestSetup, resolveGoogleRequestSetup, toGoogleIdTokenConfig, } from './providers/provider-hook-setup';
|
|
13
|
+
export { FacebookAuthRequest, discovery as facebookDiscovery, } from './providers/facebook';
|
|
14
|
+
export { GoogleAuthRequest, discovery as googleDiscovery, } from './providers/google';
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EACL,mBAAmB,EACnB,MAAM,EACN,YAAY,GAKb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAWrE,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEhE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,uBAAuB,EACvB,YAAY,EACZ,WAAW,GACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,SAAS,EACT,aAAa,GAQd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,gBAAgB,EAChB,6BAA6B,EAC7B,6BAA6B,EAC7B,6BAA6B,GAC9B,MAAM,4BAA4B,CAAC;AAQpC,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAU3E,OAAO,EAAE,8BAA8B,EAAE,MAAM,wCAAwC,CAAC;AACxF,OAAO,EACL,2BAA2B,EAC3B,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,iCAAiC,CAAC;AAMzC,OAAO,EACL,mBAAmB,EACnB,SAAS,IAAI,iBAAiB,GAC/B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,iBAAiB,EACjB,SAAS,IAAI,eAAe,GAC7B,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function generateRandom(size: number): string;
|
|
2
|
+
/** Proof Key for Code Exchange (RFC 7636), Section 4.1. */
|
|
3
|
+
export declare function deriveChallengeAsync(code: string): Promise<string>;
|
|
4
|
+
export declare function buildCodeAsync(size?: number): Promise<{
|
|
5
|
+
codeChallenge: string;
|
|
6
|
+
codeVerifier: string;
|
|
7
|
+
}>;
|
|
8
|
+
/** Digests a random string with hex encoding, useful for creating `nonce`s. */
|
|
9
|
+
export declare function generateHexStringAsync(size: number): Promise<string>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import invariant from 'invariant';
|
|
2
|
+
import { CryptoDigestAlgorithm, CryptoEncoding, digestStringAsync, getRandomValues, } from '@symbiote-native/crypto';
|
|
3
|
+
const CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
4
|
+
function convertBufferToString(buffer) {
|
|
5
|
+
const chars = [];
|
|
6
|
+
for (const byte of buffer) {
|
|
7
|
+
const char = CHARSET[byte % CHARSET.length];
|
|
8
|
+
if (char != null) {
|
|
9
|
+
chars.push(char);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return chars.join('');
|
|
13
|
+
}
|
|
14
|
+
function convertToUrlSafeString(b64) {
|
|
15
|
+
return b64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
16
|
+
}
|
|
17
|
+
export function generateRandom(size) {
|
|
18
|
+
const buffer = getRandomValues(new Uint8Array(size));
|
|
19
|
+
return convertBufferToString(buffer);
|
|
20
|
+
}
|
|
21
|
+
/** Proof Key for Code Exchange (RFC 7636), Section 4.1. */
|
|
22
|
+
export async function deriveChallengeAsync(code) {
|
|
23
|
+
invariant(code.length > 42 && code.length < 129, 'Invalid code length for PKCE.');
|
|
24
|
+
const buffer = await digestStringAsync(CryptoDigestAlgorithm.SHA256, code, {
|
|
25
|
+
encoding: CryptoEncoding.BASE64,
|
|
26
|
+
});
|
|
27
|
+
return convertToUrlSafeString(buffer);
|
|
28
|
+
}
|
|
29
|
+
export async function buildCodeAsync(size = 128) {
|
|
30
|
+
const codeVerifier = generateRandom(size);
|
|
31
|
+
const codeChallenge = await deriveChallengeAsync(codeVerifier);
|
|
32
|
+
return { codeVerifier, codeChallenge };
|
|
33
|
+
}
|
|
34
|
+
/** Digests a random string with hex encoding, useful for creating `nonce`s. */
|
|
35
|
+
export async function generateHexStringAsync(size) {
|
|
36
|
+
const value = generateRandom(size);
|
|
37
|
+
const buffer = await digestStringAsync(CryptoDigestAlgorithm.SHA256, value, {
|
|
38
|
+
encoding: CryptoEncoding.HEX,
|
|
39
|
+
});
|
|
40
|
+
return convertToUrlSafeString(buffer);
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=pkce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pkce.js","sourceRoot":"","sources":["../../src/core/pkce.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,iBAAiB,EACjB,eAAe,GAChB,MAAM,yBAAyB,CAAC;AAEjC,MAAM,OAAO,GACX,gEAAgE,CAAC;AAEnE,SAAS,qBAAqB,CAAC,MAAkB;IAC/C,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;QAC1B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QAC5C,IAAI,IAAI,IAAI,IAAI,EA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C,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,qBAAqB,CAAC,MAAM,EAAE,KAAK,EAAE;QAC1E,QAAQ,EAAE,cAAc,CAAC,GAAG;KAC7B,CAAC,CAAC;IACH,OAAO,sBAAsB,CAAC,MAAM,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-string.js","sourceRoot":"","sources":["../../src/core/prompt-string.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,kBAAkB,CAChC,MAAqC;IAErC,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9B,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { IAuthRequestConfig } from '../auth-request.types';
|
|
2
|
+
import { AuthRequest } from '../auth-request';
|
|
3
|
+
import type { IDiscoveryDocument } from '../discovery';
|
|
4
|
+
import type { IProviderAuthRequestConfig } from './provider.types';
|
|
5
|
+
export declare const discovery: IDiscoveryDocument;
|
|
6
|
+
export type IFacebookAuthRequestConfig = IProviderAuthRequestConfig & {
|
|
7
|
+
webClientId?: string;
|
|
8
|
+
iosClientId?: string;
|
|
9
|
+
androidClientId?: string;
|
|
10
|
+
};
|
|
11
|
+
/** Extends `AuthRequest`, applying Facebook's minimum scopes and an auth nonce. */
|
|
12
|
+
export declare class FacebookAuthRequest extends AuthRequest {
|
|
13
|
+
nonce?: string;
|
|
14
|
+
constructor({ language, extraParams, clientSecret, ...config }: IFacebookAuthRequestConfig);
|
|
15
|
+
getAuthRequestConfigAsync(): Promise<IAuthRequestConfig>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ResponseType } from '../auth-request.types';
|
|
2
|
+
import { AuthRequest } from '../auth-request';
|
|
3
|
+
import { generateHexStringAsync } from '../pkce';
|
|
4
|
+
import { applyRequiredScopes } from './provider-utils';
|
|
5
|
+
/** Required for Firebase to work properly - a reasonable default either way. */
|
|
6
|
+
const MINIMUM_SCOPES = ['public_profile', 'email'];
|
|
7
|
+
export const discovery = {
|
|
8
|
+
authorizationEndpoint: 'https://www.facebook.com/v6.0/dialog/oauth',
|
|
9
|
+
tokenEndpoint: 'https://graph.facebook.com/v6.0/oauth/access_token',
|
|
10
|
+
};
|
|
11
|
+
/** Extends `AuthRequest`, applying Facebook's minimum scopes and an auth nonce. */
|
|
12
|
+
export class FacebookAuthRequest extends AuthRequest {
|
|
13
|
+
nonce;
|
|
14
|
+
constructor({ language, extraParams = {}, clientSecret, ...config }) {
|
|
15
|
+
const inputParams = {
|
|
16
|
+
display: 'popup',
|
|
17
|
+
...extraParams,
|
|
18
|
+
};
|
|
19
|
+
if (language) {
|
|
20
|
+
inputParams.locale = language;
|
|
21
|
+
}
|
|
22
|
+
const scopes = applyRequiredScopes(config.scopes, MINIMUM_SCOPES);
|
|
23
|
+
// Facebook rejects a client secret unless the code flow is used.
|
|
24
|
+
const inputClientSecret = config.responseType && config.responseType !== ResponseType.Code
|
|
25
|
+
? clientSecret
|
|
26
|
+
: undefined;
|
|
27
|
+
super({
|
|
28
|
+
...config,
|
|
29
|
+
responseType: config.responseType ?? ResponseType.Token,
|
|
30
|
+
clientSecret: inputClientSecret,
|
|
31
|
+
scopes,
|
|
32
|
+
extraParams: inputParams,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
async getAuthRequestConfigAsync() {
|
|
36
|
+
const { extraParams = {}, ...config } = await super.getAuthRequestConfigAsync();
|
|
37
|
+
if (!extraParams.nonce) {
|
|
38
|
+
this.nonce = this.nonce ?? (await generateHexStringAsync(16));
|
|
39
|
+
extraParams.auth_nonce = this.nonce;
|
|
40
|
+
}
|
|
41
|
+
return { ...config, extraParams };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=facebook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"facebook.js","sourceRoot":"","sources":["../../../src/core/providers/facebook.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAGvD,gFAAgF;AAChF,MAAM,cAAc,GAAG,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AAEnD,MAAM,CAAC,MAAM,SAAS,GAAuB;IAC3C,qBAAqB,EAAE,4CAA4C;IACnE,aAAa,EAAE,oDAAoD;CACpE,CAAC;AAQF,mFAAmF;AACnF,MAAM,OAAO,mBAAoB,SAAQ,WAAW;IAClD,KAAK,CAAU;IAEf,YAAY,EACV,QAAQ,EACR,WAAW,GAAG,EAAE,EAChB,YAAY,EACZ,GAAG,MAAM,EACkB;QAC3B,MAAM,WAAW,GAA2B;YAC1C,OAAO,EAAE,OAAO;YAChB,GAAG,WAAW;SACf,CAAC;QACF,IAAI,QAAQ,EAAE,CAAC;YACb,WAAW,CAAC,MAAM,GAAG,QAAQ,CAAC;QAChC,CAAC;QAED,MAAM,MAAM,GAAG,mBAAmB,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;QAClE,iEAAiE;QACjE,MAAM,iBAAiB,GACrB,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC,YAAY,KAAK,YAAY,CAAC,IAAI;YAC9D,CAAC,CAAC,YAAY;YACd,CAAC,CAAC,SAAS,CAAC;QAEhB,KAAK,CAAC;YACJ,GAAG,MAAM;YACT,YAAY,EAAE,MAAM,CAAC,YAAY,IAAI,YAAY,CAAC,KAAK;YACvD,YAAY,EAAE,iBAAiB;YAC/B,MAAM;YACN,WAAW,EAAE,WAAW;SACzB,CAAC,CAAC;IACL,CAAC;IAEQ,KAAK,CAAC,yBAAyB;QACtC,MAAM,EAAE,WAAW,GAAG,EAAE,EAAE,GAAG,MAAM,EAAE,GACnC,MAAM,KAAK,CAAC,yBAAyB,EAAE,CAAC;QAC1C,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;YACvB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,sBAAsB,CAAC,EAAE,CAAC,CAAC,CAAC;YAC9D,WAAW,CAAC,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC;QACtC,CAAC;QACD,OAAO,EAAE,GAAG,MAAM,EAAE,WAAW,EAAE,CAAC;IACpC,CAAC;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IAuthCell, ILoadableRequest } from '../auth-request-controllers';
|
|
2
|
+
import type { IAuthSessionResult } from '../auth-session.types';
|
|
3
|
+
import type { IGoogleExchangeParams } from './provider-hook-setup';
|
|
4
|
+
type ICodeSource = Pick<ILoadableRequest, 'codeVerifier'>;
|
|
5
|
+
export declare function createGoogleExchangeController(): {
|
|
6
|
+
resolve: (result: IAuthSessionResult | null, request: ICodeSource | null, exchange: IGoogleExchangeParams) => IAuthCell<IAuthSessionResult | null>;
|
|
7
|
+
flushDispose: () => void;
|
|
8
|
+
dispose: () => void;
|
|
9
|
+
};
|
|
10
|
+
export {};
|