expo-auth-session 4.0.3 → 5.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/CHANGELOG.md +15 -3
- package/README.md +2 -2
- package/build/AuthRequest.d.ts +3 -3
- package/build/AuthRequest.d.ts.map +1 -1
- package/build/AuthRequest.js +6 -13
- package/build/AuthRequest.js.map +1 -1
- package/build/AuthRequest.types.d.ts +0 -17
- package/build/AuthRequest.types.d.ts.map +1 -1
- package/build/AuthRequest.types.js.map +1 -1
- package/build/AuthRequestHooks.d.ts +1 -2
- package/build/AuthRequestHooks.d.ts.map +1 -1
- package/build/AuthRequestHooks.js +1 -2
- package/build/AuthRequestHooks.js.map +1 -1
- package/build/AuthSession.d.ts +4 -20
- package/build/AuthSession.d.ts.map +1 -1
- package/build/AuthSession.js +17 -94
- package/build/AuthSession.js.map +1 -1
- package/build/AuthSession.types.d.ts +1 -16
- package/build/AuthSession.types.d.ts.map +1 -1
- package/build/AuthSession.types.js.map +1 -1
- package/build/SessionUrlProvider.d.ts.map +1 -1
- package/build/SessionUrlProvider.js +3 -3
- package/build/SessionUrlProvider.js.map +1 -1
- package/build/providers/Facebook.d.ts.map +1 -1
- package/build/providers/Facebook.js +7 -13
- package/build/providers/Facebook.js.map +1 -1
- package/build/providers/Google.d.ts.map +1 -1
- package/build/providers/Google.js +11 -18
- package/build/providers/Google.js.map +1 -1
- package/build/providers/ProviderUtils.d.ts +0 -3
- package/build/providers/ProviderUtils.d.ts.map +1 -1
- package/build/providers/ProviderUtils.js +0 -14
- package/build/providers/ProviderUtils.js.map +1 -1
- package/package.json +6 -6
- package/src/AuthRequest.ts +7 -15
- package/src/AuthRequest.types.ts +0 -15
- package/src/AuthRequestHooks.ts +1 -2
- package/src/AuthSession.ts +20 -116
- package/src/AuthSession.types.ts +1 -16
- package/src/SessionUrlProvider.ts +3 -4
- package/src/providers/Facebook.ts +7 -14
- package/src/providers/Google.ts +11 -20
- package/src/providers/ProviderUtils.ts +0 -24
package/CHANGELOG.md
CHANGED
|
@@ -10,17 +10,29 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## 5.0.0 — 2023-06-21
|
|
14
|
+
|
|
15
|
+
### 💡 Others
|
|
16
|
+
|
|
17
|
+
- Remove all auth proxy APIs. ([#22834](https://github.com/expo/expo/pull/22834) by [@alanhughes](https://github.com/alanjhughes))
|
|
18
|
+
|
|
19
|
+
## 4.1.0 — 2023-05-08
|
|
20
|
+
|
|
21
|
+
### 💡 Others
|
|
22
|
+
|
|
23
|
+
- Added deprecation warning to `promptAsync` when the `useProxy` option is used. ([#21367](https://github.com/expo/expo/pull/21367) by [@gabrieldonadel](https://github.com/gabrieldonadel))
|
|
24
|
+
- Warn on use of Constants.manifest. ([#22247](https://github.com/expo/expo/pull/22247) by [@wschurman](https://github.com/wschurman))
|
|
25
|
+
|
|
26
|
+
## 4.0.3 - 2023-02-23
|
|
14
27
|
|
|
15
28
|
_This version does not introduce any user-facing changes._
|
|
16
29
|
|
|
17
|
-
## 4.0.2
|
|
30
|
+
## 4.0.2 - 2023-02-21
|
|
18
31
|
|
|
19
32
|
### 💡 Others
|
|
20
33
|
|
|
21
34
|
- Deprecated `useProxy` option. ([#21313](https://github.com/expo/expo/pull/21313) by [@gabrieldonadel](https://github.com/gabrieldonadel))
|
|
22
35
|
- Replaced references of `makeRedirectUriAsync` with `makeRedirectUri`. ([#21314](https://github.com/expo/expo/pull/21314) by [@gabrieldonadel](https://github.com/gabrieldonadel))
|
|
23
|
-
- Added deprecation warning to `promptAsync` when the` useProxy` option is used. ([#21367](https://github.com/expo/expo/pull/21367) by [@gabrieldonadel](https://github.com/gabrieldonadel))
|
|
24
36
|
|
|
25
37
|
## 4.0.1 — 2023-02-09
|
|
26
38
|
|
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
# Installation in managed Expo projects
|
|
11
11
|
|
|
12
|
-
For [managed](https://docs.expo.dev/
|
|
12
|
+
For [managed](https://docs.expo.dev/archive/managed-vs-bare/) Expo projects, please follow the installation instructions in the [API documentation for the latest stable release](https://docs.expo.dev/versions/latest/sdk/auth-session).
|
|
13
13
|
|
|
14
14
|
# Installation in bare React Native projects
|
|
15
15
|
|
|
@@ -18,7 +18,7 @@ For bare React Native projects, you must ensure that you have [installed and con
|
|
|
18
18
|
### Add the package to your npm dependencies
|
|
19
19
|
|
|
20
20
|
```
|
|
21
|
-
expo install expo-auth-session expo-
|
|
21
|
+
npx expo install expo-auth-session expo-crypto
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
### Configuration
|
package/build/AuthRequest.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { AuthSessionResult } from './AuthSession.types';
|
|
|
3
3
|
import { DiscoveryDocument } from './Discovery';
|
|
4
4
|
type AuthDiscoveryDocument = Pick<DiscoveryDocument, 'authorizationEndpoint'>;
|
|
5
5
|
/**
|
|
6
|
-
* Used to manage an authorization request according to the OAuth spec: [Section 4.1.1]
|
|
6
|
+
* Used to manage an authorization request according to the OAuth spec: [Section 4.1.1](https://tools.ietf.org/html/rfc6749#section-4.1.1).
|
|
7
7
|
* You can use this class directly for more info around the authorization.
|
|
8
8
|
*
|
|
9
9
|
* **Common use-cases:**
|
|
@@ -18,7 +18,7 @@ type AuthDiscoveryDocument = Pick<DiscoveryDocument, 'authorizationEndpoint'>;
|
|
|
18
18
|
* const request = new AuthRequest({ ... });
|
|
19
19
|
*
|
|
20
20
|
* // Prompt for an auth code
|
|
21
|
-
* const result = await request.promptAsync(discovery
|
|
21
|
+
* const result = await request.promptAsync(discovery);
|
|
22
22
|
*
|
|
23
23
|
* // Get the URL to invoke
|
|
24
24
|
* const url = await request.makeAuthUrlAsync(discovery);
|
|
@@ -55,7 +55,7 @@ export declare class AuthRequest implements Omit<AuthRequestConfig, 'state'> {
|
|
|
55
55
|
* @param discovery
|
|
56
56
|
* @param promptOptions
|
|
57
57
|
*/
|
|
58
|
-
promptAsync(discovery: AuthDiscoveryDocument, { url,
|
|
58
|
+
promptAsync(discovery: AuthDiscoveryDocument, { url, ...options }?: AuthRequestPromptOptions): Promise<AuthSessionResult>;
|
|
59
59
|
parseReturnUrl(url: string): AuthSessionResult;
|
|
60
60
|
/**
|
|
61
61
|
* Create the URL for authorization.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthRequest.d.ts","sourceRoot":"","sources":["../src/AuthRequest.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,mBAAmB,EACnB,YAAY,EACZ,MAAM,EACP,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"AuthRequest.d.ts","sourceRoot":"","sources":["../src/AuthRequest.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,mBAAmB,EACnB,YAAY,EACZ,MAAM,EACP,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAQhD,KAAK,qBAAqB,GAAG,IAAI,CAAC,iBAAiB,EAAE,uBAAuB,CAAC,CAAC;AAG9E;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,WAAY,YAAW,IAAI,CAAC,iBAAiB,EAAE,OAAO,CAAC;IAClE;;OAEG;IACI,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IAE9B,QAAQ,CAAC,YAAY,EAAE,YAAY,GAAG,MAAM,CAAC;IAC7C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7C,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,mBAAmB,EAAE,mBAAmB,CAAC;IAClD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;gBAEb,OAAO,EAAE,iBAAiB;IA2CtC;;OAEG;IACG,yBAAyB,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAoB7D;;;;;OAKG;IACG,WAAW,CACf,SAAS,EAAE,qBAAqB,EAChC,EAAE,GAAG,EAAE,GAAG,OAAO,EAAE,GAAE,wBAA6B,GACjD,OAAO,CAAC,iBAAiB,CAAC;IAuD7B,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB;IAgC9C;;;;OAIG;IACG,gBAAgB,CAAC,SAAS,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC;YA8C3D,sBAAsB;CAWrC"}
|
package/build/AuthRequest.js
CHANGED
|
@@ -5,12 +5,11 @@ import { CodeChallengeMethod, ResponseType, } from './AuthRequest.types';
|
|
|
5
5
|
import { AuthError } from './Errors';
|
|
6
6
|
import * as PKCE from './PKCE';
|
|
7
7
|
import * as QueryParams from './QueryParams';
|
|
8
|
-
import sessionUrlProvider from './SessionUrlProvider';
|
|
9
8
|
import { TokenResponse } from './TokenRequest';
|
|
10
9
|
let _authLock = false;
|
|
11
10
|
// @needsAudit @docsMissing
|
|
12
11
|
/**
|
|
13
|
-
* Used to manage an authorization request according to the OAuth spec: [Section 4.1.1]
|
|
12
|
+
* Used to manage an authorization request according to the OAuth spec: [Section 4.1.1](https://tools.ietf.org/html/rfc6749#section-4.1.1).
|
|
14
13
|
* You can use this class directly for more info around the authorization.
|
|
15
14
|
*
|
|
16
15
|
* **Common use-cases:**
|
|
@@ -25,7 +24,7 @@ let _authLock = false;
|
|
|
25
24
|
* const request = new AuthRequest({ ... });
|
|
26
25
|
*
|
|
27
26
|
* // Prompt for an auth code
|
|
28
|
-
* const result = await request.promptAsync(discovery
|
|
27
|
+
* const result = await request.promptAsync(discovery);
|
|
29
28
|
*
|
|
30
29
|
* // Get the URL to invoke
|
|
31
30
|
* const url = await request.makeAuthUrlAsync(discovery);
|
|
@@ -108,7 +107,7 @@ export class AuthRequest {
|
|
|
108
107
|
* @param discovery
|
|
109
108
|
* @param promptOptions
|
|
110
109
|
*/
|
|
111
|
-
async promptAsync(discovery, { url,
|
|
110
|
+
async promptAsync(discovery, { url, ...options } = {}) {
|
|
112
111
|
if (!url) {
|
|
113
112
|
if (!this.url) {
|
|
114
113
|
// Generate a new url
|
|
@@ -122,13 +121,8 @@ export class AuthRequest {
|
|
|
122
121
|
}
|
|
123
122
|
// Prevent accidentally starting to an empty url
|
|
124
123
|
invariant(url, 'No authUrl provided to AuthSession.startAsync. An authUrl is required -- it points to the page where the user will be able to sign in.');
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (options.useProxy) {
|
|
128
|
-
console.warn('The useProxy option is deprecated and will be removed in a future release, for more information check https://expo.fyi/auth-proxy-migration.');
|
|
129
|
-
returnUrl = sessionUrlProvider.getDefaultReturnUrl(proxyOptions?.path, proxyOptions);
|
|
130
|
-
startUrl = sessionUrlProvider.getStartUrl(url, returnUrl, options.projectNameForProxy);
|
|
131
|
-
}
|
|
124
|
+
const startUrl = url;
|
|
125
|
+
const returnUrl = this.redirectUri;
|
|
132
126
|
// Prevent multiple sessions from running at the same time, WebBrowser doesn't
|
|
133
127
|
// support it this makes the behavior predictable.
|
|
134
128
|
if (_authLock) {
|
|
@@ -141,8 +135,7 @@ export class AuthRequest {
|
|
|
141
135
|
_authLock = true;
|
|
142
136
|
let result;
|
|
143
137
|
try {
|
|
144
|
-
|
|
145
|
-
result = await WebBrowser.openAuthSessionAsync(startUrl, returnUrl, openOptions);
|
|
138
|
+
result = await WebBrowser.openAuthSessionAsync(startUrl, returnUrl, options);
|
|
146
139
|
}
|
|
147
140
|
finally {
|
|
148
141
|
_authLock = false;
|
package/build/AuthRequest.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthRequest.js","sourceRoot":"","sources":["../src/AuthRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,EAGL,mBAAmB,EACnB,YAAY,GAEb,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,WAAW,MAAM,eAAe,CAAC;AAC7C,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,IAAI,SAAS,GAAY,KAAK,CAAC;AAI/B,2BAA2B;AAC3B;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,OAAO,WAAW;IACtB;;OAEG;IACI,KAAK,CAAS;IACd,GAAG,GAAkB,IAAI,CAAC;IAC1B,YAAY,CAAU;IACtB,aAAa,CAAU;IAErB,YAAY,CAAwB;IACpC,QAAQ,CAAS;IACjB,WAAW,CAAyB;IACpC,OAAO,CAAW;IAClB,mBAAmB,CAAsB;IACzC,WAAW,CAAS;IACpB,MAAM,CAAY;IAClB,YAAY,CAAU;IACtB,MAAM,CAAU;IAEzB,YAAY,OAA0B;QACpC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,IA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-browser';\nimport invariant from 'invariant';\nimport { Platform } from 'react-native';\n\nimport {\n AuthRequestConfig,\n AuthRequestPromptOptions,\n CodeChallengeMethod,\n ResponseType,\n Prompt,\n} from './AuthRequest.types';\nimport { AuthSessionResult } from './AuthSession.types';\nimport { DiscoveryDocument } from './Discovery';\nimport { AuthError } from './Errors';\nimport * as PKCE from './PKCE';\nimport * as QueryParams from './QueryParams';\nimport sessionUrlProvider from './SessionUrlProvider';\nimport { TokenResponse } from './TokenRequest';\n\nlet _authLock: boolean = false;\n\ntype AuthDiscoveryDocument = Pick<DiscoveryDocument, 'authorizationEndpoint'>;\n\n// @needsAudit @docsMissing\n/**\n * Used to manage an authorization request according to the OAuth spec: [Section 4.1.1][https://tools.ietf.org/html/rfc6749#section-4.1.1].\n * You can use this class directly for more info around the authorization.\n *\n * **Common use-cases:**\n *\n * - Parse a URL returned from the authorization server with `parseReturnUrlAsync()`.\n * - Get the built authorization URL with `makeAuthUrlAsync()`.\n * - Get a loaded JSON representation of the auth request with crypto state loaded with `getAuthRequestConfigAsync()`.\n *\n * @example\n * ```ts\n * // Create a request.\n * const request = new AuthRequest({ ... });\n *\n * // Prompt for an auth code\n * const result = await request.promptAsync(discovery, { useProxy: true });\n *\n * // Get the URL to invoke\n * const url = await request.makeAuthUrlAsync(discovery);\n *\n * // Get the URL to invoke\n * const parsed = await request.parseReturnUrlAsync(\"<URL From Server>\");\n * ```\n */\nexport class AuthRequest implements Omit<AuthRequestConfig, 'state'> {\n /**\n * Used for protection against [Cross-Site Request Forgery](https://tools.ietf.org/html/rfc6749#section-10.12).\n */\n public state: string;\n public url: string | null = null;\n public codeVerifier?: string;\n public codeChallenge?: string;\n\n readonly responseType: ResponseType | string;\n readonly clientId: string;\n readonly extraParams: Record<string, string>;\n readonly usePKCE?: boolean;\n readonly codeChallengeMethod: CodeChallengeMethod;\n readonly redirectUri: string;\n readonly scopes?: string[];\n readonly clientSecret?: string;\n readonly prompt?: Prompt;\n\n constructor(request: AuthRequestConfig) {\n this.responseType = request.responseType ?? ResponseType.Code;\n this.clientId = request.clientId;\n this.redirectUri = request.redirectUri;\n this.scopes = request.scopes;\n this.clientSecret = request.clientSecret;\n this.prompt = request.prompt;\n this.state = request.state ?? PKCE.generateRandom(10);\n this.extraParams = request.extraParams ?? {};\n this.codeChallengeMethod = request.codeChallengeMethod ?? CodeChallengeMethod.S256;\n // PKCE defaults to true\n this.usePKCE = request.usePKCE ?? true;\n\n // Some warnings in development about potential confusing application code\n if (__DEV__) {\n if (this.prompt && this.extraParams.prompt) {\n console.warn(`\\`AuthRequest\\` \\`extraParams.prompt\\` will be overwritten by \\`prompt\\`.`);\n }\n if (this.clientSecret && this.extraParams.client_secret) {\n console.warn(\n `\\`AuthRequest\\` \\`extraParams.client_secret\\` will be overwritten by \\`clientSecret\\`.`\n );\n }\n if (this.codeChallengeMethod && this.extraParams.code_challenge_method) {\n console.warn(\n `\\`AuthRequest\\` \\`extraParams.code_challenge_method\\` will be overwritten by \\`codeChallengeMethod\\`.`\n );\n }\n }\n\n invariant(\n this.codeChallengeMethod !== CodeChallengeMethod.Plain,\n `\\`AuthRequest\\` does not support \\`CodeChallengeMethod.Plain\\` as it's not secure.`\n );\n invariant(\n this.redirectUri,\n `\\`AuthRequest\\` requires a valid \\`redirectUri\\`. Ex: ${Platform.select({\n web: 'https://yourwebsite.com/',\n default: 'com.your.app:/oauthredirect',\n })}`\n );\n }\n\n /**\n * Load and return a valid auth request based on the input config.\n */\n async getAuthRequestConfigAsync(): Promise<AuthRequestConfig> {\n if (this.usePKCE) {\n await this.ensureCodeIsSetupAsync();\n }\n\n return {\n responseType: this.responseType,\n clientId: this.clientId,\n redirectUri: this.redirectUri,\n scopes: this.scopes,\n clientSecret: this.clientSecret,\n codeChallenge: this.codeChallenge,\n codeChallengeMethod: this.codeChallengeMethod,\n prompt: this.prompt,\n state: this.state,\n extraParams: this.extraParams,\n usePKCE: this.usePKCE,\n };\n }\n\n /**\n * Prompt a user to authorize for a code.\n *\n * @param discovery\n * @param promptOptions\n */\n async promptAsync(\n discovery: AuthDiscoveryDocument,\n { url, proxyOptions, ...options }: AuthRequestPromptOptions = {}\n ): Promise<AuthSessionResult> {\n if (!url) {\n if (!this.url) {\n // Generate a new url\n return this.promptAsync(discovery, {\n ...options,\n url: await this.makeAuthUrlAsync(discovery),\n });\n }\n // Reuse the preloaded url\n url = this.url;\n }\n\n // Prevent accidentally starting to an empty url\n invariant(\n url,\n 'No authUrl provided to AuthSession.startAsync. An authUrl is required -- it points to the page where the user will be able to sign in.'\n );\n\n let startUrl: string = url!;\n let returnUrl: string = this.redirectUri;\n if (options.useProxy) {\n console.warn(\n 'The useProxy option is deprecated and will be removed in a future release, for more information check https://expo.fyi/auth-proxy-migration.'\n );\n returnUrl = sessionUrlProvider.getDefaultReturnUrl(proxyOptions?.path, proxyOptions);\n startUrl = sessionUrlProvider.getStartUrl(url, returnUrl, options.projectNameForProxy);\n }\n // Prevent multiple sessions from running at the same time, WebBrowser doesn't\n // support it this makes the behavior predictable.\n if (_authLock) {\n if (__DEV__) {\n console.warn(\n 'Attempted to call AuthSession.startAsync multiple times while already active. Only one AuthSession can be active at any given time.'\n );\n }\n\n return { type: 'locked' };\n }\n\n // About to start session, set lock\n _authLock = true;\n\n let result: WebBrowser.WebBrowserAuthSessionResult;\n try {\n const { useProxy, ...openOptions } = options;\n result = await WebBrowser.openAuthSessionAsync(startUrl, returnUrl, openOptions);\n } finally {\n _authLock = false;\n }\n\n if (result.type === 'opened') {\n // This should never happen\n throw new Error('An unexpected error occurred');\n }\n if (result.type !== 'success') {\n return { type: result.type };\n }\n\n return this.parseReturnUrl(result.url);\n }\n\n parseReturnUrl(url: string): AuthSessionResult {\n const { params, errorCode } = QueryParams.getQueryParams(url);\n const { state, error = errorCode } = params;\n\n let parsedError: AuthError | null = null;\n let authentication: TokenResponse | null = null;\n if (state !== this.state) {\n // This is a non-standard error\n parsedError = new AuthError({\n error: 'state_mismatch',\n error_description:\n 'Cross-Site request verification failed. Cached state and returned state do not match.',\n });\n } else if (error) {\n parsedError = new AuthError({ error, ...params });\n }\n if (params.access_token) {\n authentication = TokenResponse.fromQueryParams(params);\n }\n\n return {\n type: parsedError ? 'error' : 'success',\n error: parsedError,\n url,\n params,\n authentication,\n\n // Return errorCode for legacy\n errorCode,\n };\n }\n\n /**\n * Create the URL for authorization.\n *\n * @param discovery\n */\n async makeAuthUrlAsync(discovery: AuthDiscoveryDocument): Promise<string> {\n const request = await this.getAuthRequestConfigAsync();\n if (!request.state) throw new Error('Cannot make request URL without a valid `state` loaded');\n\n // Create a query string\n const params: Record<string, string> = {};\n\n if (request.codeChallenge) {\n params.code_challenge = request.codeChallenge;\n }\n\n // copy over extra params\n for (const extra in request.extraParams) {\n if (extra in request.extraParams) {\n params[extra] = request.extraParams[extra];\n }\n }\n\n if (request.usePKCE && request.codeChallengeMethod) {\n params.code_challenge_method = request.codeChallengeMethod;\n }\n\n if (request.clientSecret) {\n params.client_secret = request.clientSecret;\n }\n\n if (request.prompt) {\n params.prompt = request.prompt;\n }\n\n // These overwrite any extra params\n params.redirect_uri = request.redirectUri;\n params.client_id = request.clientId;\n params.response_type = request.responseType!;\n params.state = request.state;\n\n if (request.scopes?.length) {\n params.scope = request.scopes.join(' ');\n }\n\n const query = QueryParams.buildQueryString(params);\n // Store the URL for later\n this.url = `${discovery.authorizationEndpoint}?${query}`;\n return this.url;\n }\n\n private async ensureCodeIsSetupAsync(): Promise<void> {\n if (this.codeVerifier) {\n return;\n }\n\n // This method needs to be resolved like all other native methods.\n const { codeVerifier, codeChallenge } = await PKCE.buildCodeAsync();\n\n this.codeVerifier = codeVerifier;\n this.codeChallenge = codeChallenge;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AuthRequest.js","sourceRoot":"","sources":["../src/AuthRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,QAAQ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AK,EAAE,CAAC;QACzD,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAEO,KAAK,CAAC,sBAAsB;QAClC,IAAI,IAAI,CAAC,YAAY,EAAE;YACrB,OAAO;SACR;QAED,kEAAkE;QAClE,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,GAAG,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;QAEpE,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;CACF","sourcesContent":["import * as WebBrowser from 'expo-web-browser';\nimport invariant from 'invariant';\nimport { Platform } from 'react-native';\n\nimport {\n AuthRequestConfig,\n AuthRequestPromptOptions,\n CodeChallengeMethod,\n ResponseType,\n Prompt,\n} from './AuthRequest.types';\nimport { AuthSessionResult } from './AuthSession.types';\nimport { DiscoveryDocument } from './Discovery';\nimport { AuthError } from './Errors';\nimport * as PKCE from './PKCE';\nimport * as QueryParams from './QueryParams';\nimport { TokenResponse } from './TokenRequest';\n\nlet _authLock: boolean = false;\n\ntype AuthDiscoveryDocument = Pick<DiscoveryDocument, 'authorizationEndpoint'>;\n\n// @needsAudit @docsMissing\n/**\n * Used to manage an authorization request according to the OAuth spec: [Section 4.1.1](https://tools.ietf.org/html/rfc6749#section-4.1.1).\n * You can use this class directly for more info around the authorization.\n *\n * **Common use-cases:**\n *\n * - Parse a URL returned from the authorization server with `parseReturnUrlAsync()`.\n * - Get the built authorization URL with `makeAuthUrlAsync()`.\n * - Get a loaded JSON representation of the auth request with crypto state loaded with `getAuthRequestConfigAsync()`.\n *\n * @example\n * ```ts\n * // Create a request.\n * const request = new AuthRequest({ ... });\n *\n * // Prompt for an auth code\n * const result = await request.promptAsync(discovery);\n *\n * // Get the URL to invoke\n * const url = await request.makeAuthUrlAsync(discovery);\n *\n * // Get the URL to invoke\n * const parsed = await request.parseReturnUrlAsync(\"<URL From Server>\");\n * ```\n */\nexport class AuthRequest implements Omit<AuthRequestConfig, 'state'> {\n /**\n * Used for protection against [Cross-Site Request Forgery](https://tools.ietf.org/html/rfc6749#section-10.12).\n */\n public state: string;\n public url: string | null = null;\n public codeVerifier?: string;\n public codeChallenge?: string;\n\n readonly responseType: ResponseType | string;\n readonly clientId: string;\n readonly extraParams: Record<string, string>;\n readonly usePKCE?: boolean;\n readonly codeChallengeMethod: CodeChallengeMethod;\n readonly redirectUri: string;\n readonly scopes?: string[];\n readonly clientSecret?: string;\n readonly prompt?: Prompt;\n\n constructor(request: AuthRequestConfig) {\n this.responseType = request.responseType ?? ResponseType.Code;\n this.clientId = request.clientId;\n this.redirectUri = request.redirectUri;\n this.scopes = request.scopes;\n this.clientSecret = request.clientSecret;\n this.prompt = request.prompt;\n this.state = request.state ?? PKCE.generateRandom(10);\n this.extraParams = request.extraParams ?? {};\n this.codeChallengeMethod = request.codeChallengeMethod ?? CodeChallengeMethod.S256;\n // PKCE defaults to true\n this.usePKCE = request.usePKCE ?? true;\n\n // Some warnings in development about potential confusing application code\n if (__DEV__) {\n if (this.prompt && this.extraParams.prompt) {\n console.warn(`\\`AuthRequest\\` \\`extraParams.prompt\\` will be overwritten by \\`prompt\\`.`);\n }\n if (this.clientSecret && this.extraParams.client_secret) {\n console.warn(\n `\\`AuthRequest\\` \\`extraParams.client_secret\\` will be overwritten by \\`clientSecret\\`.`\n );\n }\n if (this.codeChallengeMethod && this.extraParams.code_challenge_method) {\n console.warn(\n `\\`AuthRequest\\` \\`extraParams.code_challenge_method\\` will be overwritten by \\`codeChallengeMethod\\`.`\n );\n }\n }\n\n invariant(\n this.codeChallengeMethod !== CodeChallengeMethod.Plain,\n `\\`AuthRequest\\` does not support \\`CodeChallengeMethod.Plain\\` as it's not secure.`\n );\n invariant(\n this.redirectUri,\n `\\`AuthRequest\\` requires a valid \\`redirectUri\\`. Ex: ${Platform.select({\n web: 'https://yourwebsite.com/',\n default: 'com.your.app:/oauthredirect',\n })}`\n );\n }\n\n /**\n * Load and return a valid auth request based on the input config.\n */\n async getAuthRequestConfigAsync(): Promise<AuthRequestConfig> {\n if (this.usePKCE) {\n await this.ensureCodeIsSetupAsync();\n }\n\n return {\n responseType: this.responseType,\n clientId: this.clientId,\n redirectUri: this.redirectUri,\n scopes: this.scopes,\n clientSecret: this.clientSecret,\n codeChallenge: this.codeChallenge,\n codeChallengeMethod: this.codeChallengeMethod,\n prompt: this.prompt,\n state: this.state,\n extraParams: this.extraParams,\n usePKCE: this.usePKCE,\n };\n }\n\n /**\n * Prompt a user to authorize for a code.\n *\n * @param discovery\n * @param promptOptions\n */\n async promptAsync(\n discovery: AuthDiscoveryDocument,\n { url, ...options }: AuthRequestPromptOptions = {}\n ): Promise<AuthSessionResult> {\n if (!url) {\n if (!this.url) {\n // Generate a new url\n return this.promptAsync(discovery, {\n ...options,\n url: await this.makeAuthUrlAsync(discovery),\n });\n }\n // Reuse the preloaded url\n url = this.url;\n }\n\n // Prevent accidentally starting to an empty url\n invariant(\n url,\n 'No authUrl provided to AuthSession.startAsync. An authUrl is required -- it points to the page where the user will be able to sign in.'\n );\n\n const startUrl: string = url!;\n const returnUrl: string = this.redirectUri;\n\n // Prevent multiple sessions from running at the same time, WebBrowser doesn't\n // support it this makes the behavior predictable.\n if (_authLock) {\n if (__DEV__) {\n console.warn(\n 'Attempted to call AuthSession.startAsync multiple times while already active. Only one AuthSession can be active at any given time.'\n );\n }\n\n return { type: 'locked' };\n }\n\n // About to start session, set lock\n _authLock = true;\n\n let result: WebBrowser.WebBrowserAuthSessionResult;\n try {\n result = await WebBrowser.openAuthSessionAsync(startUrl, returnUrl, options);\n } finally {\n _authLock = false;\n }\n\n if (result.type === 'opened') {\n // This should never happen\n throw new Error('An unexpected error occurred');\n }\n if (result.type !== 'success') {\n return { type: result.type };\n }\n\n return this.parseReturnUrl(result.url);\n }\n\n parseReturnUrl(url: string): AuthSessionResult {\n const { params, errorCode } = QueryParams.getQueryParams(url);\n const { state, error = errorCode } = params;\n\n let parsedError: AuthError | null = null;\n let authentication: TokenResponse | null = null;\n if (state !== this.state) {\n // This is a non-standard error\n parsedError = new AuthError({\n error: 'state_mismatch',\n error_description:\n 'Cross-Site request verification failed. Cached state and returned state do not match.',\n });\n } else if (error) {\n parsedError = new AuthError({ error, ...params });\n }\n if (params.access_token) {\n authentication = TokenResponse.fromQueryParams(params);\n }\n\n return {\n type: parsedError ? 'error' : 'success',\n error: parsedError,\n url,\n params,\n authentication,\n\n // Return errorCode for legacy\n errorCode,\n };\n }\n\n /**\n * Create the URL for authorization.\n *\n * @param discovery\n */\n async makeAuthUrlAsync(discovery: AuthDiscoveryDocument): Promise<string> {\n const request = await this.getAuthRequestConfigAsync();\n if (!request.state) throw new Error('Cannot make request URL without a valid `state` loaded');\n\n // Create a query string\n const params: Record<string, string> = {};\n\n if (request.codeChallenge) {\n params.code_challenge = request.codeChallenge;\n }\n\n // copy over extra params\n for (const extra in request.extraParams) {\n if (extra in request.extraParams) {\n params[extra] = request.extraParams[extra];\n }\n }\n\n if (request.usePKCE && request.codeChallengeMethod) {\n params.code_challenge_method = request.codeChallengeMethod;\n }\n\n if (request.clientSecret) {\n params.client_secret = request.clientSecret;\n }\n\n if (request.prompt) {\n params.prompt = request.prompt;\n }\n\n // These overwrite any extra params\n params.redirect_uri = request.redirectUri;\n params.client_id = request.clientId;\n params.response_type = request.responseType!;\n params.state = request.state;\n\n if (request.scopes?.length) {\n params.scope = request.scopes.join(' ');\n }\n\n const query = QueryParams.buildQueryString(params);\n // Store the URL for later\n this.url = `${discovery.authorizationEndpoint}?${query}`;\n return this.url;\n }\n\n private async ensureCodeIsSetupAsync(): Promise<void> {\n if (this.codeVerifier) {\n return;\n }\n\n // This method needs to be resolved like all other native methods.\n const { codeVerifier, codeChallenge } = await PKCE.buildCodeAsync();\n\n this.codeVerifier = codeVerifier;\n this.codeChallenge = codeChallenge;\n }\n}\n"]}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { CreateURLOptions } from 'expo-linking';
|
|
2
1
|
import { WebBrowserOpenOptions, WebBrowserWindowFeatures } from 'expo-web-browser';
|
|
3
2
|
export declare enum CodeChallengeMethod {
|
|
4
3
|
/**
|
|
@@ -71,22 +70,6 @@ export type AuthRequestPromptOptions = Omit<WebBrowserOpenOptions, 'windowFeatur
|
|
|
71
70
|
* URL to open when prompting the user. This usually should be defined internally and left `undefined` in most cases.
|
|
72
71
|
*/
|
|
73
72
|
url?: string;
|
|
74
|
-
/**
|
|
75
|
-
* Should the authentication request use the Expo proxy service `auth.expo.io`.
|
|
76
|
-
* @default false
|
|
77
|
-
* @deprecated This option will be removed in a future release, for more information check [the migration guide](https://expo.fyi/auth-proxy-migration).
|
|
78
|
-
*/
|
|
79
|
-
useProxy?: boolean;
|
|
80
|
-
/**
|
|
81
|
-
* Project name to use for the `auth.expo.io` proxy when `useProxy` is `true`.
|
|
82
|
-
*/
|
|
83
|
-
projectNameForProxy?: string;
|
|
84
|
-
/**
|
|
85
|
-
* URL options to be used when creating the redirect URL for the auth proxy.
|
|
86
|
-
*/
|
|
87
|
-
proxyOptions?: Omit<CreateURLOptions, 'queryParams'> & {
|
|
88
|
-
path?: string;
|
|
89
|
-
};
|
|
90
73
|
/**
|
|
91
74
|
* Features to use with `window.open()`.
|
|
92
75
|
* @platform web
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthRequest.types.d.ts","sourceRoot":"","sources":["../src/AuthRequest.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"AuthRequest.types.d.ts","sourceRoot":"","sources":["../src/AuthRequest.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAGnF,oBAAY,mBAAmB;IAC7B;;;;;OAKG;IACH,IAAI,SAAS;IACb;;OAEG;IACH,KAAK,UAAU;CAChB;AAGD;;;;GAIG;AACH,oBAAY,YAAY;IACtB;;OAEG;IACH,IAAI,SAAS;IACb;;OAEG;IACH,KAAK,UAAU;IACf;;OAEG;IACH,OAAO,aAAa;CACrB;AAGD;;;;;;GAMG;AACH,oBAAY,MAAM;IAChB;;;;OAIG;IACH,IAAI,SAAS;IACb;;;OAGG;IACH,KAAK,UAAU;IACf;;;OAGG;IACH,OAAO,YAAY;IACnB;;;OAGG;IACH,aAAa,mBAAmB;CACjC;AAGD;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAAG,IAAI,CAAC,qBAAqB,EAAE,gBAAgB,CAAC,GAAG;IACrF;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,cAAc,CAAC,EAAE,wBAAwB,CAAC;CAC3C,CAAC;AAGF;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC;IACrC;;;;;;;;OAQG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAC1C;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthRequest.types.js","sourceRoot":"","sources":["../src/AuthRequest.types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AuthRequest.types.js","sourceRoot":"","sources":["../src/AuthRequest.types.ts"],"names":[],"mappings":"AAEA,cAAc;AACd,MAAM,CAAN,IAAY,mBAYX;AAZD,WAAY,mBAAmB;IAC7B;;;;;OAKG;IACH,oCAAa,CAAA;IACb;;OAEG;IACH,sCAAe,CAAA;AACjB,CAAC,EAZW,mBAAmB,KAAnB,mBAAmB,QAY9B;AAED,cAAc;AACd;;;;GAIG;AACH,MAAM,CAAN,IAAY,YAaX;AAbD,WAAY,YAAY;IACtB;;OAEG;IACH,6BAAa,CAAA;IACb;;OAEG;IACH,+BAAe,CAAA;IACf;;OAEG;IACH,oCAAoB,CAAA;AACtB,CAAC,EAbW,YAAY,KAAZ,YAAY,QAavB;AAED,cAAc;AACd;;;;;;GAMG;AACH,MAAM,CAAN,IAAY,MAsBX;AAtBD,WAAY,MAAM;IAChB;;;;OAIG;IACH,uBAAa,CAAA;IACb;;;OAGG;IACH,yBAAe,CAAA;IACf;;;OAGG;IACH,6BAAmB,CAAA;IACnB;;;OAGG;IACH,0CAAgC,CAAA;AAClC,CAAC,EAtBW,MAAM,KAAN,MAAM,QAsBjB","sourcesContent":["import { WebBrowserOpenOptions, WebBrowserWindowFeatures } from 'expo-web-browser';\n\n// @needsAudit\nexport enum CodeChallengeMethod {\n /**\n * The default and recommended method for transforming the code verifier.\n * - Convert the code verifier to ASCII.\n * - Create a digest of the string using crypto method SHA256.\n * - Convert the digest to Base64 and URL encode it.\n */\n S256 = 'S256',\n /**\n * This should not be used. When used, the code verifier will be sent to the server as-is.\n */\n Plain = 'plain',\n}\n\n// @needsAudit\n/**\n * The client informs the authorization server of the desired grant type by using the response type.\n *\n * @see [Section 3.1.1](https://tools.ietf.org/html/rfc6749#section-3.1.1).\n */\nexport enum ResponseType {\n /**\n * For requesting an authorization code as described by [Section 4.1.1](https://tools.ietf.org/html/rfc6749#section-4.1.1).\n */\n Code = 'code',\n /**\n * For requesting an access token (implicit grant) as described by [Section 4.2.1](https://tools.ietf.org/html/rfc6749#section-4.2.1).\n */\n Token = 'token',\n /**\n * A custom registered type for getting an `id_token` from Google OAuth.\n */\n IdToken = 'id_token',\n}\n\n// @needsAudit\n/**\n * Informs the server if the user should be prompted to login or consent again.\n * This can be used to present a dialog for switching accounts after the user has already been logged in.\n * You should use this in favor of clearing cookies (which is mostly not possible on iOS).\n *\n * @see [Section 3.1.2.1](https://openid.net/specs/openid-connect-core-1_0.html#AuthorizationRequest).\n */\nexport enum Prompt {\n /**\n * Server must not display any auth or consent UI. Can be used to check for existing auth or consent.\n * An error is returned if a user isn't already authenticated or the client doesn't have pre-configured consent for the requested claims, or does not fulfill other conditions for processing the request.\n * The error code will typically be `login_required`, `interaction_required`, or another code defined in [Section 3.1.2.6](https://openid.net/specs/openid-connect-core-1_0.html#AuthError).\n */\n None = 'none',\n /**\n * The server should prompt the user to reauthenticate.\n * If it cannot reauthenticate the End-User, it must return an error, typically `login_required`.\n */\n Login = 'login',\n /**\n * Server should prompt the user for consent before returning information to the client.\n * If it cannot obtain consent, it must return an error, typically `consent_required`.\n */\n Consent = 'consent',\n /**\n * Server should prompt the user to select an account. Can be used to switch accounts.\n * If it can't obtain an account selection choice made by the user, it must return an error, typically `account_selection_required`.\n */\n SelectAccount = 'select_account',\n}\n\n// @needsAudit\n/**\n * Options passed to the `promptAsync()` method of `AuthRequest`s.\n * This can be used to configure how the web browser should look and behave.\n */\nexport type AuthRequestPromptOptions = Omit<WebBrowserOpenOptions, 'windowFeatures'> & {\n /**\n * URL to open when prompting the user. This usually should be defined internally and left `undefined` in most cases.\n */\n url?: string;\n /**\n * Features to use with `window.open()`.\n * @platform web\n */\n windowFeatures?: WebBrowserWindowFeatures;\n};\n\n// @needsAudit\n/**\n * Represents an OAuth authorization request as JSON.\n */\nexport interface AuthRequestConfig {\n /**\n * Specifies what is returned from the authorization server.\n *\n * [Section 3.1.1](https://tools.ietf.org/html/rfc6749#section-3.1.1)\n *\n * @default ResponseType.Code\n */\n responseType?: ResponseType | string;\n /**\n * A unique string representing the registration information provided by the client.\n * The client identifier is not a secret; it is exposed to the resource owner and shouldn't be used\n * alone for client authentication.\n *\n * The client identifier is unique to the authorization server.\n *\n * [Section 2.2](https://tools.ietf.org/html/rfc6749#section-2.2)\n */\n clientId: string;\n /**\n * After completing an interaction with a resource owner the\n * server will redirect to this URI. Learn more about [linking in Expo](/guides/linking/).\n *\n * [Section 3.1.2](https://tools.ietf.org/html/rfc6749#section-3.1.2)\n */\n redirectUri: string;\n /**\n * List of strings to request access to.\n *\n * [Section 3.3](https://tools.ietf.org/html/rfc6749#section-3.3)\n */\n scopes?: string[];\n /**\n * Client secret supplied by an auth provider.\n * There is no secure way to store this on the client.\n *\n * [Section 2.3.1](https://tools.ietf.org/html/rfc6749#section-2.3.1)\n */\n clientSecret?: string;\n /**\n * Method used to generate the code challenge. You should never use `Plain` as it's not good enough for secure verification.\n * @default CodeChallengeMethod.S256\n */\n codeChallengeMethod?: CodeChallengeMethod;\n /**\n * Derived from the code verifier by using the `CodeChallengeMethod`.\n *\n * [Section 4.2](https://tools.ietf.org/html/rfc7636#section-4.2)\n */\n codeChallenge?: string;\n /**\n * Informs the server if the user should be prompted to login or consent again.\n * This can be used to present a dialog for switching accounts after the user has already been logged in.\n *\n * [Section 3.1.2.1](https://openid.net/specs/openid-connect-core-1_0.html#AuthorizationRequest)\n */\n prompt?: Prompt;\n /**\n * Used for protection against [Cross-Site Request Forgery](https://tools.ietf.org/html/rfc6749#section-10.12).\n */\n state?: string;\n /**\n * Extra query params that'll be added to the query string.\n */\n extraParams?: Record<string, string>;\n /**\n * Should use [Proof Key for Code Exchange](https://oauth.net/2/pkce/).\n * @default true\n */\n usePKCE?: boolean;\n}\n"]}
|
|
@@ -22,7 +22,7 @@ export declare function useAuthRequestResult(request: AuthRequest | null, discov
|
|
|
22
22
|
* Load an authorization request for a code. When the prompt method completes then the response will be fulfilled.
|
|
23
23
|
*
|
|
24
24
|
* > In order to close the popup window on web, you need to invoke `WebBrowser.maybeCompleteAuthSession()`.
|
|
25
|
-
* > See the [Identity example](/guides/authentication
|
|
25
|
+
* > See the [Identity example](/guides/authentication#identityserver-4) for more info.
|
|
26
26
|
*
|
|
27
27
|
* If an Implicit grant flow was used, you can pass the `response.params` to `TokenResponse.fromQueryParams()`
|
|
28
28
|
* to get a `TokenResponse` instance which you can use to easily refresh the token.
|
|
@@ -37,7 +37,6 @@ export declare function useAuthRequestResult(request: AuthRequest | null, discov
|
|
|
37
37
|
* - `response` - This is `null` until `promptAsync` has been invoked. Once fulfilled it will return information about the authorization.
|
|
38
38
|
* - `promptAsync` - When invoked, a web browser will open up and prompt the user for authentication.
|
|
39
39
|
* Accepts an [`AuthRequestPromptOptions`](#authrequestpromptoptions) object with options about how the prompt will execute.
|
|
40
|
-
* You can use this to enable the Expo proxy service `auth.expo.io`.
|
|
41
40
|
*
|
|
42
41
|
* @example
|
|
43
42
|
* ```ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthRequestHooks.d.ts","sourceRoot":"","sources":["../src/AuthRequestHooks.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAyB,MAAM,aAAa,CAAC;AAG1F;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,iBAAiB,EAAE,iBAAiB,GAAG,iBAAiB,GAAG,IAAI,CAiB/F;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,iBAAiB,EACzB,SAAS,EAAE,iBAAiB,GAAG,IAAI,EACnC,mBAAmB,EAAE,OAAO,WAAW,GACtC,WAAW,GAAG,IAAI,CAmCpB;AAED,KAAK,YAAY,GAAG,CAAC,OAAO,CAAC,EAAE,wBAAwB,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAE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G,IAAI;IACxB,CAAC,OAAO,CAAC,EAAE,wBAAwB,KAAK,OAAO,CAAC,iBAAiB,CAAC;CACnE,CAIA"}
|
|
@@ -86,7 +86,7 @@ export function useAuthRequestResult(request, discovery, customOptions = {}) {
|
|
|
86
86
|
* Load an authorization request for a code. When the prompt method completes then the response will be fulfilled.
|
|
87
87
|
*
|
|
88
88
|
* > In order to close the popup window on web, you need to invoke `WebBrowser.maybeCompleteAuthSession()`.
|
|
89
|
-
* > See the [Identity example](/guides/authentication
|
|
89
|
+
* > See the [Identity example](/guides/authentication#identityserver-4) for more info.
|
|
90
90
|
*
|
|
91
91
|
* If an Implicit grant flow was used, you can pass the `response.params` to `TokenResponse.fromQueryParams()`
|
|
92
92
|
* to get a `TokenResponse` instance which you can use to easily refresh the token.
|
|
@@ -101,7 +101,6 @@ export function useAuthRequestResult(request, discovery, customOptions = {}) {
|
|
|
101
101
|
* - `response` - This is `null` until `promptAsync` has been invoked. Once fulfilled it will return information about the authorization.
|
|
102
102
|
* - `promptAsync` - When invoked, a web browser will open up and prompt the user for authentication.
|
|
103
103
|
* Accepts an [`AuthRequestPromptOptions`](#authrequestpromptoptions) object with options about how the prompt will execute.
|
|
104
|
-
* You can use this to enable the Expo proxy service `auth.expo.io`.
|
|
105
104
|
*
|
|
106
105
|
* @example
|
|
107
106
|
* ```ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthRequestHooks.js","sourceRoot":"","sources":["../src/AuthRequestHooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAElE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,OAAO,EAAwC,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAE1F,cAAc;AACd;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAAC,iBAAoC;IACnE,MAAM,CAAC,SAAS,EAAE,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C,aAAa,CAAC,cAAc,IAAI,EAAE,CAAC;gBACvC,GAAG,cAAc;aAClB;SACF,CAAC;QACF,MAAM,MAAM,GAAG,MAAM,OAAO,EAAE,WAAW,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;QACnE,SAAS,CAAC,MAAM,CAAC,CAAC;QAClB,OAAO,MAAM,CAAC;IAChB,CAAC,EACD,CAAC,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,qBAAqB,CAAC,CACjD,CAAC;IAEF,OAAO,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAC/B,CAAC;AAED,cAAc;AACd;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAyB,EACzB,SAAmC;IAMnC,MAAM,OAAO,GAAG,oBAAoB,CAAC,MAAM,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;IACrE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,oBAAoB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACvE,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;AACxC,CAAC","sourcesContent":["import { useCallback, useMemo, useEffect, useState } from 'react';\n\nimport { AuthRequest } from './AuthRequest';\nimport { AuthRequestConfig, AuthRequestPromptOptions } from './AuthRequest.types';\nimport { AuthSessionResult } from './AuthSession.types';\nimport { DiscoveryDocument, IssuerOrDiscovery, resolveDiscoveryAsync } from './Discovery';\n\n// @needsAudit\n/**\n * Given an OpenID Connect issuer URL, this will fetch and return the [`DiscoveryDocument`](#discoverydocument)\n * (a collection of URLs) from the resource provider.\n *\n * @param issuerOrDiscovery URL using the `https` scheme with no query or fragment component that the OP asserts as its Issuer Identifier.\n * @return Returns `null` until the [`DiscoveryDocument`](#discoverydocument) has been fetched from the provided issuer URL.\n *\n * @example\n * ```ts\n * const discovery = useAutoDiscovery('https://example.com/auth');\n * ```\n */\nexport function useAutoDiscovery(issuerOrDiscovery: IssuerOrDiscovery): DiscoveryDocument | null {\n const [discovery, setDiscovery] = useState<DiscoveryDocument | null>(null);\n\n useEffect(() => {\n let isAllowed = true;\n resolveDiscoveryAsync(issuerOrDiscovery).then((discovery) => {\n if (isAllowed) {\n setDiscovery(discovery);\n }\n });\n\n return () => {\n isAllowed = false;\n };\n }, [issuerOrDiscovery]);\n\n return discovery;\n}\n\nexport function useLoadedAuthRequest(\n config: AuthRequestConfig,\n discovery: DiscoveryDocument | null,\n AuthRequestInstance: typeof AuthRequest\n): AuthRequest | null {\n const [request, setRequest] = useState<AuthRequest | null>(null);\n const scopeString = useMemo(() => config.scopes?.join(','), [config.scopes]);\n const extraParamsString = useMemo(\n () => JSON.stringify(config.extraParams || {}),\n [config.extraParams]\n );\n useEffect(() => {\n let isMounted = true;\n\n if (discovery) {\n const request = new AuthRequestInstance(config);\n request.makeAuthUrlAsync(discovery).then(() => {\n if (isMounted) {\n setRequest(request);\n }\n });\n }\n return () => {\n isMounted = false;\n };\n }, [\n discovery?.authorizationEndpoint,\n config.clientId,\n config.redirectUri,\n config.responseType,\n config.prompt,\n config.clientSecret,\n config.codeChallenge,\n config.state,\n config.usePKCE,\n scopeString,\n extraParamsString,\n ]);\n return request;\n}\n\ntype PromptMethod = (options?: AuthRequestPromptOptions) => Promise<AuthSessionResult>;\n\nexport function useAuthRequestResult(\n request: AuthRequest | null,\n discovery: DiscoveryDocument | null,\n customOptions: AuthRequestPromptOptions = {}\n): [AuthSessionResult | null, PromptMethod] {\n const [result, setResult] = useState<AuthSessionResult | null>(null);\n\n const promptAsync = useCallback(\n async ({ windowFeatures = {}, ...options }: AuthRequestPromptOptions = {}) => {\n if (!discovery || !request) {\n throw new Error('Cannot prompt to authenticate until the request has finished loading.');\n }\n const inputOptions = {\n ...customOptions,\n ...options,\n windowFeatures: {\n ...(customOptions.windowFeatures ?? {}),\n ...windowFeatures,\n },\n };\n const result = await request?.promptAsync(discovery, inputOptions);\n setResult(result);\n return result;\n },\n [request?.url, discovery?.authorizationEndpoint]\n );\n\n return [result, promptAsync];\n}\n\n// @needsAudit\n/**\n * Load an authorization request for a code. When the prompt method completes then the response will be fulfilled.\n *\n * > In order to close the popup window on web, you need to invoke `WebBrowser.maybeCompleteAuthSession()`.\n * > See the [Identity example](/guides/authentication#identityserver-4) for more info.\n *\n * If an Implicit grant flow was used, you can pass the `response.params` to `TokenResponse.fromQueryParams()`\n * to get a `TokenResponse` instance which you can use to easily refresh the token.\n *\n * @param config A valid [`AuthRequestConfig`](#authrequestconfig) that specifies what provider to use.\n * @param discovery A loaded [`DiscoveryDocument`](#discoverydocument) with endpoints used for authenticating.\n * Only `authorizationEndpoint` is required for requesting an authorization code.\n *\n * @return Returns a loaded request, a response, and a prompt method in a single array in the following order:\n * - `request` - An instance of [`AuthRequest`](#authrequest) that can be used to prompt the user for authorization.\n * This will be `null` until the auth request has finished loading.\n * - `response` - This is `null` until `promptAsync` has been invoked. Once fulfilled it will return information about the authorization.\n * - `promptAsync` - When invoked, a web browser will open up and prompt the user for authentication.\n * Accepts an [`AuthRequestPromptOptions`](#authrequestpromptoptions) object with options about how the prompt will execute.\n *\n * @example\n * ```ts\n * const [request, response, promptAsync] = useAuthRequest({ ... }, { ... });\n * ```\n */\nexport function useAuthRequest(\n config: AuthRequestConfig,\n discovery: DiscoveryDocument | null\n): [\n AuthRequest | null,\n AuthSessionResult | null,\n (options?: AuthRequestPromptOptions) => Promise<AuthSessionResult>\n] {\n const request = useLoadedAuthRequest(config, discovery, AuthRequest);\n const [result, promptAsync] = useAuthRequestResult(request, discovery);\n return [request, result, promptAsync];\n}\n"]}
|
package/build/AuthSession.d.ts
CHANGED
|
@@ -4,14 +4,6 @@ import { AuthRequestConfig, AuthRequestPromptOptions, CodeChallengeMethod, Promp
|
|
|
4
4
|
import { AuthSessionOptions, AuthSessionRedirectUriOptions, AuthSessionResult } from './AuthSession.types';
|
|
5
5
|
import { DiscoveryDocument, fetchDiscoveryAsync, Issuer, IssuerOrDiscovery, ProviderMetadata, resolveDiscoveryAsync } from './Discovery';
|
|
6
6
|
import { generateHexStringAsync } from './PKCE';
|
|
7
|
-
/**
|
|
8
|
-
* Initiate a proxied authentication session with the given options. Only one `AuthSession` can be active at any given time in your application.
|
|
9
|
-
* If you attempt to open a second session while one is still in progress, the second session will return a value to indicate that `AuthSession` is locked.
|
|
10
|
-
*
|
|
11
|
-
* @param options An object of type `AuthSessionOptions`.
|
|
12
|
-
* @return Returns a Promise that resolves to an `AuthSessionResult` object.
|
|
13
|
-
*/
|
|
14
|
-
export declare function startAsync(options: AuthSessionOptions): Promise<AuthSessionResult>;
|
|
15
7
|
/**
|
|
16
8
|
* Cancels an active `AuthSession` if there is one. No return value, but if there is an active `AuthSession`
|
|
17
9
|
* then the Promise returned by the `AuthSession.startAsync()` that initiated it resolves to `{ type: 'dismiss' }`.
|
|
@@ -33,7 +25,7 @@ export declare const getDefaultReturnUrl: (urlPath?: string | undefined, options
|
|
|
33
25
|
* // Web: https://localhost:19006/redirect
|
|
34
26
|
* ```
|
|
35
27
|
*
|
|
36
|
-
* @deprecated Use `makeRedirectUri(
|
|
28
|
+
* @deprecated Use `makeRedirectUri()` instead.
|
|
37
29
|
*/
|
|
38
30
|
export declare function getRedirectUrl(path?: string): string;
|
|
39
31
|
/**
|
|
@@ -54,7 +46,7 @@ export declare function getRedirectUrl(path?: string): string;
|
|
|
54
46
|
* path: 'redirect'
|
|
55
47
|
* });
|
|
56
48
|
* // Development Build: my-scheme://redirect
|
|
57
|
-
* // Expo Go: exp://127.0.0.1:
|
|
49
|
+
* // Expo Go: exp://127.0.0.1:8081/--/redirect
|
|
58
50
|
* // Web dev: https://localhost:19006/redirect
|
|
59
51
|
* // Web prod: https://yourwebsite.com/redirect
|
|
60
52
|
*
|
|
@@ -64,20 +56,12 @@ export declare function getRedirectUrl(path?: string): string;
|
|
|
64
56
|
* isTripleSlashed: true,
|
|
65
57
|
* });
|
|
66
58
|
* // Development Build: scheme2:///
|
|
67
|
-
* // Expo Go: exp://localhost:
|
|
68
|
-
* // Web dev: https://localhost:19006
|
|
69
|
-
* // Web prod: https://yourwebsite.com
|
|
70
|
-
*
|
|
71
|
-
* const redirectUri3 = makeRedirectUri({
|
|
72
|
-
* useProxy: true,
|
|
73
|
-
* });
|
|
74
|
-
* // Development Build: https://auth.expo.io/@username/slug
|
|
75
|
-
* // Expo Go: https://auth.expo.io/@username/slug
|
|
59
|
+
* // Expo Go: exp://localhost:8081
|
|
76
60
|
* // Web dev: https://localhost:19006
|
|
77
61
|
* // Web prod: https://yourwebsite.com
|
|
78
62
|
* ```
|
|
79
63
|
*/
|
|
80
|
-
export declare function makeRedirectUri({ native, scheme, isTripleSlashed, queryParams, path, preferLocalhost,
|
|
64
|
+
export declare function makeRedirectUri({ native, scheme, isTripleSlashed, queryParams, path, preferLocalhost, }?: AuthSessionRedirectUriOptions): string;
|
|
81
65
|
/**
|
|
82
66
|
* Build an `AuthRequest` and load it before returning.
|
|
83
67
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthSession.d.ts","sourceRoot":"","sources":["../src/AuthSession.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"AuthSession.d.ts","sourceRoot":"","sources":["../src/AuthSession.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAIxC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,mBAAmB,EACnB,MAAM,EACN,YAAY,EACb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,kBAAkB,EAClB,6BAA6B,EAC7B,iBAAiB,EAClB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,MAAM,EACN,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,EACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,s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
|
1
1
|
import Constants, { ExecutionEnvironment } from 'expo-constants';
|
|
2
2
|
import * as Linking from 'expo-linking';
|
|
3
3
|
import { Platform } from 'expo-modules-core';
|
|
4
|
-
import { dismissAuthSession
|
|
4
|
+
import { dismissAuthSession } from 'expo-web-browser';
|
|
5
5
|
import { AuthRequest } from './AuthRequest';
|
|
6
6
|
import { CodeChallengeMethod, Prompt, ResponseType, } from './AuthRequest.types';
|
|
7
7
|
import { fetchDiscoveryAsync, resolveDiscoveryAsync, } from './Discovery';
|
|
8
8
|
import { generateHexStringAsync } from './PKCE';
|
|
9
|
-
import { getQueryParams } from './QueryParams';
|
|
10
9
|
import sessionUrlProvider from './SessionUrlProvider';
|
|
11
|
-
let _authLock = false;
|
|
12
|
-
// @needsAudit
|
|
13
|
-
/**
|
|
14
|
-
* Initiate a proxied authentication session with the given options. Only one `AuthSession` can be active at any given time in your application.
|
|
15
|
-
* If you attempt to open a second session while one is still in progress, the second session will return a value to indicate that `AuthSession` is locked.
|
|
16
|
-
*
|
|
17
|
-
* @param options An object of type `AuthSessionOptions`.
|
|
18
|
-
* @return Returns a Promise that resolves to an `AuthSessionResult` object.
|
|
19
|
-
*/
|
|
20
|
-
export async function startAsync(options) {
|
|
21
|
-
const authUrl = options.authUrl;
|
|
22
|
-
// Prevent accidentally starting to an empty url
|
|
23
|
-
if (!authUrl) {
|
|
24
|
-
throw new Error('No authUrl provided to AuthSession.startAsync. An authUrl is required -- it points to the page where the user will be able to sign in.');
|
|
25
|
-
}
|
|
26
|
-
// Prevent multiple sessions from running at the same time, WebBrowser doesn't
|
|
27
|
-
// support it this makes the behavior predictable.
|
|
28
|
-
if (_authLock) {
|
|
29
|
-
if (__DEV__) {
|
|
30
|
-
console.warn('Attempted to call AuthSession.startAsync multiple times while already active. Only one AuthSession can be active at any given time.');
|
|
31
|
-
}
|
|
32
|
-
return { type: 'locked' };
|
|
33
|
-
}
|
|
34
|
-
const returnUrl = options.returnUrl || sessionUrlProvider.getDefaultReturnUrl();
|
|
35
|
-
const startUrl = sessionUrlProvider.getStartUrl(authUrl, returnUrl, options.projectNameForProxy);
|
|
36
|
-
const showInRecents = options.showInRecents || false;
|
|
37
|
-
// About to start session, set lock
|
|
38
|
-
_authLock = true;
|
|
39
|
-
let result;
|
|
40
|
-
try {
|
|
41
|
-
result = await _openWebBrowserAsync(startUrl, returnUrl, showInRecents);
|
|
42
|
-
}
|
|
43
|
-
finally {
|
|
44
|
-
// WebBrowser session complete, unset lock
|
|
45
|
-
_authLock = false;
|
|
46
|
-
}
|
|
47
|
-
// Handle failures
|
|
48
|
-
if (!result) {
|
|
49
|
-
throw new Error('Unexpected missing AuthSession result');
|
|
50
|
-
}
|
|
51
|
-
if (!('url' in result)) {
|
|
52
|
-
if ('type' in result) {
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
throw new Error('Unexpected AuthSession result with missing type');
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
const { params, errorCode } = getQueryParams(result.url);
|
|
60
|
-
return {
|
|
61
|
-
type: errorCode ? 'error' : 'success',
|
|
62
|
-
params,
|
|
63
|
-
errorCode,
|
|
64
|
-
authentication: null,
|
|
65
|
-
url: result.url,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
10
|
// @needsAudit
|
|
69
11
|
/**
|
|
70
12
|
* Cancels an active `AuthSession` if there is one. No return value, but if there is an active `AuthSession`
|
|
@@ -90,7 +32,7 @@ export const getDefaultReturnUrl = sessionUrlProvider.getDefaultReturnUrl;
|
|
|
90
32
|
* // Web: https://localhost:19006/redirect
|
|
91
33
|
* ```
|
|
92
34
|
*
|
|
93
|
-
* @deprecated Use `makeRedirectUri(
|
|
35
|
+
* @deprecated Use `makeRedirectUri()` instead.
|
|
94
36
|
*/
|
|
95
37
|
export function getRedirectUrl(path) {
|
|
96
38
|
return sessionUrlProvider.getRedirectUrl({ urlPath: path });
|
|
@@ -114,7 +56,7 @@ export function getRedirectUrl(path) {
|
|
|
114
56
|
* path: 'redirect'
|
|
115
57
|
* });
|
|
116
58
|
* // Development Build: my-scheme://redirect
|
|
117
|
-
* // Expo Go: exp://127.0.0.1:
|
|
59
|
+
* // Expo Go: exp://127.0.0.1:8081/--/redirect
|
|
118
60
|
* // Web dev: https://localhost:19006/redirect
|
|
119
61
|
* // Web prod: https://yourwebsite.com/redirect
|
|
120
62
|
*
|
|
@@ -124,44 +66,32 @@ export function getRedirectUrl(path) {
|
|
|
124
66
|
* isTripleSlashed: true,
|
|
125
67
|
* });
|
|
126
68
|
* // Development Build: scheme2:///
|
|
127
|
-
* // Expo Go: exp://localhost:
|
|
128
|
-
* // Web dev: https://localhost:19006
|
|
129
|
-
* // Web prod: https://yourwebsite.com
|
|
130
|
-
*
|
|
131
|
-
* const redirectUri3 = makeRedirectUri({
|
|
132
|
-
* useProxy: true,
|
|
133
|
-
* });
|
|
134
|
-
* // Development Build: https://auth.expo.io/@username/slug
|
|
135
|
-
* // Expo Go: https://auth.expo.io/@username/slug
|
|
69
|
+
* // Expo Go: exp://localhost:8081
|
|
136
70
|
* // Web dev: https://localhost:19006
|
|
137
71
|
* // Web prod: https://yourwebsite.com
|
|
138
72
|
* ```
|
|
139
73
|
*/
|
|
140
|
-
export function makeRedirectUri({ native, scheme, isTripleSlashed, queryParams, path, preferLocalhost,
|
|
74
|
+
export function makeRedirectUri({ native, scheme, isTripleSlashed, queryParams, path, preferLocalhost, } = {}) {
|
|
141
75
|
if (Platform.OS !== 'web' &&
|
|
142
76
|
native &&
|
|
143
77
|
[ExecutionEnvironment.Standalone, ExecutionEnvironment.Bare].includes(Constants.executionEnvironment)) {
|
|
144
78
|
// Should use the user-defined native scheme in standalone builds
|
|
145
79
|
return native;
|
|
146
80
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return `${protocol}localhost${path}`;
|
|
159
|
-
}
|
|
81
|
+
const url = Linking.createURL(path || '', {
|
|
82
|
+
isTripleSlashed,
|
|
83
|
+
scheme,
|
|
84
|
+
queryParams,
|
|
85
|
+
});
|
|
86
|
+
if (preferLocalhost) {
|
|
87
|
+
const ipAddress = url.match(/\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/);
|
|
88
|
+
// Only replace if an IP address exists
|
|
89
|
+
if (ipAddress?.length) {
|
|
90
|
+
const [protocol, path] = url.split(ipAddress[0]);
|
|
91
|
+
return `${protocol}localhost${path}`;
|
|
160
92
|
}
|
|
161
|
-
return url;
|
|
162
93
|
}
|
|
163
|
-
|
|
164
|
-
return sessionUrlProvider.getRedirectUrl({ urlPath: path, projectNameForProxy });
|
|
94
|
+
return url;
|
|
165
95
|
}
|
|
166
96
|
// @needsAudit
|
|
167
97
|
/**
|
|
@@ -178,13 +108,6 @@ export async function loadAsync(config, issuerOrDiscovery) {
|
|
|
178
108
|
await request.makeAuthUrlAsync(discovery);
|
|
179
109
|
return request;
|
|
180
110
|
}
|
|
181
|
-
async function _openWebBrowserAsync(startUrl, returnUrl, showInRecents) {
|
|
182
|
-
const result = await openAuthSessionAsync(startUrl, returnUrl, { showInRecents });
|
|
183
|
-
if (result.type === 'cancel' || result.type === 'dismiss') {
|
|
184
|
-
return { type: result.type };
|
|
185
|
-
}
|
|
186
|
-
return result;
|
|
187
|
-
}
|
|
188
111
|
export { useAutoDiscovery, useAuthRequest } from './AuthRequestHooks';
|
|
189
112
|
export { AuthError, TokenError } from './Errors';
|
|
190
113
|
export { AuthRequest, CodeChallengeMethod, Prompt, ResponseType, resolveDiscoveryAsync, fetchDiscoveryAsync, generateHexStringAsync, };
|