expo-auth-session 3.2.2 → 3.4.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 CHANGED
@@ -8,6 +8,25 @@
8
8
 
9
9
  ### 🐛 Bug fixes
10
10
 
11
+ ### 💡 Others
12
+
13
+ ## 3.4.0 — 2021-09-28
14
+
15
+ ### 🎉 New features
16
+
17
+ - Update JS code to read manifest2 when manifest is not available. ([#13602](https://github.com/expo/expo/pull/13602) by [@wschurman](https://github.com/wschurman))
18
+
19
+ ## 3.3.0 — 2021-06-16
20
+
21
+ ### 🐛 Bug fixes
22
+
23
+ - Add new manifest2 field and make existing field optional. ([#12817](https://github.com/expo/expo/pull/12817) by [@wschurman](https://github.com/wschurman))
24
+ - Use originalFullName instead of currentFullName ([#12953](https://github.com/expo/expo/pull/12953)) by [@wschurman](https://github.com/wschurman))
25
+
26
+ ## 3.2.3 — 2021-04-13
27
+
28
+ _This version does not introduce any user-facing changes._
29
+
11
30
  ## 3.2.2 — 2021-04-09
12
31
 
13
32
  ### 🎉 New features
@@ -89,3 +108,4 @@ _This version does not introduce any user-facing changes._
89
108
  ### 🐛 Bug fixes
90
109
 
91
110
  - Fix `AuthSession.getDefaultReturnUrl()` returning wrong URL while using release channels. ([#7687](https://github.com/expo/expo/pull/7687) by [@lukmccall](https://github.com/lukmccall))
111
+ - Fixed a bug where the `useAutoDiscovery()` hook hadn't finished before a component was unmounted. There was no cleanup, so when the fetch request completed, a react state update was attempted on an unmounted component. ([#12491](https://github.com/expo/expo/pull/12491) by [@andrew1601](https://github.com/andrew1601))
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  # Installation in managed Expo projects
11
11
 
12
- For managed [managed](https://docs.expo.io/versions/latest/introduction/managed-vs-bare/) Expo projects, please follow the installation instructions in the [API documentation for the latest stable release](https://docs.expo.io/versions/latest/sdk/auth-session).
12
+ For [managed](https://docs.expo.io/versions/latest/introduction/managed-vs-bare/) Expo projects, please follow the installation instructions in the [API documentation for the latest stable release](https://docs.expo.io/versions/latest/sdk/auth-session).
13
13
 
14
14
  # Installation in bare React Native projects
15
15
 
@@ -14,8 +14,23 @@ let _authLock = false;
14
14
  * [Section 4.1.1](https://tools.ietf.org/html/rfc6749#section-4.1.1)
15
15
  */
16
16
  export class AuthRequest {
17
+ /**
18
+ * Used for protection against [Cross-Site Request Forgery](https://tools.ietf.org/html/rfc6749#section-10.12).
19
+ */
20
+ state;
21
+ url = null;
22
+ codeVerifier;
23
+ codeChallenge;
24
+ responseType;
25
+ clientId;
26
+ extraParams;
27
+ usePKCE;
28
+ codeChallengeMethod;
29
+ redirectUri;
30
+ scopes;
31
+ clientSecret;
32
+ prompt;
17
33
  constructor(request) {
18
- this.url = null;
19
34
  this.responseType = request.responseType ?? ResponseType.Code;
20
35
  this.clientId = request.clientId;
21
36
  this.redirectUri = request.redirectUri;
@@ -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;;;;GAIG;AACH,MAAM,OAAO,WAAW;IAmBtB,YAAY,OAA0B;QAd/B,QAAG,GAAkB,IAAI,CAAC;QAe/B,IAAI,CAAC,YAA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O,IAAI,OAAO,CAAC,mBAAmB,EAAE;YAClD,MAAM,CAAC,qBAAqB,GAAG,OAAO,CAAC,mBAAmB,CAAC;SAC5D;QAED,IAAI,OAAO,CAAC,YAAY,EAAE;YACxB,MAAM,CAAC,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;SAC7C;QAED,IAAI,OAAO,CAAC,MAAM,EAAE;YAClB,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;SAChC;QAED,mCAAmC;QACnC,MAAM,CAAC,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC;QAC1C,MAAM,CAAC,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC;QACpC,MAAM,CAAC,aAAa,GAAG,OAAO,CAAC,YAAa,CAAC;QAC7C,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAE7B,IAAI,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE;YAC1B,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SACzC;QAED,MAAM,KAAK,GAAG,WAAW,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;QACnD,0BAA0B;QAC1B,IAAI,CAAC,GAAG,GAAG,GAAG,SAAS,CAAC,qBAAqB,IAAI,KAAK,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 sessionUrlProvider from './SessionUrlProvider';\nimport { TokenResponse } from './TokenRequest';\n\nlet _authLock: boolean = false;\n\ntype AuthDiscoveryDocument = Pick<DiscoveryDocument, 'authorizationEndpoint'>;\n\n/**\n * Implements an authorization request.\n *\n * [Section 4.1.1](https://tools.ietf.org/html/rfc6749#section-4.1.1)\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 returnUrl = sessionUrlProvider.getDefaultReturnUrl(proxyOptions?.path, proxyOptions);\n startUrl = sessionUrlProvider.getStartUrl(url, returnUrl);\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,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;;;;GAIG;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;IACp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AAG,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 sessionUrlProvider from './SessionUrlProvider';\nimport { TokenResponse } from './TokenRequest';\n\nlet _authLock: boolean = false;\n\ntype AuthDiscoveryDocument = Pick<DiscoveryDocument, 'authorizationEndpoint'>;\n\n/**\n * Implements an authorization request.\n *\n * [Section 4.1.1](https://tools.ietf.org/html/rfc6749#section-4.1.1)\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 returnUrl = sessionUrlProvider.getDefaultReturnUrl(proxyOptions?.path, proxyOptions);\n startUrl = sessionUrlProvider.getStartUrl(url, returnUrl);\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"]}
@@ -9,18 +9,22 @@ import { resolveDiscoveryAsync } from './Discovery';
9
9
  export function useAutoDiscovery(issuerOrDiscovery) {
10
10
  const [discovery, setDiscovery] = useState(null);
11
11
  useEffect(() => {
12
- resolveDiscoveryAsync(issuerOrDiscovery).then(discovery => {
13
- setDiscovery(discovery);
12
+ let isAllowed = true;
13
+ resolveDiscoveryAsync(issuerOrDiscovery).then((discovery) => {
14
+ if (isAllowed) {
15
+ setDiscovery(discovery);
16
+ }
14
17
  });
18
+ return () => {
19
+ isAllowed = false;
20
+ };
15
21
  }, [issuerOrDiscovery]);
16
22
  return discovery;
17
23
  }
18
24
  export function useLoadedAuthRequest(config, discovery, AuthRequestInstance) {
19
25
  const [request, setRequest] = useState(null);
20
26
  const scopeString = useMemo(() => config.scopes?.join(','), [config.scopes]);
21
- const extraParamsString = useMemo(() => JSON.stringify(config.extraParams || {}), [
22
- config.extraParams,
23
- ]);
27
+ const extraParamsString = useMemo(() => JSON.stringify(config.extraParams || {}), [config.extraParams]);
24
28
  useEffect(() => {
25
29
  let isMounted = true;
26
30
  if (discovery) {
@@ -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;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,iBAAoC;IACnE,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAA2B,IAAI,CAAC,CAAC;IAE3E,SAAS,CAAC,GAAG,EAAE;QACb,qBAAqB,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;YACxD,YAAY,CAAC,SAAS,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAExB,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,MAAyB,EACzB,SAAmC,EACnC,mBAAuC;IAEvC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAqB,IAAI,CAAC,CAAC;IACjE,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7E,MAAM,iBAAiB,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC,EAAE;QAChF,MAAM,CAAC,WAAW;KACnB,CAAC,CAAC;IACH,SAAS,CAC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AAG,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;IACD,uDAAuD;IACvD,CAAC,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,qBAAqB,CAAC,CACjD,CAAC;IAEF,OAAO,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAC/B,CAAC;AAED;;;;;;;GAOG;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/**\n * Fetch the discovery document from an OpenID Connect issuer.\n *\n * @param issuerOrDiscovery\n */\nexport function useAutoDiscovery(issuerOrDiscovery: IssuerOrDiscovery): DiscoveryDocument | null {\n const [discovery, setDiscovery] = useState<DiscoveryDocument | null>(null);\n\n useEffect(() => {\n resolveDiscoveryAsync(issuerOrDiscovery).then(discovery => {\n setDiscovery(discovery);\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(() => JSON.stringify(config.extraParams || {}), [\n config.extraParams,\n ]);\n useEffect(\n () => {\n let isMounted = true;\n\n if (discovery) {\n const request = new AuthRequestInstance(config);\n request.makeAuthUrlAsync(discovery).then(() => {\n if (isMounted) {\n // @ts-ignore\n setRequest(request);\n }\n });\n }\n return () => {\n isMounted = false;\n };\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\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 );\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 // eslint-disable-next-line react-hooks/exhaustive-deps\n [request?.url, discovery?.authorizationEndpoint]\n );\n\n return [result, promptAsync];\n}\n\n/**\n * Load an authorization request.\n * Returns a loaded request, a response, and a prompt method.\n * When the prompt method completes then the response will be fulfilled.\n *\n * @param config\n * @param discovery\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"]}
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;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,iBAAoC;IACnE,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAA2B,IAAI,CAAC,CAAC;IAE3E,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,SAAS,GAAG,IAAI,CAAC;QACrB,qBAAqB,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE;YAC1D,IAAI,SAAS,EAAE;gBACb,YAAY,CAAC,SAAS,CAAC,CAAC;aACzB;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE;YACV,SAAS,GAAG,KAAK,CAAC;QACpB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAExB,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,MAAyB,EACzB,SAAmC,EACnC,mBAAuC;IAEvC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAqB,IAAI,CAAC,CAAC;IACjE,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7E,MAAM,iBAAiB,GAAG,OAAO,CA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SAC1F;QACD,MAAM,YAAY,GAAG;YACnB,GAAG,aAAa;YAChB,GAAG,OAAO;YACV,cAAc,EAAE;gBACd,GAAG,CAAC,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;IACD,uDAAuD;IACvD,CAAC,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,qBAAqB,CAAC,CACjD,CAAC;IAEF,OAAO,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAC/B,CAAC;AAED;;;;;;;GAOG;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/**\n * Fetch the discovery document from an OpenID Connect issuer.\n *\n * @param issuerOrDiscovery\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 () => {\n let isMounted = true;\n\n if (discovery) {\n const request = new AuthRequestInstance(config);\n request.makeAuthUrlAsync(discovery).then(() => {\n if (isMounted) {\n // @ts-ignore\n setRequest(request);\n }\n });\n }\n return () => {\n isMounted = false;\n };\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\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 );\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 // eslint-disable-next-line react-hooks/exhaustive-deps\n [request?.url, discovery?.authorizationEndpoint]\n );\n\n return [result, promptAsync];\n}\n\n/**\n * Load an authorization request.\n * Returns a loaded request, a response, and a prompt method.\n * When the prompt method completes then the response will be fulfilled.\n *\n * @param config\n * @param discovery\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"]}
@@ -6,7 +6,7 @@ import { DiscoveryDocument, fetchDiscoveryAsync, Issuer, IssuerOrDiscovery, Prov
6
6
  import { generateHexStringAsync } from './PKCE';
7
7
  export declare function startAsync(options: AuthSessionOptions): Promise<AuthSessionResult>;
8
8
  export declare function dismiss(): void;
9
- export declare const getDefaultReturnUrl: (urlPath?: string | undefined, options?: Pick<Linking.CreateURLOptions, "scheme" | "isTripleSlashed"> | undefined) => string;
9
+ export declare const getDefaultReturnUrl: (urlPath?: string | undefined, options?: Omit<Linking.CreateURLOptions, "queryParams"> | undefined) => string;
10
10
  /**
11
11
  * @deprecated Use `makeRedirectUri({ path, useProxy })` instead.
12
12
  *
@@ -1,6 +1,6 @@
1
- import { Platform } from '@unimodules/core';
2
1
  import Constants, { ExecutionEnvironment } from 'expo-constants';
3
2
  import * as Linking from 'expo-linking';
3
+ import { Platform } from 'expo-modules-core';
4
4
  import { dismissAuthSession, openAuthSessionAsync } from 'expo-web-browser';
5
5
  import { AuthRequest } from './AuthRequest';
6
6
  import { CodeChallengeMethod, Prompt, ResponseType, } from './AuthRequest.types';
@@ -1 +1 @@
1
- {"version":3,"file":"AuthSession.js","sourceRoot":"","sources":["../src/AuthSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,SAAS,EAAE,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAA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9B;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEjD,OAAO,EAIL,WAAW,EAGX,mBAAmB,EAInB,MAAM,EAEN,YAAY,EACZ,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,GACvB,CAAC;AAEF,OAAO;AACL,gBAAgB;AAChB,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB;AAClB,gBAAgB;AAChB,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AAExB,cAAc;AACd,cAAc,sBAAsB,CAAC","sourcesContent":["import { Platform } from '@unimodules/core';\nimport Constants, { ExecutionEnvironment } from 'expo-constants';\nimport * as Linking from 'expo-linking';\nimport { dismissAuthSession, openAuthSessionAsync } from 'expo-web-browser';\n\nimport { AuthRequest } from './AuthRequest';\nimport {\n AuthRequestConfig,\n AuthRequestPromptOptions,\n CodeChallengeMethod,\n Prompt,\n ResponseType,\n} from './AuthRequest.types';\nimport {\n AuthSessionOptions,\n AuthSessionRedirectUriOptions,\n AuthSessionResult,\n} from './AuthSession.types';\nimport {\n DiscoveryDocument,\n fetchDiscoveryAsync,\n Issuer,\n IssuerOrDiscovery,\n ProviderMetadata,\n resolveDiscoveryAsync,\n} from './Discovery';\nimport { generateHexStringAsync } from './PKCE';\nimport { getQueryParams } from './QueryParams';\nimport sessionUrlProvider from './SessionUrlProvider';\n\nlet _authLock = false;\n\nexport async function startAsync(options: AuthSessionOptions): Promise<AuthSessionResult> {\n const authUrl = options.authUrl;\n // Prevent accidentally starting to an empty url\n if (!authUrl) {\n throw new Error(\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 // 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 const returnUrl = options.returnUrl || sessionUrlProvider.getDefaultReturnUrl();\n const startUrl = sessionUrlProvider.getStartUrl(authUrl, returnUrl);\n const showInRecents = options.showInRecents || false;\n\n // About to start session, set lock\n _authLock = true;\n\n let result;\n try {\n result = await _openWebBrowserAsync(startUrl, returnUrl, showInRecents);\n } finally {\n // WebBrowser session complete, unset lock\n _authLock = false;\n }\n\n // Handle failures\n if (!result) {\n throw new Error('Unexpected missing AuthSession result');\n }\n if (!result.url) {\n if (result.type) {\n return result;\n } else {\n throw new Error('Unexpected AuthSession result with missing type');\n }\n }\n\n const { params, errorCode } = getQueryParams(result.url);\n\n return {\n type: errorCode ? 'error' : 'success',\n params,\n errorCode,\n authentication: null,\n url: result.url,\n };\n}\n\nexport function dismiss() {\n dismissAuthSession();\n}\n\nexport const getDefaultReturnUrl = sessionUrlProvider.getDefaultReturnUrl;\n\n/**\n * @deprecated Use `makeRedirectUri({ path, useProxy })` instead.\n *\n * @param path\n */\nexport function getRedirectUrl(path?: string): string {\n return sessionUrlProvider.getRedirectUrl(path);\n}\n\n/**\n * Create a redirect url for the current platform.\n *\n * - **Web:** Generates a path based on the current \\`window.location\\`. For production web apps you should hard code the URL.\n * - **Managed:** Uses the `scheme` property of your `app.config.js` or `app.json`.\n * - **Proxy:** Uses auth.expo.io as the base URL for the path. This only works in Expo client and standalone environments.\n * - **Bare workflow:** Provide either the `scheme` or a manual `native` property to use.\n *\n * @param options Additional options for configuring the path.\n *\n * @example\n * ```ts\n * const redirectUri = makeRedirectUri({\n * scheme: 'my-scheme',\n * path: 'redirect'\n * });\n * // Custom app: my-scheme://redirect\n * // Expo Go: exp://127.0.0.1:19000/--/redirect\n * // Web dev: https://localhost:19006/redirect\n * // Web prod: https://yourwebsite.com/redirect\n *\n * const redirectUri2 = makeRedirectUri({\n * scheme: 'scheme2',\n * preferLocalhost: true,\n * isTripleSlashed: true,\n * });\n * // Custom app: scheme2:///\n * // Expo Go: exp://localhost:19000\n * // Web dev: https://localhost:19006\n * // Web prod: https://yourwebsite.com\n * ```\n *\n * const redirectUri3 = makeRedirectUri({\n * useProxy: true,\n * });\n * // Custom app: https://auth.expo.io/@username/slug\n * // Expo Go: https://auth.expo.io/@username/slug\n * // Web dev: https://localhost:19006\n * // Web prod: https://yourwebsite.com\n * ```\n */\nexport function makeRedirectUri({\n native,\n scheme,\n isTripleSlashed,\n queryParams,\n path,\n preferLocalhost,\n useProxy,\n}: AuthSessionRedirectUriOptions = {}): string {\n if (\n Platform.OS !== 'web' &&\n native &&\n [ExecutionEnvironment.Standalone, ExecutionEnvironment.Bare].includes(\n Constants.executionEnvironment\n )\n ) {\n // Should use the user-defined native scheme in standalone builds\n return native;\n }\n if (!useProxy || Platform.OS === 'web') {\n const url = Linking.createURL(path || '', {\n isTripleSlashed,\n scheme,\n queryParams,\n });\n\n if (preferLocalhost) {\n const ipAddress = url.match(\n /\\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/\n );\n // Only replace if an IP address exists\n if (ipAddress?.length) {\n const [protocol, path] = url.split(ipAddress[0]);\n return `${protocol}localhost${path}`;\n }\n }\n\n return url;\n }\n // Attempt to use the proxy\n return sessionUrlProvider.getRedirectUrl(path);\n}\n\n/**\n * Build an `AuthRequest` and load it before returning.\n *\n * @param config\n * @param issuerOrDiscovery\n */\nexport async function loadAsync(\n config: AuthRequestConfig,\n issuerOrDiscovery: IssuerOrDiscovery\n): Promise<AuthRequest> {\n const request = new AuthRequest(config);\n const discovery = await resolveDiscoveryAsync(issuerOrDiscovery);\n await request.makeAuthUrlAsync(discovery);\n return request;\n}\n\nasync function _openWebBrowserAsync(startUrl: string, returnUrl: string, showInRecents: boolean) {\n // $FlowIssue: Flow thinks the awaited result can be a promise\n const result = await openAuthSessionAsync(startUrl, returnUrl, { showInRecents });\n if (result.type === 'cancel' || result.type === 'dismiss') {\n return { type: result.type };\n }\n\n return result;\n}\n\nexport { useAutoDiscovery, useAuthRequest } from './AuthRequestHooks';\nexport { AuthError, TokenError } from './Errors';\n\nexport {\n AuthSessionOptions,\n AuthSessionRedirectUriOptions,\n AuthSessionResult,\n AuthRequest,\n AuthRequestConfig,\n AuthRequestPromptOptions,\n CodeChallengeMethod,\n DiscoveryDocument,\n Issuer,\n IssuerOrDiscovery,\n Prompt,\n ProviderMetadata,\n ResponseType,\n resolveDiscoveryAsync,\n fetchDiscoveryAsync,\n generateHexStringAsync,\n};\n\nexport {\n // Token classes\n TokenResponse,\n AccessTokenRequest,\n RefreshTokenRequest,\n RevokeTokenRequest,\n // Token methods\n revokeAsync,\n refreshAsync,\n exchangeCodeAsync,\n fetchUserInfoAsync,\n} from './TokenRequest';\n\n// Token types\nexport * from './TokenRequest.types';\n"]}
1
+ {"version":3,"file":"AuthSession.js","sourceRoot":"","sources":["../src/AuthSession.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,EAAE,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE5E,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAGL,mBAAmB,EACnB,MAAM,EACN,YAAY,GACb,MAAM,qBAAqB,CAAC;AAM7B,OAAO,EAEL,mBAAmB,EAInB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,sBAAsB,EAAE,MAAM,QAAQ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;AACL,gBAAgB;AAChB,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB;AAClB,gBAAgB;AAChB,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AAExB,cAAc;AACd,cAAc,sBAAsB,CAAC","sourcesContent":["import Constants, { ExecutionEnvironment } from 'expo-constants';\nimport * as Linking from 'expo-linking';\nimport { Platform } from 'expo-modules-core';\nimport { dismissAuthSession, openAuthSessionAsync } from 'expo-web-browser';\n\nimport { AuthRequest } from './AuthRequest';\nimport {\n AuthRequestConfig,\n AuthRequestPromptOptions,\n CodeChallengeMethod,\n Prompt,\n ResponseType,\n} from './AuthRequest.types';\nimport {\n AuthSessionOptions,\n AuthSessionRedirectUriOptions,\n AuthSessionResult,\n} from './AuthSession.types';\nimport {\n DiscoveryDocument,\n fetchDiscoveryAsync,\n Issuer,\n IssuerOrDiscovery,\n ProviderMetadata,\n resolveDiscoveryAsync,\n} from './Discovery';\nimport { generateHexStringAsync } from './PKCE';\nimport { getQueryParams } from './QueryParams';\nimport sessionUrlProvider from './SessionUrlProvider';\n\nlet _authLock = false;\n\nexport async function startAsync(options: AuthSessionOptions): Promise<AuthSessionResult> {\n const authUrl = options.authUrl;\n // Prevent accidentally starting to an empty url\n if (!authUrl) {\n throw new Error(\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 // 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 const returnUrl = options.returnUrl || sessionUrlProvider.getDefaultReturnUrl();\n const startUrl = sessionUrlProvider.getStartUrl(authUrl, returnUrl);\n const showInRecents = options.showInRecents || false;\n\n // About to start session, set lock\n _authLock = true;\n\n let result;\n try {\n result = await _openWebBrowserAsync(startUrl, returnUrl, showInRecents);\n } finally {\n // WebBrowser session complete, unset lock\n _authLock = false;\n }\n\n // Handle failures\n if (!result) {\n throw new Error('Unexpected missing AuthSession result');\n }\n if (!result.url) {\n if (result.type) {\n return result;\n } else {\n throw new Error('Unexpected AuthSession result with missing type');\n }\n }\n\n const { params, errorCode } = getQueryParams(result.url);\n\n return {\n type: errorCode ? 'error' : 'success',\n params,\n errorCode,\n authentication: null,\n url: result.url,\n };\n}\n\nexport function dismiss() {\n dismissAuthSession();\n}\n\nexport const getDefaultReturnUrl = sessionUrlProvider.getDefaultReturnUrl;\n\n/**\n * @deprecated Use `makeRedirectUri({ path, useProxy })` instead.\n *\n * @param path\n */\nexport function getRedirectUrl(path?: string): string {\n return sessionUrlProvider.getRedirectUrl(path);\n}\n\n/**\n * Create a redirect url for the current platform.\n *\n * - **Web:** Generates a path based on the current \\`window.location\\`. For production web apps you should hard code the URL.\n * - **Managed:** Uses the `scheme` property of your `app.config.js` or `app.json`.\n * - **Proxy:** Uses auth.expo.io as the base URL for the path. This only works in Expo client and standalone environments.\n * - **Bare workflow:** Provide either the `scheme` or a manual `native` property to use.\n *\n * @param options Additional options for configuring the path.\n *\n * @example\n * ```ts\n * const redirectUri = makeRedirectUri({\n * scheme: 'my-scheme',\n * path: 'redirect'\n * });\n * // Custom app: my-scheme://redirect\n * // Expo Go: exp://127.0.0.1:19000/--/redirect\n * // Web dev: https://localhost:19006/redirect\n * // Web prod: https://yourwebsite.com/redirect\n *\n * const redirectUri2 = makeRedirectUri({\n * scheme: 'scheme2',\n * preferLocalhost: true,\n * isTripleSlashed: true,\n * });\n * // Custom app: scheme2:///\n * // Expo Go: exp://localhost:19000\n * // Web dev: https://localhost:19006\n * // Web prod: https://yourwebsite.com\n * ```\n *\n * const redirectUri3 = makeRedirectUri({\n * useProxy: true,\n * });\n * // Custom app: https://auth.expo.io/@username/slug\n * // Expo Go: https://auth.expo.io/@username/slug\n * // Web dev: https://localhost:19006\n * // Web prod: https://yourwebsite.com\n * ```\n */\nexport function makeRedirectUri({\n native,\n scheme,\n isTripleSlashed,\n queryParams,\n path,\n preferLocalhost,\n useProxy,\n}: AuthSessionRedirectUriOptions = {}): string {\n if (\n Platform.OS !== 'web' &&\n native &&\n [ExecutionEnvironment.Standalone, ExecutionEnvironment.Bare].includes(\n Constants.executionEnvironment\n )\n ) {\n // Should use the user-defined native scheme in standalone builds\n return native;\n }\n if (!useProxy || Platform.OS === 'web') {\n const url = Linking.createURL(path || '', {\n isTripleSlashed,\n scheme,\n queryParams,\n });\n\n if (preferLocalhost) {\n const ipAddress = url.match(\n /\\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/\n );\n // Only replace if an IP address exists\n if (ipAddress?.length) {\n const [protocol, path] = url.split(ipAddress[0]);\n return `${protocol}localhost${path}`;\n }\n }\n\n return url;\n }\n // Attempt to use the proxy\n return sessionUrlProvider.getRedirectUrl(path);\n}\n\n/**\n * Build an `AuthRequest` and load it before returning.\n *\n * @param config\n * @param issuerOrDiscovery\n */\nexport async function loadAsync(\n config: AuthRequestConfig,\n issuerOrDiscovery: IssuerOrDiscovery\n): Promise<AuthRequest> {\n const request = new AuthRequest(config);\n const discovery = await resolveDiscoveryAsync(issuerOrDiscovery);\n await request.makeAuthUrlAsync(discovery);\n return request;\n}\n\nasync function _openWebBrowserAsync(startUrl: string, returnUrl: string, showInRecents: boolean) {\n // $FlowIssue: Flow thinks the awaited result can be a promise\n const result = await openAuthSessionAsync(startUrl, returnUrl, { showInRecents });\n if (result.type === 'cancel' || result.type === 'dismiss') {\n return { type: result.type };\n }\n\n return result;\n}\n\nexport { useAutoDiscovery, useAuthRequest } from './AuthRequestHooks';\nexport { AuthError, TokenError } from './Errors';\n\nexport {\n AuthSessionOptions,\n AuthSessionRedirectUriOptions,\n AuthSessionResult,\n AuthRequest,\n AuthRequestConfig,\n AuthRequestPromptOptions,\n CodeChallengeMethod,\n DiscoveryDocument,\n Issuer,\n IssuerOrDiscovery,\n Prompt,\n ProviderMetadata,\n ResponseType,\n resolveDiscoveryAsync,\n fetchDiscoveryAsync,\n generateHexStringAsync,\n};\n\nexport {\n // Token classes\n TokenResponse,\n AccessTokenRequest,\n RefreshTokenRequest,\n RevokeTokenRequest,\n // Token methods\n revokeAsync,\n refreshAsync,\n exchangeCodeAsync,\n fetchUserInfoAsync,\n} from './TokenRequest';\n\n// Token types\nexport * from './TokenRequest.types';\n"]}
package/build/Errors.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CodedError } from '@unimodules/core';
1
+ import { CodedError } from 'expo-modules-core';
2
2
  /**
3
3
  * Server response error.
4
4
  */
package/build/Errors.js CHANGED
@@ -1,4 +1,4 @@
1
- import { CodedError } from '@unimodules/core';
1
+ import { CodedError } from 'expo-modules-core';
2
2
  const errorCodeMessages = {
3
3
  // https://tools.ietf.org/html/rfc6749#section-4.1.2.1
4
4
  // https://openid.net/specs/openid-connect-core-1_0.html#AuthError
@@ -35,6 +35,21 @@ const errorCodeMessages = {
35
35
  * [Section 4.1.2.1](https://tools.ietf.org/html/rfc6749#section-4.1.2.1)
36
36
  */
37
37
  export class ResponseError extends CodedError {
38
+ /**
39
+ * Used to assist the client developer in
40
+ * understanding the error that occurred.
41
+ */
42
+ description;
43
+ /**
44
+ * A URI identifying a human-readable web page with
45
+ * information about the error, used to provide the client
46
+ * developer with additional information about the error.
47
+ */
48
+ uri;
49
+ /**
50
+ * Raw results of the error.
51
+ */
52
+ params;
38
53
  constructor(params, errorCodeType) {
39
54
  const { error, error_description, error_uri } = params;
40
55
  const message = errorCodeMessages[errorCodeType][error];
@@ -58,6 +73,10 @@ export class ResponseError extends CodedError {
58
73
  * [Section 5.2](https://tools.ietf.org/html/rfc6749#section-5.2)
59
74
  */
60
75
  export class AuthError extends ResponseError {
76
+ /**
77
+ * Required only if state is used in the initial request
78
+ */
79
+ state;
61
80
  constructor(response) {
62
81
  super(response, 'auth');
63
82
  this.state = response.state;
@@ -1 +1 @@
1
- {"version":3,"file":"Errors.js","sourceRoot":"","sources":["../src/Errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AA2B9C,MAAM,iBAAiB,GAAG;IACxB,sDAAsD;IACtD,kEAAkE;IAClE,IAAI,EAAE;QACJ,YAAY;QACZ,eAAe,EAAE,mJAAmJ;QACpK,mBAAmB,EAAE,kFAAkF;QACvG,aAAa,EAAE,gEAAgE;QAC/E,yBAAyB,EAAE,8FAA8F;QACzH,aAAa,EAAE,wDAAwD;QACvE,YAAY,EACV,qPAAqP;QACvP,uBAAuB,EACrB,wQAAwQ;QAC1Q,8BAA8B;QAC9B,oBAAoB,EAClB,2PAA2P;QAC7P,cAAc,EACZ,yOAAyO;QAC3O,0BAA0B,EACxB,6XAA6X;QAC/X,gBAAgB,EACd,2NAA2N;QAC7N,mBAAmB,EACjB,kFAAkF;QACpF,sBAAsB,EAAE,2DAA2D;QACnF,qBAAqB,EACnB,kJAAkJ;QACpJ,yBAAyB,EACvB,sJAAsJ;QACxJ,0BAA0B,EACxB,qKAAqK;KACxK;IACD,kDAAkD;IAClD,KAAK,EAAE;QACL,eAAe,EAAE,8PAA8P;QAC/Q,cAAc,EAAE,iiBAAiiB;QACjjB,aAAa,EAAE,+OAA+O;QAC9P,mBAAmB,EAAE,kFAAkF;QACvG,sBAAsB,EAAE,4EAA4E;KACrG;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,UAAU;IAiB3C,YAAY,MAA2B,EAAE,aAAqB;QAC5D,MAAM,EAAE,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;QACvD,MAAM,OAAO,GAAG,iBAAiB,CAAC,aAAa,CAAC,CAAC,KAAK,CAAC,CAAC;QACxD,IAAI,YAAoB,CAAC;QACzB,IAAI,OAAO,EAAE;YACX,YAAY,GAAG,OAAO,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,gBAAgB,iBAAiB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;SACzF;aAAM,IAAI,iBAAiB,EAAE;YAC5B,YAAY,GAAG,iBAAiB,CAAC;SAClC;aAAM;YACL,YAAY,GAAG,2BAA2B,CAAC;SAC5C;QACD,KAAK,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;QAC3B,IAAI,CAAC,WAAW,GAAG,iBAAiB,IAAI,OAAO,CAAC;QAChD,IAAI,CAAC,GAAG,GAAG,SAAS,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,aAAa;IAM1C,YAAY,QAAyB;QACnC,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;IAC9B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,aAAa;IAC3C,YAAY,QAA6B;QACvC,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC3B,CAAC;CACF","sourcesContent":["import { CodedError } from '@unimodules/core';\n\n/**\n * Server response error.\n */\nexport interface ResponseErrorConfig extends Record<string, any> {\n /**\n * Error code\n */\n error: string;\n /**\n * Additional message\n */\n error_description?: string;\n /**\n * URI for more info on the error\n */\n error_uri?: string;\n}\n\nexport interface AuthErrorConfig extends ResponseErrorConfig {\n /**\n * Required only if state is used in the initial request\n */\n state?: string;\n}\n\nconst errorCodeMessages = {\n // https://tools.ietf.org/html/rfc6749#section-4.1.2.1\n // https://openid.net/specs/openid-connect-core-1_0.html#AuthError\n auth: {\n // OAuth 2.0\n invalid_request: `The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed.`,\n unauthorized_client: `The client is not authorized to request an authorization code using this method.`,\n access_denied: `The resource owner or authorization server denied the request.`,\n unsupported_response_type: `The authorization server does not support obtaining an authorization code using this method.`,\n invalid_scope: 'The requested scope is invalid, unknown, or malformed.',\n server_error:\n 'The authorization server encountered an unexpected condition that prevented it from fulfilling the request. (This error code is needed because a 500 Internal Server Error HTTP status code cannot be returned to the client via an HTTP redirect.)',\n temporarily_unavailable:\n 'The authorization server is currently unable to handle the request due to a temporary overloading or maintenance of the server. (This error code is needed because a 503 Service Unavailable HTTP status code cannot be returned to the client via an HTTP redirect.)',\n // Open ID Connect error codes\n interaction_required:\n 'Auth server requires user interaction of some form to proceed. This error may be returned when the prompt parameter value in the auth request is none, but the auth request cannot be completed without displaying a user interface for user interaction.',\n login_required:\n 'Auth server requires user authentication. This error may be returned when the prompt parameter value in the auth request is none, but the auth request cannot be completed without displaying a user interface for user authentication.',\n account_selection_required:\n 'User is required to select a session at the auth server. The user may be authenticated at the auth server with different associated accounts, but the user did not select a session. This error may be returned when the prompt parameter value in the auth request is `none`, but the auth request cannot be completed without displaying a user interface to prompt for a session to use.',\n consent_required:\n 'Auth server requires user consent. This error may be returned when the prompt parameter value in the auth request is none, but the auth request cannot be completed without displaying a user interface for user consent.',\n invalid_request_uri:\n 'The `request_uri` in the auth request returns an error or contains invalid data.',\n invalid_request_object: 'The request parameter contains an invalid request object.',\n request_not_supported:\n 'The OP does not support use of the `request` parameter defined in Section 6. (https://openid.net/specs/openid-connect-core-1_0.html#JWTRequests)',\n request_uri_not_supported:\n 'The OP does not support use of the `request_uri` parameter defined in Section 6. (https://openid.net/specs/openid-connect-core-1_0.html#JWTRequests)',\n registration_not_supported:\n 'The OP does not support use of the `registration` parameter defined in Section 7.2.1. (https://openid.net/specs/openid-connect-core-1_0.html#RegistrationParameter)',\n },\n // https://tools.ietf.org/html/rfc6749#section-5.2\n token: {\n 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.`,\n invalid_client: `Client authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method). The authorization server MAY return an HTTP 401 (Unauthorized) status code to indicate which HTTP authentication schemes are supported. If the client attempted to authenticate via the \"Authorization\" request header field, the authorization server MUST respond with an HTTP 401 (Unauthorized) status code and include the \"WWW-Authenticate\" response header field matching the authentication scheme used by the client.`,\n 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.`,\n unauthorized_client: `The authenticated client is not authorized to use this authorization grant type.`,\n unsupported_grant_type: `The authorization grant type is not supported by the authorization server.`,\n },\n};\n\n/**\n * [Section 4.1.2.1](https://tools.ietf.org/html/rfc6749#section-4.1.2.1)\n */\nexport class ResponseError extends CodedError {\n /**\n * Used to assist the client developer in\n * understanding the error that occurred.\n */\n description?: string;\n /**\n * A URI identifying a human-readable web page with\n * information about the error, used to provide the client\n * developer with additional information about the error.\n */\n uri?: string;\n /**\n * Raw results of the error.\n */\n params: Record<string, string>;\n\n constructor(params: ResponseErrorConfig, errorCodeType: string) {\n const { error, error_description, error_uri } = params;\n const message = errorCodeMessages[errorCodeType][error];\n let errorMessage: string;\n if (message) {\n errorMessage = message + (error_description ? `\\nMore info: ${error_description}` : '');\n } else if (error_description) {\n errorMessage = error_description;\n } else {\n errorMessage = 'An unknown error occurred';\n }\n super(error, errorMessage);\n this.description = error_description ?? message;\n this.uri = error_uri;\n this.params = params;\n }\n}\n\n/**\n * [Section 5.2](https://tools.ietf.org/html/rfc6749#section-5.2)\n */\nexport class AuthError extends ResponseError {\n /**\n * Required only if state is used in the initial request\n */\n state?: string;\n\n constructor(response: AuthErrorConfig) {\n super(response, 'auth');\n this.state = response.state;\n }\n}\n\n/**\n * [Section 4.1.2.1](https://tools.ietf.org/html/rfc6749#section-4.1.2.1)\n */\nexport class TokenError extends ResponseError {\n constructor(response: ResponseErrorCon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C,CAAC;QACxD,IAAI,YAAoB,CAAC;QACzB,IAAI,OAAO,EAAE;YACX,YAAY,GAAG,OAAO,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,gBAAgB,iBAAiB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;SACzF;aAAM,IAAI,iBAAiB,EAAE;YAC5B,YAAY,GAAG,iBAAiB,CAAC;SAClC;aAAM;YACL,YAAY,GAAG,2BAA2B,CAAC;SAC5C;QACD,KAAK,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;QAC3B,IAAI,CAAC,WAAW,GAAG,iBAAiB,IAAI,OAAO,CAAC;QAChD,IAAI,CAAC,GAAG,GAAG,SAAS,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,aAAa;IAC1C;;OAEG;IACH,KAAK,CAAU;IAEf,YAAY,QAAyB;QACnC,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;IAC9B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,aAAa;IAC3C,YAAY,QAA6B;QACvC,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC3B,CAAC;CACF","sourcesContent":["import { CodedError } from 'expo-modules-core';\n\n/**\n * Server response error.\n */\nexport interface ResponseErrorConfig extends Record<string, any> {\n /**\n * Error code\n */\n error: string;\n /**\n * Additional message\n */\n error_description?: string;\n /**\n * URI for more info on the error\n */\n error_uri?: string;\n}\n\nexport interface AuthErrorConfig extends ResponseErrorConfig {\n /**\n * Required only if state is used in the initial request\n */\n state?: string;\n}\n\nconst errorCodeMessages = {\n // https://tools.ietf.org/html/rfc6749#section-4.1.2.1\n // https://openid.net/specs/openid-connect-core-1_0.html#AuthError\n auth: {\n // OAuth 2.0\n invalid_request: `The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed.`,\n unauthorized_client: `The client is not authorized to request an authorization code using this method.`,\n access_denied: `The resource owner or authorization server denied the request.`,\n unsupported_response_type: `The authorization server does not support obtaining an authorization code using this method.`,\n invalid_scope: 'The requested scope is invalid, unknown, or malformed.',\n server_error:\n 'The authorization server encountered an unexpected condition that prevented it from fulfilling the request. (This error code is needed because a 500 Internal Server Error HTTP status code cannot be returned to the client via an HTTP redirect.)',\n temporarily_unavailable:\n 'The authorization server is currently unable to handle the request due to a temporary overloading or maintenance of the server. (This error code is needed because a 503 Service Unavailable HTTP status code cannot be returned to the client via an HTTP redirect.)',\n // Open ID Connect error codes\n interaction_required:\n 'Auth server requires user interaction of some form to proceed. This error may be returned when the prompt parameter value in the auth request is none, but the auth request cannot be completed without displaying a user interface for user interaction.',\n login_required:\n 'Auth server requires user authentication. This error may be returned when the prompt parameter value in the auth request is none, but the auth request cannot be completed without displaying a user interface for user authentication.',\n account_selection_required:\n 'User is required to select a session at the auth server. The user may be authenticated at the auth server with different associated accounts, but the user did not select a session. This error may be returned when the prompt parameter value in the auth request is `none`, but the auth request cannot be completed without displaying a user interface to prompt for a session to use.',\n consent_required:\n 'Auth server requires user consent. This error may be returned when the prompt parameter value in the auth request is none, but the auth request cannot be completed without displaying a user interface for user consent.',\n invalid_request_uri:\n 'The `request_uri` in the auth request returns an error or contains invalid data.',\n invalid_request_object: 'The request parameter contains an invalid request object.',\n request_not_supported:\n 'The OP does not support use of the `request` parameter defined in Section 6. (https://openid.net/specs/openid-connect-core-1_0.html#JWTRequests)',\n request_uri_not_supported:\n 'The OP does not support use of the `request_uri` parameter defined in Section 6. (https://openid.net/specs/openid-connect-core-1_0.html#JWTRequests)',\n registration_not_supported:\n 'The OP does not support use of the `registration` parameter defined in Section 7.2.1. (https://openid.net/specs/openid-connect-core-1_0.html#RegistrationParameter)',\n },\n // https://tools.ietf.org/html/rfc6749#section-5.2\n token: {\n 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.`,\n invalid_client: `Client authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method). The authorization server MAY return an HTTP 401 (Unauthorized) status code to indicate which HTTP authentication schemes are supported. If the client attempted to authenticate via the \"Authorization\" request header field, the authorization server MUST respond with an HTTP 401 (Unauthorized) status code and include the \"WWW-Authenticate\" response header field matching the authentication scheme used by the client.`,\n 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.`,\n unauthorized_client: `The authenticated client is not authorized to use this authorization grant type.`,\n unsupported_grant_type: `The authorization grant type is not supported by the authorization server.`,\n },\n};\n\n/**\n * [Section 4.1.2.1](https://tools.ietf.org/html/rfc6749#section-4.1.2.1)\n */\nexport class ResponseError extends CodedError {\n /**\n * Used to assist the client developer in\n * understanding the error that occurred.\n */\n description?: string;\n /**\n * A URI identifying a human-readable web page with\n * information about the error, used to provide the client\n * developer with additional information about the error.\n */\n uri?: string;\n /**\n * Raw results of the error.\n */\n params: Record<string, string>;\n\n constructor(params: ResponseErrorConfig, errorCodeType: string) {\n const { error, error_description, error_uri } = params;\n const message = errorCodeMessages[errorCodeType][error];\n let errorMessage: string;\n if (message) {\n errorMessage = message + (error_description ? `\\nMore info: ${error_description}` : '');\n } else if (error_description) {\n errorMessage = error_description;\n } else {\n errorMessage = 'An unknown error occurred';\n }\n super(error, errorMessage);\n this.description = error_description ?? message;\n this.uri = error_uri;\n this.params = params;\n }\n}\n\n/**\n * [Section 5.2](https://tools.ietf.org/html/rfc6749#section-5.2)\n */\nexport class AuthError extends ResponseError {\n /**\n * Required only if state is used in the initial request\n */\n state?: string;\n\n constructor(response: AuthErrorConfig) {\n super(response, 'auth');\n this.state = response.state;\n }\n}\n\n/**\n * [Section 4.1.2.1](https://tools.ietf.org/html/rfc6749#section-4.1.2.1)\n */\nexport class TokenError extends ResponseError {\n constructor(response: ResponseErrorConfig) {\n super(response, 'token');\n }\n}\n"]}
package/build/Fetch.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Platform } from '@unimodules/core';
1
+ import { Platform } from 'expo-modules-core';
2
2
  import qs from 'qs';
3
3
  // TODO(Bacon): pending react-native-adapter publish after sdk 38
4
4
  const isDOMAvailable = Platform.OS === 'web' &&
@@ -1 +1 @@
1
- {"version":3,"file":"Fetch.js","sourceRoot":"","sources":["../src/Fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,MAAM,IAAI,CAAC;AAepB,iEAAiE;AACjE,MAAM,cAAc,GAClB,QAAQ,CAAC,EAAE,KAAK,KAAK;IACrB,OAAO,MAAM,KAAK,WAAW;IAC7B,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,aAAa;IAChC,oCAAoC;IACpC,OAAO,GAAG,KAAK,WAAW,CAAC;AAE7B,MAAM,CAAC,KAAK,UAAU,YAAY,CAAI,UAAkB,EAAE,YAA0B;IAClF,IAAI,QAAQ,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC,cAAc,EAAE;QAC5C,aAAa;QACb,OAAO;KACR;IACD,oCAAoC;IACpC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC;IAEhC,MAAM,OAAO,GAA4D;QACvE,MAAM,EAAE,YAAY,CAAC,MAAM;QAC3B,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,EAAE;KACZ,CAAC;IAEF,MAAM,cAAc,GAAG,YAAY,CAAC,QAAQ,EAAE,WAAW,EAAE,KAAK,MAAM,CAAC;IAEvE,IAAI,YAAY,CAAC,OAAO,EAAE;QACxB,KAAK,MAAM,CAAC,IAAI,YAAY,CAAC,OAAO,EAAE;YACpC,IAAI,CAAC,IAAI,YAAY,CAAC,OAAO,EAAE;gBAC7B,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC,CAAW,CAAC;aACxD;SACF;KACF;IAED,IAAI,YAAY,CAAC,IAAI,EAAE;QACrB,IAAI,YAAY,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,MAAM,EAAE;YACjD,OAAO,CAAC,IAAI,GAAG,EAAE,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;SAChD;aAAM;YACL,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE;gBAChD,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,EAAE,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;aACtD;SACF;KACF;IAED,IAAI,cAAc,IAAI,CAAC,CAAC,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;QACpD,kFAAkF;QAClF,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,2CAA2C,CAAC;KACzE;IAED,8EAA8E;IAC9E,MAAM,YAAY,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAEvD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAEpD,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACzD,IAAI,cAAc,IAAI,WAAW,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EAAE;QAC/D,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;KACxB;IACD,2DAA2D;IAC3D,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;AACzB,CAAC","sourcesContent":["import { Platform } from '@unimodules/core';\nimport qs from 'qs';\n\nexport type Headers = Record<string, string> & {\n 'Content-Type': string;\n Authorization?: string;\n Accept?: string;\n};\n\nexport type FetchRequest = {\n headers?: Headers;\n body?: Record<string, string>;\n dataType?: string;\n method?: string;\n};\n\n// TODO(Bacon): pending react-native-adapter publish after sdk 38\nconst isDOMAvailable =\n Platform.OS === 'web' &&\n typeof window !== 'undefined' &&\n !!window.document?.createElement &&\n // eslint-disable-next-line no-undef\n typeof URL !== 'undefined';\n\nexport async function requestAsync<T>(requestUrl: string, fetchRequest: FetchRequest): Promise<T> {\n if (Platform.OS === 'web' && !isDOMAvailable) {\n // @ts-ignore\n return;\n }\n // eslint-disable-next-line no-undef\n const url = new URL(requestUrl);\n\n const request: Omit<RequestInit, 'headers'> & { headers: HeadersInit } = {\n method: fetchRequest.method,\n mode: 'cors',\n headers: {},\n };\n\n const isJsonDataType = fetchRequest.dataType?.toLowerCase() === 'json';\n\n if (fetchRequest.headers) {\n for (const i in fetchRequest.headers) {\n if (i in fetchRequest.headers) {\n request.headers[i] = fetchRequest.headers[i] as string;\n }\n }\n }\n\n if (fetchRequest.body) {\n if (fetchRequest.method?.toUpperCase() === 'POST') {\n request.body = qs.stringify(fetchRequest.body);\n } else {\n for (const key of Object.keys(fetchRequest.body)) {\n url.searchParams.append(key, fetchRequest.body[key]);\n }\n }\n }\n\n if (isJsonDataType && !('Accept' in request.headers)) {\n // NOTE: Github authentication will return XML if this includes the standard `*/*`\n request.headers['Accept'] = 'application/json, text/javascript; q=0.01';\n }\n\n // Fix a problem with React Native `URL` causing a trailing slash to be added.\n const correctedUrl = url.toString().replace(/\\/$/, '');\n\n const response = await fetch(correctedUrl, request);\n\n const contentType = response.headers.get('content-type');\n if (isJsonDataType || contentType?.includes('application/json')) {\n return response.json();\n }\n // @ts-ignore: Type 'string' is not assignable to type 'T'.\n return response.text();\n}\n"]}
1
+ {"version":3,"file":"Fetch.js","sourceRoot":"","sources":["../src/Fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,MAAM,IAAI,CAAC;AAepB,iEAAiE;AACjE,MAAM,cAAc,GA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C;aACtD;SACF;KACF;IAED,IAAI,cAAc,IAAI,CAAC,CAAC,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;QACpD,kFAAkF;QAClF,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,2CAA2C,CAAC;KACzE;IAED,8EAA8E;IAC9E,MAAM,YAAY,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAEvD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAEpD,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACzD,IAAI,cAAc,IAAI,WAAW,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EAAE;QAC/D,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;KACxB;IACD,2DAA2D;IAC3D,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;AACzB,CAAC","sourcesContent":["import { Platform } from 'expo-modules-core';\nimport qs from 'qs';\n\nexport type Headers = Record<string, string> & {\n 'Content-Type': string;\n Authorization?: string;\n Accept?: string;\n};\n\nexport type FetchRequest = {\n headers?: Headers;\n body?: Record<string, string>;\n dataType?: string;\n method?: string;\n};\n\n// TODO(Bacon): pending react-native-adapter publish after sdk 38\nconst isDOMAvailable =\n Platform.OS === 'web' &&\n typeof window !== 'undefined' &&\n !!window.document?.createElement &&\n // eslint-disable-next-line no-undef\n typeof URL !== 'undefined';\n\nexport async function requestAsync<T>(requestUrl: string, fetchRequest: FetchRequest): Promise<T> {\n if (Platform.OS === 'web' && !isDOMAvailable) {\n // @ts-ignore\n return;\n }\n // eslint-disable-next-line no-undef\n const url = new URL(requestUrl);\n\n const request: Omit<RequestInit, 'headers'> & { headers: HeadersInit } = {\n method: fetchRequest.method,\n mode: 'cors',\n headers: {},\n };\n\n const isJsonDataType = fetchRequest.dataType?.toLowerCase() === 'json';\n\n if (fetchRequest.headers) {\n for (const i in fetchRequest.headers) {\n if (i in fetchRequest.headers) {\n request.headers[i] = fetchRequest.headers[i] as string;\n }\n }\n }\n\n if (fetchRequest.body) {\n if (fetchRequest.method?.toUpperCase() === 'POST') {\n request.body = qs.stringify(fetchRequest.body);\n } else {\n for (const key of Object.keys(fetchRequest.body)) {\n url.searchParams.append(key, fetchRequest.body[key]);\n }\n }\n }\n\n if (isJsonDataType && !('Accept' in request.headers)) {\n // NOTE: Github authentication will return XML if this includes the standard `*/*`\n request.headers['Accept'] = 'application/json, text/javascript; q=0.01';\n }\n\n // Fix a problem with React Native `URL` causing a trailing slash to be added.\n const correctedUrl = url.toString().replace(/\\/$/, '');\n\n const response = await fetch(correctedUrl, request);\n\n const contentType = response.headers.get('content-type');\n if (isJsonDataType || contentType?.includes('application/json')) {\n return response.json();\n }\n // @ts-ignore: Type 'string' is not assignable to type 'T'.\n return response.text();\n}\n"]}
package/build/PKCE.js CHANGED
@@ -21,10 +21,7 @@ function convertBufferToString(buffer) {
21
21
  return state.join('');
22
22
  }
23
23
  function convertToUrlSafeString(b64) {
24
- return b64
25
- .replace(/\+/g, '-')
26
- .replace(/\//g, '_')
27
- .replace(/=/g, '');
24
+ return b64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
28
25
  }
29
26
  export function generateRandom(size) {
30
27
  const buffer = new Uint8Array(size);
package/build/PKCE.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"PKCE.js","sourceRoot":"","sources":["../src/PKCE.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,MAAM,OAAO,GAAG,gEAAgE,CAAC;AAEjF,SAAS,eAAe,CAAC,KAAiB;IACxC,MAAM,MAAM,GAAG,KAAK,CAAC;IACrB,yCAAyC;IACzC,IAAI,KAAK,CA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S,CAAC,IAAI,CAAC,MAAM,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,GAAG,GAAG,EAAE,+BAA+B,CAAC,CAAC;IAElF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAAC,qBAAqB,CAAC,MAAM,EAAE,IAAI,EAAE;QACvF,QAAQ,EAAE,MAAM,CAAC,cAAc,CAAC,MAAM;KACvC,CAAC,CAAC;IACH,OAAO,sBAAsB,CAAC,MAAM,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAAe,GAAG;IAElB,kEAAkE;IAClE,MAAM,YAAY,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IAC1C,MAAM,aAAa,GAAG,MAAM,oBAAoB,CAAC,YAAY,CAAC,CAAC;IAE/D,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,CAAC;AACzC,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,IAAY;IACvD,MAAM,KAAK,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IACnC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAAC,qBAAqB,CAAC,MAAM,EAAE,KAAK,EAAE;QACxF,QAAQ,EAAE,MAAM,CAAC,cAAc,CAAC,GAAG;KACpC,CAAC,CAAC;IACH,OAAO,sBAAsB,CAAC,MAAM,CAAC,CAAC;AACxC,CAAC","sourcesContent":["import * as Crypto from 'expo-crypto';\nimport * as Random from 'expo-random';\nimport invariant from 'invariant';\n\nconst CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\n\nfunction getRandomValues(input: Uint8Array): Uint8Array {\n const output = input;\n // Get access to the underlying raw bytes\n if (input.byteLength !== input.length) input = new Uint8Array(input.buffer);\n\n const bytes = Random.getRandomBytes(input.length);\n\n for (let i = 0; i < bytes.length; i++) input[i] = bytes[i];\n\n return output;\n}\n\nfunction convertBufferToString(buffer: Uint8Array): string {\n const state: string[] = [];\n for (let i = 0; i < buffer.byteLength; i += 1) {\n const index = buffer[i] % CHARSET.length;\n state.push(CHARSET[index]);\n }\n return state.join('');\n}\n\nfunction convertToUrlSafeString(b64: string): string {\n return b64\n .replace(/\\+/g, '-')\n .replace(/\\//g, '_')\n .replace(/=/g, '');\n}\n\nexport function generateRandom(size: number): string {\n const buffer = new Uint8Array(size);\n getRandomValues(buffer);\n return convertBufferToString(buffer);\n}\n\n/**\n * Proof key for Code Exchange by OAuth Public Clients (RFC 7636), Section 4.1\n * [Section 4.1](https://tools.ietf.org/html/rfc7636#section-4.1)\n */\nexport async function deriveChallengeAsync(code: string): Promise<string> {\n // 43 is the minimum, and 128 is the maximum.\n invariant(code.length > 42 && code.length < 129, 'Invalid code length for PKCE.');\n\n const buffer = await Crypto.digestStringAsync(Crypto.CryptoDigestAlgorithm.SHA256, code, {\n encoding: Crypto.CryptoEncoding.BASE64,\n });\n return convertToUrlSafeString(buffer);\n}\n\nexport async function buildCodeAsync(\n size: number = 128\n): Promise<{ codeChallenge: string; codeVerifier: string }> {\n // This method needs to be resolved like all other native methods.\n const codeVerifier = generateRandom(size);\n const codeChallenge = await deriveChallengeAsync(codeVerifier);\n\n return { codeVerifier, codeChallenge };\n}\n\n/**\n * Digest a random string with hex encoding, useful for creating `nonce`s.\n */\nexport async function generateHexStringAsync(size: number): Promise<string> {\n const value = generateRandom(size);\n const buffer = await Crypto.digestStringAsync(Crypto.CryptoDigestAlgorithm.SHA256, value, {\n encoding: Crypto.CryptoEncoding.HEX,\n });\n return convertToUrlSafeString(buffer);\n}\n"]}
1
+ {"version":3,"file":"PKCE.js","sourceRoot":"","sources":["../src/PKCE.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,SAAS,MAAM,WAAW,CAAC;AAEl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,OAAO,qBAAqB,CAAC,MAAM,CAAC,CAAC;AACvC,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,IAAY;IACrD,6CAA6C;IAC7C,SAAS,CAAC,IAAI,CAAC,MAAM,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,GAAG,GAAG,EAAE,+BAA+B,CAAC,CAAC;IAElF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAAC,qBAAqB,CAAC,MAAM,EAAE,IAAI,EAAE;QACvF,QAAQ,EAAE,MAAM,CAAC,cAAc,CAAC,MAAM;KACvC,CAAC,CAAC;IACH,OAAO,sBAAsB,CAAC,MAAM,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAAe,GAAG;IAElB,kEAAkE;IAClE,MAAM,YAAY,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IAC1C,MAAM,aAAa,GAAG,MAAM,oBAAoB,CAAC,YAAY,CAAC,CAAC;IAE/D,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,CAAC;AACzC,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,IAAY;IACvD,MAAM,KAAK,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IACnC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAAC,qBAAqB,CAAC,MAAM,EAAE,KAAK,EAAE;QACxF,QAAQ,EAAE,MAAM,CAAC,cAAc,CAAC,GAAG;KACpC,CAAC,CAAC;IACH,OAAO,sBAAsB,CAAC,MAAM,CAAC,CAAC;AACxC,CAAC","sourcesContent":["import * as Crypto from 'expo-crypto';\nimport * as Random from 'expo-random';\nimport invariant from 'invariant';\n\nconst CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\n\nfunction getRandomValues(input: Uint8Array): Uint8Array {\n const output = input;\n // Get access to the underlying raw bytes\n if (input.byteLength !== input.length) input = new Uint8Array(input.buffer);\n\n const bytes = Random.getRandomBytes(input.length);\n\n for (let i = 0; i < bytes.length; i++) input[i] = bytes[i];\n\n return output;\n}\n\nfunction convertBufferToString(buffer: Uint8Array): string {\n const state: string[] = [];\n for (let i = 0; i < buffer.byteLength; i += 1) {\n const index = buffer[i] % CHARSET.length;\n state.push(CHARSET[index]);\n }\n return state.join('');\n}\n\nfunction convertToUrlSafeString(b64: string): string {\n return b64.replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=/g, '');\n}\n\nexport function generateRandom(size: number): string {\n const buffer = new Uint8Array(size);\n getRandomValues(buffer);\n return convertBufferToString(buffer);\n}\n\n/**\n * Proof key for Code Exchange by OAuth Public Clients (RFC 7636), Section 4.1\n * [Section 4.1](https://tools.ietf.org/html/rfc7636#section-4.1)\n */\nexport async function deriveChallengeAsync(code: string): Promise<string> {\n // 43 is the minimum, and 128 is the maximum.\n invariant(code.length > 42 && code.length < 129, 'Invalid code length for PKCE.');\n\n const buffer = await Crypto.digestStringAsync(Crypto.CryptoDigestAlgorithm.SHA256, code, {\n encoding: Crypto.CryptoEncoding.BASE64,\n });\n return convertToUrlSafeString(buffer);\n}\n\nexport async function buildCodeAsync(\n size: number = 128\n): Promise<{ codeChallenge: string; codeVerifier: string }> {\n // This method needs to be resolved like all other native methods.\n const codeVerifier = generateRandom(size);\n const codeChallenge = await deriveChallengeAsync(codeVerifier);\n\n return { codeVerifier, codeChallenge };\n}\n\n/**\n * Digest a random string with hex encoding, useful for creating `nonce`s.\n */\nexport async function generateHexStringAsync(size: number): Promise<string> {\n const value = generateRandom(size);\n const buffer = await Crypto.digestStringAsync(Crypto.CryptoDigestAlgorithm.SHA256, value, {\n encoding: Crypto.CryptoEncoding.HEX,\n });\n return convertToUrlSafeString(buffer);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"QueryParams.js","sourceRoot":"","sources":["../src/QueryParams.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,MAAM,UAAU,gBAAgB,CAAC,KAA6B;IAC5D,OAAO,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,GAAW;IAEX,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7B,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IACtB,MAAM,gBAAgB,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7C,MAAM,WAAW,GAAG,gBAAgB,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAElE,kCAAkC;IAClC,MAAM,YAAY,GAAG,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC;IAEnE,+BAA+B;IAC/B,MAAM,SAAS,GAAG,CAAC,YAAY,CAAC,SAAS,IAAI,IAAI,CAAkB,CAAC;IACpE,SAAS,CACP,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,IAAI,EACnD,yDAAyD,CAC1D,CAAC;IACF,OAAO,YAAY,CAAC,SAAS,CAAC;IAE9B,0BAA0B;IAC1B,IAAI,UAAU,GAAG,EAAE,CAAC;IACpB,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE;QACZ,UAAU,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;KAC7B;IAED,wBAAwB;IACxB,MAAM,MAAM,GAAG;QACb,GAAG,YAAY;QACf,GAAG,UAAU;KACd,CAAC;IAEF,OAAO;QACL,SAAS;QACT,MAAM;KACP,CAAC;AACJ,CAAC","sourcesContent":["import invariant from 'invariant';\nimport qs from 'qs';\n\nexport function buildQueryString(input: Record<string, string>): string {\n return qs.stringify(input);\n}\n\nexport function getQueryParams(\n url: string\n): { errorCode: string | null; params: { [key: string]: string } } {\n const parts = url.split('#');\n const hash = parts[1];\n const partsWithoutHash = parts[0].split('?');\n const queryString = partsWithoutHash[partsWithoutHash.length - 1];\n\n // Get query string (?hello=world)\n const parsedSearch = qs.parse(queryString, { parseArrays: false });\n\n // Pull errorCode off of params\n const errorCode = (parsedSearch.errorCode ?? null) as string | null;\n invariant(\n typeof errorCode === 'string' || errorCode === null,\n `The \"errorCode\" parameter must be a string if specified`\n );\n delete parsedSearch.errorCode;\n\n // Get hash (#abc=example)\n let parsedHash = {};\n if (parts[1]) {\n parsedHash = qs.parse(hash);\n }\n\n // Merge search and hash\n const params = {\n ...parsedSearch,\n ...parsedHash,\n };\n\n return {\n errorCode,\n params,\n };\n}\n"]}
1
+ {"version":3,"file":"QueryParams.js","sourceRoot":"","sources":["../src/QueryParams.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,MAAM,UAAU,gBAAgB,CAAC,KAA6B;IAC5D,OAAO,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,GAAW;IAIxC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7B,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IACtB,MAAM,gBAAgB,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7C,MAAM,WAAW,GAAG,gBAAgB,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAElE,kCAAkC;IAClC,MAAM,YAAY,GAAG,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC;IAEnE,+BAA+B;IAC/B,MAAM,SAAS,GAAG,CAAC,YAAY,CAAC,SAAS,IAAI,IAAI,CAAkB,CAAC;IACpE,SAAS,CACP,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,IAAI,EACnD,yDAAyD,CAC1D,CAAC;IACF,OAAO,YAAY,CAAC,SAAS,CAAC;IAE9B,0BAA0B;IAC1B,IAAI,UAAU,GAAG,EAAE,CAAC;IACpB,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE;QACZ,UAAU,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;KAC7B;IAED,wBAAwB;IACxB,MAAM,MAAM,GAAG;QACb,GAAG,YAAY;QACf,GAAG,UAAU;KACd,CAAC;IAEF,OAAO;QACL,SAAS;QACT,MAAM;KACP,CAAC;AACJ,CAAC","sourcesContent":["import invariant from 'invariant';\nimport qs from 'qs';\n\nexport function buildQueryString(input: Record<string, string>): string {\n return qs.stringify(input);\n}\n\nexport function getQueryParams(url: string): {\n errorCode: string | null;\n params: { [key: string]: string };\n} {\n const parts = url.split('#');\n const hash = parts[1];\n const partsWithoutHash = parts[0].split('?');\n const queryString = partsWithoutHash[partsWithoutHash.length - 1];\n\n // Get query string (?hello=world)\n const parsedSearch = qs.parse(queryString, { parseArrays: false });\n\n // Pull errorCode off of params\n const errorCode = (parsedSearch.errorCode ?? null) as string | null;\n invariant(\n typeof errorCode === 'string' || errorCode === null,\n `The \"errorCode\" parameter must be a string if specified`\n );\n delete parsedSearch.errorCode;\n\n // Get hash (#abc=example)\n let parsedHash = {};\n if (parts[1]) {\n parsedHash = qs.parse(hash);\n }\n\n // Merge search and hash\n const params = {\n ...parsedSearch,\n ...parsedHash,\n };\n\n return {\n errorCode,\n params,\n };\n}\n"]}
@@ -3,8 +3,9 @@ import Constants, { ExecutionEnvironment } from 'expo-constants';
3
3
  import * as Linking from 'expo-linking';
4
4
  import { resolveScheme } from 'expo-linking/build/Schemes';
5
5
  import qs from 'qs';
6
- const { manifest } = Constants;
7
6
  export class SessionUrlProvider {
7
+ static BASE_URL = `https://auth.expo.io`;
8
+ static SESSION_PATH = 'expo-auth-session';
8
9
  getDefaultReturnUrl(urlPath, options) {
9
10
  const queryParams = SessionUrlProvider.getHostAddressQueryParams();
10
11
  let path = SessionUrlProvider.SESSION_PATH;
@@ -39,13 +40,15 @@ export class SessionUrlProvider {
39
40
  return '';
40
41
  }
41
42
  }
42
- const legacyExpoProjectId = manifest.currentFullName || manifest.id;
43
+ const legacyExpoProjectId = Constants.manifest?.originalFullName ||
44
+ Constants.manifest2?.extra?.expoClient?.originalFullName ||
45
+ Constants.manifest?.id;
43
46
  if (!legacyExpoProjectId) {
44
47
  let nextSteps = '';
45
48
  if (__DEV__) {
46
49
  if (Constants.executionEnvironment === ExecutionEnvironment.Bare) {
47
50
  nextSteps =
48
- ' Please ensure you have the latest version of expo-constants installed and rebuild your native app. You can verify that currentFullName is defined by running `expo config --type public` and inspecting the output.';
51
+ ' Please ensure you have the latest version of expo-constants installed and rebuild your native app. You can verify that originalFullName is defined by running `expo config --type public` and inspecting the output.';
49
52
  }
50
53
  else if (Constants.executionEnvironment === ExecutionEnvironment.StoreClient) {
51
54
  nextSteps =
@@ -62,7 +65,7 @@ export class SessionUrlProvider {
62
65
  return redirectUrl;
63
66
  }
64
67
  static getHostAddressQueryParams() {
65
- let hostUri = Constants.manifest?.hostUri;
68
+ let hostUri = Constants.manifest?.hostUri ?? Constants.manifest2?.extra?.expoClient?.hostUri;
66
69
  if (!hostUri &&
67
70
  (ExecutionEnvironment.StoreClient === Constants.executionEnvironment || resolveScheme({}))) {
68
71
  if (!Constants.linkingUri) {
@@ -74,6 +77,9 @@ export class SessionUrlProvider {
74
77
  hostUri = SessionUrlProvider.removeScheme(Constants.linkingUri).replace(/\/--(\/.*)?$/, '');
75
78
  }
76
79
  }
80
+ if (!hostUri) {
81
+ return undefined;
82
+ }
77
83
  const uriParts = hostUri?.split('?');
78
84
  try {
79
85
  return qs.parse(uriParts?.[1]);
@@ -93,7 +99,5 @@ export class SessionUrlProvider {
93
99
  return url.replace(/^\//, '');
94
100
  }
95
101
  }
96
- SessionUrlProvider.BASE_URL = `https://auth.expo.io`;
97
- SessionUrlProvider.SESSION_PATH = 'expo-auth-session';
98
102
  export default new SessionUrlProvider();
99
103
  //# sourceMappingURL=SessionUrlProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SessionUrlProvider.js","sourceRoot":"","sources":["../src/SessionUrlProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAC5D,OAAO,SAAS,EAAE,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAgB,MAAM,IAAI,CAAC;AAElC,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC;AAE/B,MAAM,OAAO,kBAAkB;IAI7B,mBAAmB,CAAC,OAAgB,EAAE,OAA+C;QACnF,MAAM,WAAW,GAAG,kBAAkB,CAAC,yBAAyB,EAAE,CAAC;QACnE,IAAI,IAAI,GAAG,kBAAkB,CAAC,YAAY,CAAC;QAC3C,IAAI,OAAO,EAAE;YACX,IAAI,GAAG,CAAC,IAAI,EAAE,kBAAkB,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SACzF;QAED,OAAO,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE;YAC7B,sGAAsG;YACtG,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,aAAa,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;YAC5D,WAAW;YACX,eAAe,EAAE,OAAO,EAAE,eAAe;SAC1C,CAAC,CAAC;IACL,CAAC;IAED,WAAW,CAAC,OAAe,EAAE,SAAiB;QAC5C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EAAE,CAAC","sourcesContent":["import { Platform } from '@unimodules/react-native-adapter';\nimport Constants, { ExecutionEnvironment } from 'expo-constants';\nimport * as Linking from 'expo-linking';\nimport { CreateURLOptions } from 'expo-linking';\nimport { resolveScheme } from 'expo-linking/build/Schemes';\nimport qs, { ParsedQs } from 'qs';\n\nconst { manifest } = Constants;\n\nexport class SessionUrlProvider {\n private static readonly BASE_URL = `https://auth.expo.io`;\n private static readonly SESSION_PATH = 'expo-auth-session';\n\n getDefaultReturnUrl(urlPath?: string, options?: Omit<CreateURLOptions, 'queryParams'>): string {\n const queryParams = SessionUrlProvider.getHostAddressQueryParams();\n let path = SessionUrlProvider.SESSION_PATH;\n if (urlPath) {\n path = [path, SessionUrlProvider.removeLeadingSlash(urlPath)].filter(Boolean).join('/');\n }\n\n return Linking.createURL(path, {\n // The redirect URL doesn't matter for the proxy as long as it's valid, so silence warnings if needed.\n scheme: options?.scheme ?? resolveScheme({ isSilent: true }),\n queryParams,\n isTripleSlashed: options?.isTripleSlashed,\n });\n }\n\n getStartUrl(authUrl: string, returnUrl: string): string {\n if (Platform.OS === 'web' && !Platform.isDOMAvailable) {\n // Return nothing in SSR envs\n return '';\n }\n const queryString = qs.stringify({\n authUrl,\n returnUrl,\n });\n\n return `${this.getRedirectUrl()}/start?${queryString}`;\n }\n\n getRedirectUrl(urlPath?: string): string {\n if (Platform.OS === 'web') {\n if (Platform.isDOMAvailable) {\n return [window.location.origin, urlPath].filter(Boolean).join('/');\n } else {\n // Return nothing in SSR envs\n return '';\n }\n }\n\n const legacyExpoProjectId = manifest.currentFullName || manifest.id;\n\n if (!legacyExpoProjectId) {\n let nextSteps = '';\n if (__DEV__) {\n if (Constants.executionEnvironment === ExecutionEnvironment.Bare) {\n nextSteps =\n ' Please ensure you have the latest version of expo-constants installed and rebuild your native app. You can verify that currentFullName is defined by running `expo config --type public` and inspecting the output.';\n } else if (Constants.executionEnvironment === ExecutionEnvironment.StoreClient) {\n nextSteps =\n ' Please report this as a bug with the contents of `expo config --type public`.';\n }\n }\n throw new Error(\n 'Cannot use AuthSession proxy because the project ID is not defined.' + nextSteps\n );\n }\n\n const redirectUrl = `${SessionUrlProvider.BASE_URL}/${legacyExpoProjectId}`;\n if (__DEV__) {\n SessionUrlProvider.warnIfAnonymous(legacyExpoProjectId, redirectUrl);\n // TODO: Verify with the dev server that the manifest is up to date.\n }\n return redirectUrl;\n }\n\n private static getHostAddressQueryParams(): ParsedQs | undefined {\n let hostUri: string = Constants.manifest?.hostUri;\n if (\n !hostUri &&\n (ExecutionEnvironment.StoreClient === Constants.executionEnvironment || resolveScheme({}))\n ) {\n if (!Constants.linkingUri) {\n hostUri = '';\n } else {\n // we're probably not using up-to-date xdl, so just fake it for now\n // we have to remove the /--/ on the end since this will be inserted again later\n hostUri = SessionUrlProvider.removeScheme(Constants.linkingUri).replace(/\\/--(\\/.*)?$/, '');\n }\n }\n\n const uriParts = hostUri?.split('?');\n try {\n return qs.parse(uriParts?.[1]);\n } catch {}\n\n return undefined;\n }\n\n private static warnIfAnonymous(id, url): void {\n if (id.startsWith('@anonymous/')) {\n console.warn(\n `You are not currently signed in to Expo on your development machine. As a result, the redirect URL for AuthSession will be \"${url}\". If you are using an OAuth provider that requires adding redirect URLs to an allow list, we recommend that you do not add this URL -- instead, you should sign in to Expo to acquire a unique redirect URL. Additionally, if you do decide to publish this app using Expo, you will need to register an account to do it.`\n );\n }\n }\n\n private static removeScheme(url: string) {\n return url.replace(/^[a-zA-Z0-9+.-]+:\\/\\//, '');\n }\n\n private static removeLeadingSlash(url: string) {\n return url.replace(/^\\//, '');\n }\n}\n\nexport default new SessionUrlProvider();\n"]}
1
+ {"version":3,"file":"SessionUrlProvider.js","sourceRoot":"","sources":["../src/SessionUrlProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAC5D,OAAO,SAAS,EAAE,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,KAAK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AC1F;YACA,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE;gBACzB,OAAO,GAAG,EAAE,CAAC;aACd;iBAAM;gBACL,mEAAmE;gBACnE,gFAAgF;gBAChF,OAAO,GAAG,kBAAkB,CAAC,YAAY,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;aAC7F;SACF;QAED,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO,SAAS,CAAC;SAClB;QAED,MAAM,QAAQ,GAAG,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;QACrC,IAAI;YACF,OAAO,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;SAChC;QAAC,MAAM,GAAE;QAEV,OAAO,SAAS,CAAC;IACnB,CAAC;IAEO,MAAM,CAAC,eAAe,CAAC,EAAE,EAAE,GAAG;QACpC,IAAI,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE;YAChC,OAAO,CAAC,IAAI,CACV,+HAA+H,GAAG,6TAA6T,CAChc,CAAC;SACH;IACH,CAAC;IAEO,MAAM,CAAC,YAAY,CAAC,GAAW;QACrC,OAAO,GAAG,CAAC,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAC;IAClD,CAAC;IAEO,MAAM,CAAC,kBAAkB,CAAC,GAAW;QAC3C,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAChC,CAAC;;AAGH,eAAe,IAAI,kBAAkB,EAAE,CAAC","sourcesContent":["import { Platform } from '@unimodules/react-native-adapter';\nimport Constants, { ExecutionEnvironment } from 'expo-constants';\nimport * as Linking from 'expo-linking';\nimport { CreateURLOptions } from 'expo-linking';\nimport { resolveScheme } from 'expo-linking/build/Schemes';\nimport qs, { ParsedQs } from 'qs';\n\nexport class SessionUrlProvider {\n private static readonly BASE_URL = `https://auth.expo.io`;\n private static readonly SESSION_PATH = 'expo-auth-session';\n\n getDefaultReturnUrl(urlPath?: string, options?: Omit<CreateURLOptions, 'queryParams'>): string {\n const queryParams = SessionUrlProvider.getHostAddressQueryParams();\n let path = SessionUrlProvider.SESSION_PATH;\n if (urlPath) {\n path = [path, SessionUrlProvider.removeLeadingSlash(urlPath)].filter(Boolean).join('/');\n }\n\n return Linking.createURL(path, {\n // The redirect URL doesn't matter for the proxy as long as it's valid, so silence warnings if needed.\n scheme: options?.scheme ?? resolveScheme({ isSilent: true }),\n queryParams,\n isTripleSlashed: options?.isTripleSlashed,\n });\n }\n\n getStartUrl(authUrl: string, returnUrl: string): string {\n if (Platform.OS === 'web' && !Platform.isDOMAvailable) {\n // Return nothing in SSR envs\n return '';\n }\n const queryString = qs.stringify({\n authUrl,\n returnUrl,\n });\n\n return `${this.getRedirectUrl()}/start?${queryString}`;\n }\n\n getRedirectUrl(urlPath?: string): string {\n if (Platform.OS === 'web') {\n if (Platform.isDOMAvailable) {\n return [window.location.origin, urlPath].filter(Boolean).join('/');\n } else {\n // Return nothing in SSR envs\n return '';\n }\n }\n\n const legacyExpoProjectId =\n Constants.manifest?.originalFullName ||\n Constants.manifest2?.extra?.expoClient?.originalFullName ||\n Constants.manifest?.id;\n\n if (!legacyExpoProjectId) {\n let nextSteps = '';\n if (__DEV__) {\n if (Constants.executionEnvironment === ExecutionEnvironment.Bare) {\n nextSteps =\n ' Please ensure you have the latest version of expo-constants installed and rebuild your native app. You can verify that originalFullName is defined by running `expo config --type public` and inspecting the output.';\n } else if (Constants.executionEnvironment === ExecutionEnvironment.StoreClient) {\n nextSteps =\n ' Please report this as a bug with the contents of `expo config --type public`.';\n }\n }\n throw new Error(\n 'Cannot use AuthSession proxy because the project ID is not defined.' + nextSteps\n );\n }\n\n const redirectUrl = `${SessionUrlProvider.BASE_URL}/${legacyExpoProjectId}`;\n if (__DEV__) {\n SessionUrlProvider.warnIfAnonymous(legacyExpoProjectId, redirectUrl);\n // TODO: Verify with the dev server that the manifest is up to date.\n }\n return redirectUrl;\n }\n\n private static getHostAddressQueryParams(): ParsedQs | undefined {\n let hostUri: string | undefined =\n Constants.manifest?.hostUri ?? Constants.manifest2?.extra?.expoClient?.hostUri;\n if (\n !hostUri &&\n (ExecutionEnvironment.StoreClient === Constants.executionEnvironment || resolveScheme({}))\n ) {\n if (!Constants.linkingUri) {\n hostUri = '';\n } else {\n // we're probably not using up-to-date xdl, so just fake it for now\n // we have to remove the /--/ on the end since this will be inserted again later\n hostUri = SessionUrlProvider.removeScheme(Constants.linkingUri).replace(/\\/--(\\/.*)?$/, '');\n }\n }\n\n if (!hostUri) {\n return undefined;\n }\n\n const uriParts = hostUri?.split('?');\n try {\n return qs.parse(uriParts?.[1]);\n } catch {}\n\n return undefined;\n }\n\n private static warnIfAnonymous(id, url): void {\n if (id.startsWith('@anonymous/')) {\n console.warn(\n `You are not currently signed in to Expo on your development machine. As a result, the redirect URL for AuthSession will be \"${url}\". If you are using an OAuth provider that requires adding redirect URLs to an allow list, we recommend that you do not add this URL -- instead, you should sign in to Expo to acquire a unique redirect URL. Additionally, if you do decide to publish this app using Expo, you will need to register an account to do it.`\n );\n }\n }\n\n private static removeScheme(url: string) {\n return url.replace(/^[a-zA-Z0-9+.-]+:\\/\\//, '');\n }\n\n private static removeLeadingSlash(url: string) {\n return url.replace(/^\\//, '');\n }\n}\n\nexport default new SessionUrlProvider();\n"]}