expo-auth-session 4.1.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/build/AuthRequest.d.ts +1 -1
- package/build/AuthRequest.d.ts.map +1 -1
- package/build/AuthRequest.js +4 -11
- package/build/AuthRequest.js.map +1 -1
- package/build/AuthRequest.types.d.ts +0 -17
- package/build/AuthRequest.types.d.ts.map +1 -1
- package/build/AuthRequest.types.js.map +1 -1
- package/build/AuthSession.d.ts +3 -11
- package/build/AuthSession.d.ts.map +1 -1
- package/build/AuthSession.js +16 -85
- package/build/AuthSession.js.map +1 -1
- package/build/AuthSession.types.d.ts +1 -16
- package/build/AuthSession.types.d.ts.map +1 -1
- package/build/AuthSession.types.js.map +1 -1
- package/build/SessionUrlProvider.js +2 -2
- package/build/SessionUrlProvider.js.map +1 -1
- package/build/providers/Facebook.d.ts.map +1 -1
- package/build/providers/Facebook.js +7 -13
- package/build/providers/Facebook.js.map +1 -1
- package/build/providers/Google.d.ts.map +1 -1
- package/build/providers/Google.js +11 -18
- package/build/providers/Google.js.map +1 -1
- package/build/providers/ProviderUtils.d.ts +0 -3
- package/build/providers/ProviderUtils.d.ts.map +1 -1
- package/build/providers/ProviderUtils.js +0 -14
- package/build/providers/ProviderUtils.js.map +1 -1
- package/package.json +6 -6
- package/src/AuthRequest.ts +5 -13
- package/src/AuthRequest.types.ts +0 -15
- package/src/AuthSession.ts +19 -107
- package/src/AuthSession.types.ts +1 -16
- package/src/SessionUrlProvider.ts +2 -2
- package/src/providers/Facebook.ts +7 -14
- package/src/providers/Google.ts +11 -20
- package/src/providers/ProviderUtils.ts +0 -24
package/CHANGELOG.md
CHANGED
package/build/AuthRequest.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ export declare class AuthRequest implements Omit<AuthRequestConfig, 'state'> {
|
|
|
55
55
|
* @param discovery
|
|
56
56
|
* @param promptOptions
|
|
57
57
|
*/
|
|
58
|
-
promptAsync(discovery: AuthDiscoveryDocument, { url,
|
|
58
|
+
promptAsync(discovery: AuthDiscoveryDocument, { url, ...options }?: AuthRequestPromptOptions): Promise<AuthSessionResult>;
|
|
59
59
|
parseReturnUrl(url: string): AuthSessionResult;
|
|
60
60
|
/**
|
|
61
61
|
* Create the URL for authorization.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthRequest.d.ts","sourceRoot":"","sources":["../src/AuthRequest.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,mBAAmB,EACnB,YAAY,EACZ,MAAM,EACP,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"AuthRequest.d.ts","sourceRoot":"","sources":["../src/AuthRequest.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,mBAAmB,EACnB,YAAY,EACZ,MAAM,EACP,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAQhD,KAAK,qBAAqB,GAAG,IAAI,CAAC,iBAAiB,EAAE,uBAAuB,CAAC,CAAC;AAG9E;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,WAAY,YAAW,IAAI,CAAC,iBAAiB,EAAE,OAAO,CAAC;IAClE;;OAEG;IACI,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IAE9B,QAAQ,CAAC,YAAY,EAAE,YAAY,GAAG,MAAM,CAAC;IAC7C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7C,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,mBAAmB,EAAE,mBAAmB,CAAC;IAClD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;gBAEb,OAAO,EAAE,iBAAiB;IA2CtC;;OAEG;IACG,yBAAyB,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAoB7D;;;;;OAKG;IACG,WAAW,CACf,SAAS,EAAE,qBAAqB,EAChC,EAAE,GAAG,EAAE,GAAG,OAAO,EAAE,GAAE,wBAA6B,GACjD,OAAO,CAAC,iBAAiB,CAAC;IAuD7B,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB;IAgC9C;;;;OAIG;IACG,gBAAgB,CAAC,SAAS,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC;YA8C3D,sBAAsB;CAWrC"}
|
package/build/AuthRequest.js
CHANGED
|
@@ -5,7 +5,6 @@ import { CodeChallengeMethod, ResponseType, } from './AuthRequest.types';
|
|
|
5
5
|
import { AuthError } from './Errors';
|
|
6
6
|
import * as PKCE from './PKCE';
|
|
7
7
|
import * as QueryParams from './QueryParams';
|
|
8
|
-
import sessionUrlProvider from './SessionUrlProvider';
|
|
9
8
|
import { TokenResponse } from './TokenRequest';
|
|
10
9
|
let _authLock = false;
|
|
11
10
|
// @needsAudit @docsMissing
|
|
@@ -108,7 +107,7 @@ export class AuthRequest {
|
|
|
108
107
|
* @param discovery
|
|
109
108
|
* @param promptOptions
|
|
110
109
|
*/
|
|
111
|
-
async promptAsync(discovery, { url,
|
|
110
|
+
async promptAsync(discovery, { url, ...options } = {}) {
|
|
112
111
|
if (!url) {
|
|
113
112
|
if (!this.url) {
|
|
114
113
|
// Generate a new url
|
|
@@ -122,13 +121,8 @@ export class AuthRequest {
|
|
|
122
121
|
}
|
|
123
122
|
// Prevent accidentally starting to an empty url
|
|
124
123
|
invariant(url, 'No authUrl provided to AuthSession.startAsync. An authUrl is required -- it points to the page where the user will be able to sign in.');
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (options.useProxy) {
|
|
128
|
-
console.warn('The useProxy option is deprecated and will be removed in a future release, for more information check https://expo.fyi/auth-proxy-migration.');
|
|
129
|
-
returnUrl = sessionUrlProvider.getDefaultReturnUrl(proxyOptions?.path, proxyOptions);
|
|
130
|
-
startUrl = sessionUrlProvider.getStartUrl(url, returnUrl, options.projectNameForProxy);
|
|
131
|
-
}
|
|
124
|
+
const startUrl = url;
|
|
125
|
+
const returnUrl = this.redirectUri;
|
|
132
126
|
// Prevent multiple sessions from running at the same time, WebBrowser doesn't
|
|
133
127
|
// support it this makes the behavior predictable.
|
|
134
128
|
if (_authLock) {
|
|
@@ -141,8 +135,7 @@ export class AuthRequest {
|
|
|
141
135
|
_authLock = true;
|
|
142
136
|
let result;
|
|
143
137
|
try {
|
|
144
|
-
|
|
145
|
-
result = await WebBrowser.openAuthSessionAsync(startUrl, returnUrl, openOptions);
|
|
138
|
+
result = await WebBrowser.openAuthSessionAsync(startUrl, returnUrl, options);
|
|
146
139
|
}
|
|
147
140
|
finally {
|
|
148
141
|
_authLock = false;
|
package/build/AuthRequest.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthRequest.js","sourceRoot":"","sources":["../src/AuthRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,EAGL,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AC,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// @needsAudit @docsMissing\n/**\n * Used to manage an authorization request according to the OAuth spec: [Section 4.1.1](https://tools.ietf.org/html/rfc6749#section-4.1.1).\n * You can use this class directly for more info around the authorization.\n *\n * **Common use-cases:**\n *\n * - Parse a URL returned from the authorization server with `parseReturnUrlAsync()`.\n * - Get the built authorization URL with `makeAuthUrlAsync()`.\n * - Get a loaded JSON representation of the auth request with crypto state loaded with `getAuthRequestConfigAsync()`.\n *\n * @example\n * ```ts\n * // Create a request.\n * const request = new AuthRequest({ ... });\n *\n * // Prompt for an auth code\n * const result = await request.promptAsync(discovery);\n *\n * // Get the URL to invoke\n * const url = await request.makeAuthUrlAsync(discovery);\n *\n * // Get the URL to invoke\n * const parsed = await request.parseReturnUrlAsync(\"<URL From Server>\");\n * ```\n */\nexport class AuthRequest implements Omit<AuthRequestConfig, 'state'> {\n /**\n * Used for protection against [Cross-Site Request Forgery](https://tools.ietf.org/html/rfc6749#section-10.12).\n */\n public state: string;\n public url: string | null = null;\n public codeVerifier?: string;\n public codeChallenge?: string;\n\n readonly responseType: ResponseType | string;\n readonly clientId: string;\n readonly extraParams: Record<string, string>;\n readonly usePKCE?: boolean;\n readonly codeChallengeMethod: CodeChallengeMethod;\n readonly redirectUri: string;\n readonly scopes?: string[];\n readonly clientSecret?: string;\n readonly prompt?: Prompt;\n\n constructor(request: AuthRequestConfig) {\n this.responseType = request.responseType ?? ResponseType.Code;\n this.clientId = request.clientId;\n this.redirectUri = request.redirectUri;\n this.scopes = request.scopes;\n this.clientSecret = request.clientSecret;\n this.prompt = request.prompt;\n this.state = request.state ?? PKCE.generateRandom(10);\n this.extraParams = request.extraParams ?? {};\n this.codeChallengeMethod = request.codeChallengeMethod ?? CodeChallengeMethod.S256;\n // PKCE defaults to true\n this.usePKCE = request.usePKCE ?? true;\n\n // Some warnings in development about potential confusing application code\n if (__DEV__) {\n if (this.prompt && this.extraParams.prompt) {\n console.warn(`\\`AuthRequest\\` \\`extraParams.prompt\\` will be overwritten by \\`prompt\\`.`);\n }\n if (this.clientSecret && this.extraParams.client_secret) {\n console.warn(\n `\\`AuthRequest\\` \\`extraParams.client_secret\\` will be overwritten by \\`clientSecret\\`.`\n );\n }\n if (this.codeChallengeMethod && this.extraParams.code_challenge_method) {\n console.warn(\n `\\`AuthRequest\\` \\`extraParams.code_challenge_method\\` will be overwritten by \\`codeChallengeMethod\\`.`\n );\n }\n }\n\n invariant(\n this.codeChallengeMethod !== CodeChallengeMethod.Plain,\n `\\`AuthRequest\\` does not support \\`CodeChallengeMethod.Plain\\` as it's not secure.`\n );\n invariant(\n this.redirectUri,\n `\\`AuthRequest\\` requires a valid \\`redirectUri\\`. Ex: ${Platform.select({\n web: 'https://yourwebsite.com/',\n default: 'com.your.app:/oauthredirect',\n })}`\n );\n }\n\n /**\n * Load and return a valid auth request based on the input config.\n */\n async getAuthRequestConfigAsync(): Promise<AuthRequestConfig> {\n if (this.usePKCE) {\n await this.ensureCodeIsSetupAsync();\n }\n\n return {\n responseType: this.responseType,\n clientId: this.clientId,\n redirectUri: this.redirectUri,\n scopes: this.scopes,\n clientSecret: this.clientSecret,\n codeChallenge: this.codeChallenge,\n codeChallengeMethod: this.codeChallengeMethod,\n prompt: this.prompt,\n state: this.state,\n extraParams: this.extraParams,\n usePKCE: this.usePKCE,\n };\n }\n\n /**\n * Prompt a user to authorize for a code.\n *\n * @param discovery\n * @param promptOptions\n */\n async promptAsync(\n discovery: AuthDiscoveryDocument,\n { url, proxyOptions, ...options }: AuthRequestPromptOptions = {}\n ): Promise<AuthSessionResult> {\n if (!url) {\n if (!this.url) {\n // Generate a new url\n return this.promptAsync(discovery, {\n ...options,\n url: await this.makeAuthUrlAsync(discovery),\n });\n }\n // Reuse the preloaded url\n url = this.url;\n }\n\n // Prevent accidentally starting to an empty url\n invariant(\n url,\n 'No authUrl provided to AuthSession.startAsync. An authUrl is required -- it points to the page where the user will be able to sign in.'\n );\n\n let startUrl: string = url!;\n let returnUrl: string = this.redirectUri;\n if (options.useProxy) {\n console.warn(\n 'The useProxy option is deprecated and will be removed in a future release, for more information check https://expo.fyi/auth-proxy-migration.'\n );\n returnUrl = sessionUrlProvider.getDefaultReturnUrl(proxyOptions?.path, proxyOptions);\n startUrl = sessionUrlProvider.getStartUrl(url, returnUrl, options.projectNameForProxy);\n }\n // Prevent multiple sessions from running at the same time, WebBrowser doesn't\n // support it this makes the behavior predictable.\n if (_authLock) {\n if (__DEV__) {\n console.warn(\n 'Attempted to call AuthSession.startAsync multiple times while already active. Only one AuthSession can be active at any given time.'\n );\n }\n\n return { type: 'locked' };\n }\n\n // About to start session, set lock\n _authLock = true;\n\n let result: WebBrowser.WebBrowserAuthSessionResult;\n try {\n const { useProxy, ...openOptions } = options;\n result = await WebBrowser.openAuthSessionAsync(startUrl, returnUrl, openOptions);\n } finally {\n _authLock = false;\n }\n\n if (result.type === 'opened') {\n // This should never happen\n throw new Error('An unexpected error occurred');\n }\n if (result.type !== 'success') {\n return { type: result.type };\n }\n\n return this.parseReturnUrl(result.url);\n }\n\n parseReturnUrl(url: string): AuthSessionResult {\n const { params, errorCode } = QueryParams.getQueryParams(url);\n const { state, error = errorCode } = params;\n\n let parsedError: AuthError | null = null;\n let authentication: TokenResponse | null = null;\n if (state !== this.state) {\n // This is a non-standard error\n parsedError = new AuthError({\n error: 'state_mismatch',\n error_description:\n 'Cross-Site request verification failed. Cached state and returned state do not match.',\n });\n } else if (error) {\n parsedError = new AuthError({ error, ...params });\n }\n if (params.access_token) {\n authentication = TokenResponse.fromQueryParams(params);\n }\n\n return {\n type: parsedError ? 'error' : 'success',\n error: parsedError,\n url,\n params,\n authentication,\n\n // Return errorCode for legacy\n errorCode,\n };\n }\n\n /**\n * Create the URL for authorization.\n *\n * @param discovery\n */\n async makeAuthUrlAsync(discovery: AuthDiscoveryDocument): Promise<string> {\n const request = await this.getAuthRequestConfigAsync();\n if (!request.state) throw new Error('Cannot make request URL without a valid `state` loaded');\n\n // Create a query string\n const params: Record<string, string> = {};\n\n if (request.codeChallenge) {\n params.code_challenge = request.codeChallenge;\n }\n\n // copy over extra params\n for (const extra in request.extraParams) {\n if (extra in request.extraParams) {\n params[extra] = request.extraParams[extra];\n }\n }\n\n if (request.usePKCE && request.codeChallengeMethod) {\n params.code_challenge_method = request.codeChallengeMethod;\n }\n\n if (request.clientSecret) {\n params.client_secret = request.clientSecret;\n }\n\n if (request.prompt) {\n params.prompt = request.prompt;\n }\n\n // These overwrite any extra params\n params.redirect_uri = request.redirectUri;\n params.client_id = request.clientId;\n params.response_type = request.responseType!;\n params.state = request.state;\n\n if (request.scopes?.length) {\n params.scope = request.scopes.join(' ');\n }\n\n const query = QueryParams.buildQueryString(params);\n // Store the URL for later\n this.url = `${discovery.authorizationEndpoint}?${query}`;\n return this.url;\n }\n\n private async ensureCodeIsSetupAsync(): Promise<void> {\n if (this.codeVerifier) {\n return;\n }\n\n // This method needs to be resolved like all other native methods.\n const { codeVerifier, codeChallenge } = await PKCE.buildCodeAsync();\n\n this.codeVerifier = codeVerifier;\n this.codeChallenge = codeChallenge;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AuthRequest.js","sourceRoot":"","sources":["../src/AuthRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,QAAQ,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,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,IAAI,SAAS,GAAY,KAAK,CAAC;AAI/B,2BAA2B;AAC3B;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,OAAO,WAAW;IACtB;;OAEG;IACI,KAAK,CAAS;IACd,GAAG,GAAkB,IAAI,CAAC;IAC1B,YAAY,CAAU;IACtB,aAAa,CAAU;IAErB,YAAY,CAAw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;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 { TokenResponse } from './TokenRequest';\n\nlet _authLock: boolean = false;\n\ntype AuthDiscoveryDocument = Pick<DiscoveryDocument, 'authorizationEndpoint'>;\n\n// @needsAudit @docsMissing\n/**\n * Used to manage an authorization request according to the OAuth spec: [Section 4.1.1](https://tools.ietf.org/html/rfc6749#section-4.1.1).\n * You can use this class directly for more info around the authorization.\n *\n * **Common use-cases:**\n *\n * - Parse a URL returned from the authorization server with `parseReturnUrlAsync()`.\n * - Get the built authorization URL with `makeAuthUrlAsync()`.\n * - Get a loaded JSON representation of the auth request with crypto state loaded with `getAuthRequestConfigAsync()`.\n *\n * @example\n * ```ts\n * // Create a request.\n * const request = new AuthRequest({ ... });\n *\n * // Prompt for an auth code\n * const result = await request.promptAsync(discovery);\n *\n * // Get the URL to invoke\n * const url = await request.makeAuthUrlAsync(discovery);\n *\n * // Get the URL to invoke\n * const parsed = await request.parseReturnUrlAsync(\"<URL From Server>\");\n * ```\n */\nexport class AuthRequest implements Omit<AuthRequestConfig, 'state'> {\n /**\n * Used for protection against [Cross-Site Request Forgery](https://tools.ietf.org/html/rfc6749#section-10.12).\n */\n public state: string;\n public url: string | null = null;\n public codeVerifier?: string;\n public codeChallenge?: string;\n\n readonly responseType: ResponseType | string;\n readonly clientId: string;\n readonly extraParams: Record<string, string>;\n readonly usePKCE?: boolean;\n readonly codeChallengeMethod: CodeChallengeMethod;\n readonly redirectUri: string;\n readonly scopes?: string[];\n readonly clientSecret?: string;\n readonly prompt?: Prompt;\n\n constructor(request: AuthRequestConfig) {\n this.responseType = request.responseType ?? ResponseType.Code;\n this.clientId = request.clientId;\n this.redirectUri = request.redirectUri;\n this.scopes = request.scopes;\n this.clientSecret = request.clientSecret;\n this.prompt = request.prompt;\n this.state = request.state ?? PKCE.generateRandom(10);\n this.extraParams = request.extraParams ?? {};\n this.codeChallengeMethod = request.codeChallengeMethod ?? CodeChallengeMethod.S256;\n // PKCE defaults to true\n this.usePKCE = request.usePKCE ?? true;\n\n // Some warnings in development about potential confusing application code\n if (__DEV__) {\n if (this.prompt && this.extraParams.prompt) {\n console.warn(`\\`AuthRequest\\` \\`extraParams.prompt\\` will be overwritten by \\`prompt\\`.`);\n }\n if (this.clientSecret && this.extraParams.client_secret) {\n console.warn(\n `\\`AuthRequest\\` \\`extraParams.client_secret\\` will be overwritten by \\`clientSecret\\`.`\n );\n }\n if (this.codeChallengeMethod && this.extraParams.code_challenge_method) {\n console.warn(\n `\\`AuthRequest\\` \\`extraParams.code_challenge_method\\` will be overwritten by \\`codeChallengeMethod\\`.`\n );\n }\n }\n\n invariant(\n this.codeChallengeMethod !== CodeChallengeMethod.Plain,\n `\\`AuthRequest\\` does not support \\`CodeChallengeMethod.Plain\\` as it's not secure.`\n );\n invariant(\n this.redirectUri,\n `\\`AuthRequest\\` requires a valid \\`redirectUri\\`. Ex: ${Platform.select({\n web: 'https://yourwebsite.com/',\n default: 'com.your.app:/oauthredirect',\n })}`\n );\n }\n\n /**\n * Load and return a valid auth request based on the input config.\n */\n async getAuthRequestConfigAsync(): Promise<AuthRequestConfig> {\n if (this.usePKCE) {\n await this.ensureCodeIsSetupAsync();\n }\n\n return {\n responseType: this.responseType,\n clientId: this.clientId,\n redirectUri: this.redirectUri,\n scopes: this.scopes,\n clientSecret: this.clientSecret,\n codeChallenge: this.codeChallenge,\n codeChallengeMethod: this.codeChallengeMethod,\n prompt: this.prompt,\n state: this.state,\n extraParams: this.extraParams,\n usePKCE: this.usePKCE,\n };\n }\n\n /**\n * Prompt a user to authorize for a code.\n *\n * @param discovery\n * @param promptOptions\n */\n async promptAsync(\n discovery: AuthDiscoveryDocument,\n { url, ...options }: AuthRequestPromptOptions = {}\n ): Promise<AuthSessionResult> {\n if (!url) {\n if (!this.url) {\n // Generate a new url\n return this.promptAsync(discovery, {\n ...options,\n url: await this.makeAuthUrlAsync(discovery),\n });\n }\n // Reuse the preloaded url\n url = this.url;\n }\n\n // Prevent accidentally starting to an empty url\n invariant(\n url,\n 'No authUrl provided to AuthSession.startAsync. An authUrl is required -- it points to the page where the user will be able to sign in.'\n );\n\n const startUrl: string = url!;\n const returnUrl: string = this.redirectUri;\n\n // Prevent multiple sessions from running at the same time, WebBrowser doesn't\n // support it this makes the behavior predictable.\n if (_authLock) {\n if (__DEV__) {\n console.warn(\n 'Attempted to call AuthSession.startAsync multiple times while already active. Only one AuthSession can be active at any given time.'\n );\n }\n\n return { type: 'locked' };\n }\n\n // About to start session, set lock\n _authLock = true;\n\n let result: WebBrowser.WebBrowserAuthSessionResult;\n try {\n result = await WebBrowser.openAuthSessionAsync(startUrl, returnUrl, options);\n } finally {\n _authLock = false;\n }\n\n if (result.type === 'opened') {\n // This should never happen\n throw new Error('An unexpected error occurred');\n }\n if (result.type !== 'success') {\n return { type: result.type };\n }\n\n return this.parseReturnUrl(result.url);\n }\n\n parseReturnUrl(url: string): AuthSessionResult {\n const { params, errorCode } = QueryParams.getQueryParams(url);\n const { state, error = errorCode } = params;\n\n let parsedError: AuthError | null = null;\n let authentication: TokenResponse | null = null;\n if (state !== this.state) {\n // This is a non-standard error\n parsedError = new AuthError({\n error: 'state_mismatch',\n error_description:\n 'Cross-Site request verification failed. Cached state and returned state do not match.',\n });\n } else if (error) {\n parsedError = new AuthError({ error, ...params });\n }\n if (params.access_token) {\n authentication = TokenResponse.fromQueryParams(params);\n }\n\n return {\n type: parsedError ? 'error' : 'success',\n error: parsedError,\n url,\n params,\n authentication,\n\n // Return errorCode for legacy\n errorCode,\n };\n }\n\n /**\n * Create the URL for authorization.\n *\n * @param discovery\n */\n async makeAuthUrlAsync(discovery: AuthDiscoveryDocument): Promise<string> {\n const request = await this.getAuthRequestConfigAsync();\n if (!request.state) throw new Error('Cannot make request URL without a valid `state` loaded');\n\n // Create a query string\n const params: Record<string, string> = {};\n\n if (request.codeChallenge) {\n params.code_challenge = request.codeChallenge;\n }\n\n // copy over extra params\n for (const extra in request.extraParams) {\n if (extra in request.extraParams) {\n params[extra] = request.extraParams[extra];\n }\n }\n\n if (request.usePKCE && request.codeChallengeMethod) {\n params.code_challenge_method = request.codeChallengeMethod;\n }\n\n if (request.clientSecret) {\n params.client_secret = request.clientSecret;\n }\n\n if (request.prompt) {\n params.prompt = request.prompt;\n }\n\n // These overwrite any extra params\n params.redirect_uri = request.redirectUri;\n params.client_id = request.clientId;\n params.response_type = request.responseType!;\n params.state = request.state;\n\n if (request.scopes?.length) {\n params.scope = request.scopes.join(' ');\n }\n\n const query = QueryParams.buildQueryString(params);\n // Store the URL for later\n this.url = `${discovery.authorizationEndpoint}?${query}`;\n return this.url;\n }\n\n private async ensureCodeIsSetupAsync(): Promise<void> {\n if (this.codeVerifier) {\n return;\n }\n\n // This method needs to be resolved like all other native methods.\n const { codeVerifier, codeChallenge } = await PKCE.buildCodeAsync();\n\n this.codeVerifier = codeVerifier;\n this.codeChallenge = codeChallenge;\n }\n}\n"]}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { CreateURLOptions } from 'expo-linking';
|
|
2
1
|
import { WebBrowserOpenOptions, WebBrowserWindowFeatures } from 'expo-web-browser';
|
|
3
2
|
export declare enum CodeChallengeMethod {
|
|
4
3
|
/**
|
|
@@ -71,22 +70,6 @@ export type AuthRequestPromptOptions = Omit<WebBrowserOpenOptions, 'windowFeatur
|
|
|
71
70
|
* URL to open when prompting the user. This usually should be defined internally and left `undefined` in most cases.
|
|
72
71
|
*/
|
|
73
72
|
url?: string;
|
|
74
|
-
/**
|
|
75
|
-
* Should the authentication request use the Expo proxy service `auth.expo.io`.
|
|
76
|
-
* @default false
|
|
77
|
-
* @deprecated This option will be removed in a future release, for more information check [the migration guide](https://expo.fyi/auth-proxy-migration).
|
|
78
|
-
*/
|
|
79
|
-
useProxy?: boolean;
|
|
80
|
-
/**
|
|
81
|
-
* Project name to use for the `auth.expo.io` proxy when `useProxy` is `true`.
|
|
82
|
-
*/
|
|
83
|
-
projectNameForProxy?: string;
|
|
84
|
-
/**
|
|
85
|
-
* URL options to be used when creating the redirect URL for the auth proxy.
|
|
86
|
-
*/
|
|
87
|
-
proxyOptions?: Omit<CreateURLOptions, 'queryParams'> & {
|
|
88
|
-
path?: string;
|
|
89
|
-
};
|
|
90
73
|
/**
|
|
91
74
|
* Features to use with `window.open()`.
|
|
92
75
|
* @platform web
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthRequest.types.d.ts","sourceRoot":"","sources":["../src/AuthRequest.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"AuthRequest.types.d.ts","sourceRoot":"","sources":["../src/AuthRequest.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAGnF,oBAAY,mBAAmB;IAC7B;;;;;OAKG;IACH,IAAI,SAAS;IACb;;OAEG;IACH,KAAK,UAAU;CAChB;AAGD;;;;GAIG;AACH,oBAAY,YAAY;IACtB;;OAEG;IACH,IAAI,SAAS;IACb;;OAEG;IACH,KAAK,UAAU;IACf;;OAEG;IACH,OAAO,aAAa;CACrB;AAGD;;;;;;GAMG;AACH,oBAAY,MAAM;IAChB;;;;OAIG;IACH,IAAI,SAAS;IACb;;;OAGG;IACH,KAAK,UAAU;IACf;;;OAGG;IACH,OAAO,YAAY;IACnB;;;OAGG;IACH,aAAa,mBAAmB;CACjC;AAGD;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAAG,IAAI,CAAC,qBAAqB,EAAE,gBAAgB,CAAC,GAAG;IACrF;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,cAAc,CAAC,EAAE,wBAAwB,CAAC;CAC3C,CAAC;AAGF;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC;IACrC;;;;;;;;OAQG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAC1C;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthRequest.types.js","sourceRoot":"","sources":["../src/AuthRequest.types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AuthRequest.types.js","sourceRoot":"","sources":["../src/AuthRequest.types.ts"],"names":[],"mappings":"AAEA,cAAc;AACd,MAAM,CAAN,IAAY,mBAYX;AAZD,WAAY,mBAAmB;IAC7B;;;;;OAKG;IACH,oCAAa,CAAA;IACb;;OAEG;IACH,sCAAe,CAAA;AACjB,CAAC,EAZW,mBAAmB,KAAnB,mBAAmB,QAY9B;AAED,cAAc;AACd;;;;GAIG;AACH,MAAM,CAAN,IAAY,YAaX;AAbD,WAAY,YAAY;IACtB;;OAEG;IACH,6BAAa,CAAA;IACb;;OAEG;IACH,+BAAe,CAAA;IACf;;OAEG;IACH,oCAAoB,CAAA;AACtB,CAAC,EAbW,YAAY,KAAZ,YAAY,QAavB;AAED,cAAc;AACd;;;;;;GAMG;AACH,MAAM,CAAN,IAAY,MAsBX;AAtBD,WAAY,MAAM;IAChB;;;;OAIG;IACH,uBAAa,CAAA;IACb;;;OAGG;IACH,yBAAe,CAAA;IACf;;;OAGG;IACH,6BAAmB,CAAA;IACnB;;;OAGG;IACH,0CAAgC,CAAA;AAClC,CAAC,EAtBW,MAAM,KAAN,MAAM,QAsBjB","sourcesContent":["import { WebBrowserOpenOptions, WebBrowserWindowFeatures } from 'expo-web-browser';\n\n// @needsAudit\nexport enum CodeChallengeMethod {\n /**\n * The default and recommended method for transforming the code verifier.\n * - Convert the code verifier to ASCII.\n * - Create a digest of the string using crypto method SHA256.\n * - Convert the digest to Base64 and URL encode it.\n */\n S256 = 'S256',\n /**\n * This should not be used. When used, the code verifier will be sent to the server as-is.\n */\n Plain = 'plain',\n}\n\n// @needsAudit\n/**\n * The client informs the authorization server of the desired grant type by using the response type.\n *\n * @see [Section 3.1.1](https://tools.ietf.org/html/rfc6749#section-3.1.1).\n */\nexport enum ResponseType {\n /**\n * For requesting an authorization code as described by [Section 4.1.1](https://tools.ietf.org/html/rfc6749#section-4.1.1).\n */\n Code = 'code',\n /**\n * For requesting an access token (implicit grant) as described by [Section 4.2.1](https://tools.ietf.org/html/rfc6749#section-4.2.1).\n */\n Token = 'token',\n /**\n * A custom registered type for getting an `id_token` from Google OAuth.\n */\n IdToken = 'id_token',\n}\n\n// @needsAudit\n/**\n * Informs the server if the user should be prompted to login or consent again.\n * This can be used to present a dialog for switching accounts after the user has already been logged in.\n * You should use this in favor of clearing cookies (which is mostly not possible on iOS).\n *\n * @see [Section 3.1.2.1](https://openid.net/specs/openid-connect-core-1_0.html#AuthorizationRequest).\n */\nexport enum Prompt {\n /**\n * Server must not display any auth or consent UI. Can be used to check for existing auth or consent.\n * An error is returned if a user isn't already authenticated or the client doesn't have pre-configured consent for the requested claims, or does not fulfill other conditions for processing the request.\n * The error code will typically be `login_required`, `interaction_required`, or another code defined in [Section 3.1.2.6](https://openid.net/specs/openid-connect-core-1_0.html#AuthError).\n */\n None = 'none',\n /**\n * The server should prompt the user to reauthenticate.\n * If it cannot reauthenticate the End-User, it must return an error, typically `login_required`.\n */\n Login = 'login',\n /**\n * Server should prompt the user for consent before returning information to the client.\n * If it cannot obtain consent, it must return an error, typically `consent_required`.\n */\n Consent = 'consent',\n /**\n * Server should prompt the user to select an account. Can be used to switch accounts.\n * If it can't obtain an account selection choice made by the user, it must return an error, typically `account_selection_required`.\n */\n SelectAccount = 'select_account',\n}\n\n// @needsAudit\n/**\n * Options passed to the `promptAsync()` method of `AuthRequest`s.\n * This can be used to configure how the web browser should look and behave.\n */\nexport type AuthRequestPromptOptions = Omit<WebBrowserOpenOptions, 'windowFeatures'> & {\n /**\n * URL to open when prompting the user. This usually should be defined internally and left `undefined` in most cases.\n */\n url?: string;\n /**\n * Features to use with `window.open()`.\n * @platform web\n */\n windowFeatures?: WebBrowserWindowFeatures;\n};\n\n// @needsAudit\n/**\n * Represents an OAuth authorization request as JSON.\n */\nexport interface AuthRequestConfig {\n /**\n * Specifies what is returned from the authorization server.\n *\n * [Section 3.1.1](https://tools.ietf.org/html/rfc6749#section-3.1.1)\n *\n * @default ResponseType.Code\n */\n responseType?: ResponseType | string;\n /**\n * A unique string representing the registration information provided by the client.\n * The client identifier is not a secret; it is exposed to the resource owner and shouldn't be used\n * alone for client authentication.\n *\n * The client identifier is unique to the authorization server.\n *\n * [Section 2.2](https://tools.ietf.org/html/rfc6749#section-2.2)\n */\n clientId: string;\n /**\n * After completing an interaction with a resource owner the\n * server will redirect to this URI. Learn more about [linking in Expo](/guides/linking/).\n *\n * [Section 3.1.2](https://tools.ietf.org/html/rfc6749#section-3.1.2)\n */\n redirectUri: string;\n /**\n * List of strings to request access to.\n *\n * [Section 3.3](https://tools.ietf.org/html/rfc6749#section-3.3)\n */\n scopes?: string[];\n /**\n * Client secret supplied by an auth provider.\n * There is no secure way to store this on the client.\n *\n * [Section 2.3.1](https://tools.ietf.org/html/rfc6749#section-2.3.1)\n */\n clientSecret?: string;\n /**\n * Method used to generate the code challenge. You should never use `Plain` as it's not good enough for secure verification.\n * @default CodeChallengeMethod.S256\n */\n codeChallengeMethod?: CodeChallengeMethod;\n /**\n * Derived from the code verifier by using the `CodeChallengeMethod`.\n *\n * [Section 4.2](https://tools.ietf.org/html/rfc7636#section-4.2)\n */\n codeChallenge?: string;\n /**\n * Informs the server if the user should be prompted to login or consent again.\n * This can be used to present a dialog for switching accounts after the user has already been logged in.\n *\n * [Section 3.1.2.1](https://openid.net/specs/openid-connect-core-1_0.html#AuthorizationRequest)\n */\n prompt?: Prompt;\n /**\n * Used for protection against [Cross-Site Request Forgery](https://tools.ietf.org/html/rfc6749#section-10.12).\n */\n state?: string;\n /**\n * Extra query params that'll be added to the query string.\n */\n extraParams?: Record<string, string>;\n /**\n * Should use [Proof Key for Code Exchange](https://oauth.net/2/pkce/).\n * @default true\n */\n usePKCE?: boolean;\n}\n"]}
|
package/build/AuthSession.d.ts
CHANGED
|
@@ -4,14 +4,6 @@ import { AuthRequestConfig, AuthRequestPromptOptions, CodeChallengeMethod, Promp
|
|
|
4
4
|
import { AuthSessionOptions, AuthSessionRedirectUriOptions, AuthSessionResult } from './AuthSession.types';
|
|
5
5
|
import { DiscoveryDocument, fetchDiscoveryAsync, Issuer, IssuerOrDiscovery, ProviderMetadata, resolveDiscoveryAsync } from './Discovery';
|
|
6
6
|
import { generateHexStringAsync } from './PKCE';
|
|
7
|
-
/**
|
|
8
|
-
* Initiate a proxied authentication session with the given options. Only one `AuthSession` can be active at any given time in your application.
|
|
9
|
-
* If you attempt to open a second session while one is still in progress, the second session will return a value to indicate that `AuthSession` is locked.
|
|
10
|
-
*
|
|
11
|
-
* @param options An object of type `AuthSessionOptions`.
|
|
12
|
-
* @return Returns a Promise that resolves to an `AuthSessionResult` object.
|
|
13
|
-
*/
|
|
14
|
-
export declare function startAsync(options: AuthSessionOptions): Promise<AuthSessionResult>;
|
|
15
7
|
/**
|
|
16
8
|
* Cancels an active `AuthSession` if there is one. No return value, but if there is an active `AuthSession`
|
|
17
9
|
* then the Promise returned by the `AuthSession.startAsync()` that initiated it resolves to `{ type: 'dismiss' }`.
|
|
@@ -54,7 +46,7 @@ export declare function getRedirectUrl(path?: string): string;
|
|
|
54
46
|
* path: 'redirect'
|
|
55
47
|
* });
|
|
56
48
|
* // Development Build: my-scheme://redirect
|
|
57
|
-
* // Expo Go: exp://127.0.0.1:
|
|
49
|
+
* // Expo Go: exp://127.0.0.1:8081/--/redirect
|
|
58
50
|
* // Web dev: https://localhost:19006/redirect
|
|
59
51
|
* // Web prod: https://yourwebsite.com/redirect
|
|
60
52
|
*
|
|
@@ -64,12 +56,12 @@ export declare function getRedirectUrl(path?: string): string;
|
|
|
64
56
|
* isTripleSlashed: true,
|
|
65
57
|
* });
|
|
66
58
|
* // Development Build: scheme2:///
|
|
67
|
-
* // Expo Go: exp://localhost:
|
|
59
|
+
* // Expo Go: exp://localhost:8081
|
|
68
60
|
* // Web dev: https://localhost:19006
|
|
69
61
|
* // Web prod: https://yourwebsite.com
|
|
70
62
|
* ```
|
|
71
63
|
*/
|
|
72
|
-
export declare function makeRedirectUri({ native, scheme, isTripleSlashed, queryParams, path, preferLocalhost,
|
|
64
|
+
export declare function makeRedirectUri({ native, scheme, isTripleSlashed, queryParams, path, preferLocalhost, }?: AuthSessionRedirectUriOptions): string;
|
|
73
65
|
/**
|
|
74
66
|
* Build an `AuthRequest` and load it before returning.
|
|
75
67
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthSession.d.ts","sourceRoot":"","sources":["../src/AuthSession.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"AuthSession.d.ts","sourceRoot":"","sources":["../src/AuthSession.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAIxC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,mBAAmB,EACnB,MAAM,EACN,YAAY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AAY,EACZ,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AAGxB,cAAc,sBAAsB,CAAC;AAGrC,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/build/AuthSession.js
CHANGED
|
@@ -1,70 +1,12 @@
|
|
|
1
1
|
import Constants, { ExecutionEnvironment } from 'expo-constants';
|
|
2
2
|
import * as Linking from 'expo-linking';
|
|
3
3
|
import { Platform } from 'expo-modules-core';
|
|
4
|
-
import { dismissAuthSession
|
|
4
|
+
import { dismissAuthSession } from 'expo-web-browser';
|
|
5
5
|
import { AuthRequest } from './AuthRequest';
|
|
6
6
|
import { CodeChallengeMethod, Prompt, ResponseType, } from './AuthRequest.types';
|
|
7
7
|
import { fetchDiscoveryAsync, resolveDiscoveryAsync, } from './Discovery';
|
|
8
8
|
import { generateHexStringAsync } from './PKCE';
|
|
9
|
-
import { getQueryParams } from './QueryParams';
|
|
10
9
|
import sessionUrlProvider from './SessionUrlProvider';
|
|
11
|
-
let _authLock = false;
|
|
12
|
-
// @needsAudit
|
|
13
|
-
/**
|
|
14
|
-
* Initiate a proxied authentication session with the given options. Only one `AuthSession` can be active at any given time in your application.
|
|
15
|
-
* If you attempt to open a second session while one is still in progress, the second session will return a value to indicate that `AuthSession` is locked.
|
|
16
|
-
*
|
|
17
|
-
* @param options An object of type `AuthSessionOptions`.
|
|
18
|
-
* @return Returns a Promise that resolves to an `AuthSessionResult` object.
|
|
19
|
-
*/
|
|
20
|
-
export async function startAsync(options) {
|
|
21
|
-
const authUrl = options.authUrl;
|
|
22
|
-
// Prevent accidentally starting to an empty url
|
|
23
|
-
if (!authUrl) {
|
|
24
|
-
throw new Error('No authUrl provided to AuthSession.startAsync. An authUrl is required -- it points to the page where the user will be able to sign in.');
|
|
25
|
-
}
|
|
26
|
-
// Prevent multiple sessions from running at the same time, WebBrowser doesn't
|
|
27
|
-
// support it this makes the behavior predictable.
|
|
28
|
-
if (_authLock) {
|
|
29
|
-
if (__DEV__) {
|
|
30
|
-
console.warn('Attempted to call AuthSession.startAsync multiple times while already active. Only one AuthSession can be active at any given time.');
|
|
31
|
-
}
|
|
32
|
-
return { type: 'locked' };
|
|
33
|
-
}
|
|
34
|
-
const returnUrl = options.returnUrl || sessionUrlProvider.getDefaultReturnUrl();
|
|
35
|
-
const startUrl = sessionUrlProvider.getStartUrl(authUrl, returnUrl, options.projectNameForProxy);
|
|
36
|
-
const showInRecents = options.showInRecents || false;
|
|
37
|
-
// About to start session, set lock
|
|
38
|
-
_authLock = true;
|
|
39
|
-
let result;
|
|
40
|
-
try {
|
|
41
|
-
result = await _openWebBrowserAsync(startUrl, returnUrl, showInRecents);
|
|
42
|
-
}
|
|
43
|
-
finally {
|
|
44
|
-
// WebBrowser session complete, unset lock
|
|
45
|
-
_authLock = false;
|
|
46
|
-
}
|
|
47
|
-
// Handle failures
|
|
48
|
-
if (!result) {
|
|
49
|
-
throw new Error('Unexpected missing AuthSession result');
|
|
50
|
-
}
|
|
51
|
-
if (!('url' in result)) {
|
|
52
|
-
if ('type' in result) {
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
throw new Error('Unexpected AuthSession result with missing type');
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
const { params, errorCode } = getQueryParams(result.url);
|
|
60
|
-
return {
|
|
61
|
-
type: errorCode ? 'error' : 'success',
|
|
62
|
-
params,
|
|
63
|
-
errorCode,
|
|
64
|
-
authentication: null,
|
|
65
|
-
url: result.url,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
10
|
// @needsAudit
|
|
69
11
|
/**
|
|
70
12
|
* Cancels an active `AuthSession` if there is one. No return value, but if there is an active `AuthSession`
|
|
@@ -114,7 +56,7 @@ export function getRedirectUrl(path) {
|
|
|
114
56
|
* path: 'redirect'
|
|
115
57
|
* });
|
|
116
58
|
* // Development Build: my-scheme://redirect
|
|
117
|
-
* // Expo Go: exp://127.0.0.1:
|
|
59
|
+
* // Expo Go: exp://127.0.0.1:8081/--/redirect
|
|
118
60
|
* // Web dev: https://localhost:19006/redirect
|
|
119
61
|
* // Web prod: https://yourwebsite.com/redirect
|
|
120
62
|
*
|
|
@@ -124,36 +66,32 @@ export function getRedirectUrl(path) {
|
|
|
124
66
|
* isTripleSlashed: true,
|
|
125
67
|
* });
|
|
126
68
|
* // Development Build: scheme2:///
|
|
127
|
-
* // Expo Go: exp://localhost:
|
|
69
|
+
* // Expo Go: exp://localhost:8081
|
|
128
70
|
* // Web dev: https://localhost:19006
|
|
129
71
|
* // Web prod: https://yourwebsite.com
|
|
130
72
|
* ```
|
|
131
73
|
*/
|
|
132
|
-
export function makeRedirectUri({ native, scheme, isTripleSlashed, queryParams, path, preferLocalhost,
|
|
74
|
+
export function makeRedirectUri({ native, scheme, isTripleSlashed, queryParams, path, preferLocalhost, } = {}) {
|
|
133
75
|
if (Platform.OS !== 'web' &&
|
|
134
76
|
native &&
|
|
135
77
|
[ExecutionEnvironment.Standalone, ExecutionEnvironment.Bare].includes(Constants.executionEnvironment)) {
|
|
136
78
|
// Should use the user-defined native scheme in standalone builds
|
|
137
79
|
return native;
|
|
138
80
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
return `${protocol}localhost${path}`;
|
|
151
|
-
}
|
|
81
|
+
const url = Linking.createURL(path || '', {
|
|
82
|
+
isTripleSlashed,
|
|
83
|
+
scheme,
|
|
84
|
+
queryParams,
|
|
85
|
+
});
|
|
86
|
+
if (preferLocalhost) {
|
|
87
|
+
const ipAddress = url.match(/\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/);
|
|
88
|
+
// Only replace if an IP address exists
|
|
89
|
+
if (ipAddress?.length) {
|
|
90
|
+
const [protocol, path] = url.split(ipAddress[0]);
|
|
91
|
+
return `${protocol}localhost${path}`;
|
|
152
92
|
}
|
|
153
|
-
return url;
|
|
154
93
|
}
|
|
155
|
-
|
|
156
|
-
return sessionUrlProvider.getRedirectUrl({ urlPath: path, projectNameForProxy });
|
|
94
|
+
return url;
|
|
157
95
|
}
|
|
158
96
|
// @needsAudit
|
|
159
97
|
/**
|
|
@@ -170,13 +108,6 @@ export async function loadAsync(config, issuerOrDiscovery) {
|
|
|
170
108
|
await request.makeAuthUrlAsync(discovery);
|
|
171
109
|
return request;
|
|
172
110
|
}
|
|
173
|
-
async function _openWebBrowserAsync(startUrl, returnUrl, showInRecents) {
|
|
174
|
-
const result = await openAuthSessionAsync(startUrl, returnUrl, { showInRecents });
|
|
175
|
-
if (result.type === 'cancel' || result.type === 'dismiss') {
|
|
176
|
-
return { type: result.type };
|
|
177
|
-
}
|
|
178
|
-
return result;
|
|
179
|
-
}
|
|
180
111
|
export { useAutoDiscovery, useAuthRequest } from './AuthRequestHooks';
|
|
181
112
|
export { AuthError, TokenError } from './Errors';
|
|
182
113
|
export { AuthRequest, CodeChallengeMethod, Prompt, ResponseType, resolveDiscoveryAsync, fetchDiscoveryAsync, generateHexStringAsync, };
|
package/build/AuthSession.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,EACL,kBAAkB,EAClB,oBAAoB,GAErB,M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,CAAC,CAAC;IAClF,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE;QACzD,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;KAC9B;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 Constants, { ExecutionEnvironment } from 'expo-constants';\nimport * as Linking from 'expo-linking';\nimport { Platform } from 'expo-modules-core';\nimport {\n dismissAuthSession,\n openAuthSessionAsync,\n WebBrowserAuthSessionResult,\n} 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\n// @needsAudit\n/**\n * Initiate a proxied authentication session with the given options. Only one `AuthSession` can be active at any given time in your application.\n * If you attempt to open a second session while one is still in progress, the second session will return a value to indicate that `AuthSession` is locked.\n *\n * @param options An object of type `AuthSessionOptions`.\n * @return Returns a Promise that resolves to an `AuthSessionResult` object.\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, options.projectNameForProxy);\n const showInRecents = options.showInRecents || false;\n\n // About to start session, set lock\n _authLock = true;\n\n let result: WebBrowserAuthSessionResult;\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 (!('url' in result)) {\n if ('type' in result) {\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\n// @needsAudit\n/**\n * Cancels an active `AuthSession` if there is one. No return value, but if there is an active `AuthSession`\n * then the Promise returned by the `AuthSession.startAsync()` that initiated it resolves to `{ type: 'dismiss' }`.\n */\nexport function dismiss() {\n dismissAuthSession();\n}\n\nexport const getDefaultReturnUrl = sessionUrlProvider.getDefaultReturnUrl;\n\n// @needsAudit @docsMissing\n/**\n * Get the URL that your authentication provider needs to redirect to. For example: `https://auth.expo.io/@your-username/your-app-slug`. You can pass an additional path component to be appended to the default redirect URL.\n * > **Note** This method will throw an exception if you're using the bare workflow on native.\n *\n * @param path\n * @return\n *\n * @example\n * ```ts\n * const url = AuthSession.getRedirectUrl('redirect');\n *\n * // Managed: https://auth.expo.io/@your-username/your-app-slug/redirect\n * // Web: https://localhost:19006/redirect\n * ```\n *\n * @deprecated Use `makeRedirectUri()` instead.\n */\nexport function getRedirectUrl(path?: string): string {\n return sessionUrlProvider.getRedirectUrl({ urlPath: path });\n}\n\n// @needsAudit\n/**\n * Create a redirect url for the current platform and environment. You need to manually define the redirect that will be used in\n * a bare workflow React Native app, or an Expo standalone app, this is because it cannot be inferred automatically.\n * - **Web:** Generates a path based on the current `window.location`. For production web apps, you should hard code the URL as well.\n * - **Managed workflow:** 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 Go and standalone environments.\n * - **Bare workflow:** Will fallback to using the `native` option for bare workflow React Native apps.\n *\n * @param options Additional options for configuring the path.\n * @return The `redirectUri` to use in an authentication request.\n *\n * @example\n * ```ts\n * const redirectUri = makeRedirectUri({\n * scheme: 'my-scheme',\n * path: 'redirect'\n * });\n * // Development Build: 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 * // Development Build: scheme2:///\n * // Expo Go: exp://localhost:19000\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 projectNameForProxy,\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({ urlPath: path, projectNameForProxy });\n}\n\n// @needsAudit\n/**\n * Build an `AuthRequest` and load it before returning.\n *\n * @param config A valid [`AuthRequestConfig`](#authrequestconfig) that specifies what provider to use.\n * @param issuerOrDiscovery A loaded [`DiscoveryDocument`](#discoverydocument) or issuer URL.\n * (Only `authorizationEndpoint` is required for requesting an authorization code).\n * @return Returns an instance of `AuthRequest` that can be used to prompt the user for authorization.\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 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\n// Provider specific types\nexport { GoogleAuthRequestConfig } from './providers/Google';\nexport { FacebookAuthRequestConfig } from './providers/Facebook';\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,MAAM,kBAAkB,CAAC;AAEtD,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,CAAC;AAChD,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AAEtD,cAAc;AACd;;;GAGG;AACH,MAAM,UAAU,OAAO;IACrB,kBAAkB,EAAE,CAAC;AACvB,CAAC;AAED,MAAM,CAAC,MAAM,mBAAmB,GAAG,kBAAkB,CAAC,mBAAmB,CAAC;AAE1E,2BAA2B;AAC3B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AAM,OAAO,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAC1C,OAAO,OAAO,CAAC;AACjB,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 Constants, { ExecutionEnvironment } from 'expo-constants';\nimport * as Linking from 'expo-linking';\nimport { Platform } from 'expo-modules-core';\nimport { dismissAuthSession } 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 sessionUrlProvider from './SessionUrlProvider';\n\n// @needsAudit\n/**\n * Cancels an active `AuthSession` if there is one. No return value, but if there is an active `AuthSession`\n * then the Promise returned by the `AuthSession.startAsync()` that initiated it resolves to `{ type: 'dismiss' }`.\n */\nexport function dismiss() {\n dismissAuthSession();\n}\n\nexport const getDefaultReturnUrl = sessionUrlProvider.getDefaultReturnUrl;\n\n// @needsAudit @docsMissing\n/**\n * Get the URL that your authentication provider needs to redirect to. For example: `https://auth.expo.io/@your-username/your-app-slug`. You can pass an additional path component to be appended to the default redirect URL.\n * > **Note** This method will throw an exception if you're using the bare workflow on native.\n *\n * @param path\n * @return\n *\n * @example\n * ```ts\n * const url = AuthSession.getRedirectUrl('redirect');\n *\n * // Managed: https://auth.expo.io/@your-username/your-app-slug/redirect\n * // Web: https://localhost:19006/redirect\n * ```\n *\n * @deprecated Use `makeRedirectUri()` instead.\n */\nexport function getRedirectUrl(path?: string): string {\n return sessionUrlProvider.getRedirectUrl({ urlPath: path });\n}\n\n// @needsAudit\n/**\n * Create a redirect url for the current platform and environment. You need to manually define the redirect that will be used in\n * a bare workflow React Native app, or an Expo standalone app, this is because it cannot be inferred automatically.\n * - **Web:** Generates a path based on the current `window.location`. For production web apps, you should hard code the URL as well.\n * - **Managed workflow:** 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 Go and standalone environments.\n * - **Bare workflow:** Will fallback to using the `native` option for bare workflow React Native apps.\n *\n * @param options Additional options for configuring the path.\n * @return The `redirectUri` to use in an authentication request.\n *\n * @example\n * ```ts\n * const redirectUri = makeRedirectUri({\n * scheme: 'my-scheme',\n * path: 'redirect'\n * });\n * // Development Build: my-scheme://redirect\n * // Expo Go: exp://127.0.0.1:8081/--/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 * // Development Build: scheme2:///\n * // Expo Go: exp://localhost:8081\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}: 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 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\n// @needsAudit\n/**\n * Build an `AuthRequest` and load it before returning.\n *\n * @param config A valid [`AuthRequestConfig`](#authrequestconfig) that specifies what provider to use.\n * @param issuerOrDiscovery A loaded [`DiscoveryDocument`](#discoverydocument) or issuer URL.\n * (Only `authorizationEndpoint` is required for requesting an authorization code).\n * @return Returns an instance of `AuthRequest` that can be used to prompt the user for authorization.\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\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\n// Provider specific types\nexport { GoogleAuthRequestConfig } from './providers/Google';\nexport { FacebookAuthRequestConfig } from './providers/Facebook';\n"]}
|
|
@@ -72,33 +72,18 @@ export type AuthSessionRedirectUriOptions = {
|
|
|
72
72
|
path?: string;
|
|
73
73
|
/**
|
|
74
74
|
* URI protocol `<scheme>://` that must be built into your native app.
|
|
75
|
-
* Passed to `Linking.createURL()` when `useProxy` is `false`.
|
|
76
75
|
*/
|
|
77
76
|
scheme?: string;
|
|
78
77
|
/**
|
|
79
|
-
* Optional native scheme
|
|
78
|
+
* Optional native scheme
|
|
80
79
|
* URI protocol `<scheme>://` that must be built into your native app.
|
|
81
|
-
* Passed to `Linking.createURL()` when `useProxy` is `false`.
|
|
82
80
|
*/
|
|
83
81
|
queryParams?: Record<string, string | undefined>;
|
|
84
82
|
/**
|
|
85
83
|
* Should the URI be triple slashed `scheme:///path` or double slashed `scheme://path`.
|
|
86
84
|
* Defaults to `false`.
|
|
87
|
-
* Passed to `Linking.createURL()` when `useProxy` is `false`.
|
|
88
85
|
*/
|
|
89
86
|
isTripleSlashed?: boolean;
|
|
90
|
-
/**
|
|
91
|
-
* Should use the \`auth.expo.io\` proxy.
|
|
92
|
-
* This is useful for testing managed native apps that require a custom URI scheme.
|
|
93
|
-
*
|
|
94
|
-
* @default false
|
|
95
|
-
* @deprecated This option will be removed in a future release, for more information check [the migration guide](https://expo.fyi/auth-proxy-migration).
|
|
96
|
-
*/
|
|
97
|
-
useProxy?: boolean;
|
|
98
|
-
/**
|
|
99
|
-
* Project name to use for the `auth.expo.io` proxy when `useProxy` is `true`.
|
|
100
|
-
*/
|
|
101
|
-
projectNameForProxy?: string;
|
|
102
87
|
/**
|
|
103
88
|
* Attempt to convert the Expo server IP address to localhost.
|
|
104
89
|
* This is useful for testing when your IP changes often, this will only work for iOS simulator.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthSession.types.d.ts","sourceRoot":"","sources":["../src/AuthSession.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAG/C,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;OAEG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AAGF;;;;;;;;GAQG;AACH,MAAM,MAAM,iBAAiB,GACzB;IACE;;OAEG;IACH,IAAI,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;CAClD,GACD;IACE;;OAEG;IACH,IAAI,EAAE,OAAO,GAAG,SAAS,CAAC;IAC1B;;OAEG;IACH,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB;;OAEG;IACH,KAAK,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;IACzB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B;;OAEG;IACH,cAAc,EAAE,aAAa,GAAG,IAAI,CAAC;IACrC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAGN;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAC1C;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd
|
|
1
|
+
{"version":3,"file":"AuthSession.types.d.ts","sourceRoot":"","sources":["../src/AuthSession.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MA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uthSession.types.ts"],"names":[],"mappings":"","sourcesContent":["import { AuthError } from './Errors';\nimport { TokenResponse } from './TokenRequest';\n\n// @needsAudit\nexport type AuthSessionOptions = {\n /**\n * The URL that points to the sign in page that you would like to open the user to.\n */\n authUrl: string;\n /**\n * The URL to return to the application. In managed apps, it's optional and defaults to output of [`Linking.createURL('expo-auth-session', params)`](./linking/#linkingcreateurlpath-namedparameters)\n * call with `scheme` and `queryParams` params. However, in the bare app, it's required - `AuthSession` needs to know where to wait for the response.\n * Hence, this method will throw an exception, if you don't provide `returnUrl`.\n */\n returnUrl?: string;\n /**\n * A boolean determining whether browsed website should be shown as separate entry in Android recents/multitasking view.\n * @default false\n * @platform android\n */\n showInRecents?: boolean;\n /**\n * Project name to use for the `auth.expo.io` proxy.\n */\n projectNameForProxy?: string;\n};\n\n// @needsAudit\n/**\n * Object returned after an auth request has completed.\n * - If the user cancelled the authentication session by closing the browser, the result is `{ type: 'cancel' }`.\n * - If the authentication is dismissed manually with `AuthSession.dismiss()`, the result is `{ type: 'dismiss' }`.\n * - If the authentication flow is successful, the result is `{ type: 'success', params: Object, event: Object }`.\n * - If the authentication flow is returns an error, the result is `{ type: 'error', params: Object, error: string, event: Object }`.\n * - If you call `AuthSession.startAsync()` more than once before the first call has returned, the result is `{ type: 'locked' }`,\n * because only one `AuthSession` can be in progress at any time.\n */\nexport type AuthSessionResult =\n | {\n /**\n * How the auth completed.\n */\n type: 'cancel' | 'dismiss' | 'opened' | 'locked';\n }\n | {\n /**\n * How the auth completed.\n */\n type: 'error' | 'success';\n /**\n * @deprecated Legacy error code query param, use `error` instead.\n */\n errorCode: string | null;\n /**\n * Possible error if the auth failed with type `error`.\n */\n error?: AuthError | null;\n /**\n * Query params from the `url` as an object.\n */\n params: Record<string, string>;\n /**\n * Returned when the auth finishes with an `access_token` property.\n */\n authentication: TokenResponse | null;\n /**\n * Auth URL that was opened\n */\n url: string;\n };\n\n// @needsAudit\n/**\n * Options passed to `makeRedirectUri`.\n */\nexport type AuthSessionRedirectUriOptions = {\n /**\n * Optional path to append to a URI. This will not be added to `native`.\n */\n path?: string;\n /**\n * URI protocol `<scheme>://` that must be built into your native app.\n
|
|
1
|
+
{"version":3,"file":"AuthSession.types.js","sourceRoot":"","sources":["../src/AuthSession.types.ts"],"names":[],"mappings":"","sourcesContent":["import { AuthError } from './Errors';\nimport { TokenResponse } from './TokenRequest';\n\n// @needsAudit\nexport type AuthSessionOptions = {\n /**\n * The URL that points to the sign in page that you would like to open the user to.\n */\n authUrl: string;\n /**\n * The URL to return to the application. In managed apps, it's optional and defaults to output of [`Linking.createURL('expo-auth-session', params)`](./linking/#linkingcreateurlpath-namedparameters)\n * call with `scheme` and `queryParams` params. However, in the bare app, it's required - `AuthSession` needs to know where to wait for the response.\n * Hence, this method will throw an exception, if you don't provide `returnUrl`.\n */\n returnUrl?: string;\n /**\n * A boolean determining whether browsed website should be shown as separate entry in Android recents/multitasking view.\n * @default false\n * @platform android\n */\n showInRecents?: boolean;\n /**\n * Project name to use for the `auth.expo.io` proxy.\n */\n projectNameForProxy?: string;\n};\n\n// @needsAudit\n/**\n * Object returned after an auth request has completed.\n * - If the user cancelled the authentication session by closing the browser, the result is `{ type: 'cancel' }`.\n * - If the authentication is dismissed manually with `AuthSession.dismiss()`, the result is `{ type: 'dismiss' }`.\n * - If the authentication flow is successful, the result is `{ type: 'success', params: Object, event: Object }`.\n * - If the authentication flow is returns an error, the result is `{ type: 'error', params: Object, error: string, event: Object }`.\n * - If you call `AuthSession.startAsync()` more than once before the first call has returned, the result is `{ type: 'locked' }`,\n * because only one `AuthSession` can be in progress at any time.\n */\nexport type AuthSessionResult =\n | {\n /**\n * How the auth completed.\n */\n type: 'cancel' | 'dismiss' | 'opened' | 'locked';\n }\n | {\n /**\n * How the auth completed.\n */\n type: 'error' | 'success';\n /**\n * @deprecated Legacy error code query param, use `error` instead.\n */\n errorCode: string | null;\n /**\n * Possible error if the auth failed with type `error`.\n */\n error?: AuthError | null;\n /**\n * Query params from the `url` as an object.\n */\n params: Record<string, string>;\n /**\n * Returned when the auth finishes with an `access_token` property.\n */\n authentication: TokenResponse | null;\n /**\n * Auth URL that was opened\n */\n url: string;\n };\n\n// @needsAudit\n/**\n * Options passed to `makeRedirectUri`.\n */\nexport type AuthSessionRedirectUriOptions = {\n /**\n * Optional path to append to a URI. This will not be added to `native`.\n */\n path?: string;\n /**\n * URI protocol `<scheme>://` that must be built into your native app.\n */\n scheme?: string;\n /**\n * Optional native scheme\n * URI protocol `<scheme>://` that must be built into your native app.\n */\n queryParams?: Record<string, string | undefined>;\n /**\n * Should the URI be triple slashed `scheme:///path` or double slashed `scheme://path`.\n * Defaults to `false`.\n */\n isTripleSlashed?: boolean;\n /**\n * Attempt to convert the Expo server IP address to localhost.\n * This is useful for testing when your IP changes often, this will only work for iOS simulator.\n *\n * @default false\n */\n preferLocalhost?: boolean;\n /**\n * Manual scheme to use in Bare and Standalone native app contexts. Takes precedence over all other properties.\n * You must define the URI scheme that will be used in a custom built native application or standalone Expo application.\n * The value should conform to your native app's URI schemes.\n * You can see conformance with `npx uri-scheme list`.\n */\n native?: string;\n};\n"]}
|
|
@@ -41,7 +41,7 @@ export class SessionUrlProvider {
|
|
|
41
41
|
}
|
|
42
42
|
const legacyExpoProjectFullName = options.projectNameForProxy ||
|
|
43
43
|
Constants.expoConfig?.originalFullName ||
|
|
44
|
-
Constants.__unsafeNoWarnManifest?.
|
|
44
|
+
Constants.__unsafeNoWarnManifest?.originalFullName;
|
|
45
45
|
if (!legacyExpoProjectFullName) {
|
|
46
46
|
let nextSteps = '';
|
|
47
47
|
if (__DEV__) {
|
|
@@ -56,7 +56,7 @@ export class SessionUrlProvider {
|
|
|
56
56
|
}
|
|
57
57
|
if (Constants.manifest2) {
|
|
58
58
|
nextSteps =
|
|
59
|
-
' Prefer AuthRequest
|
|
59
|
+
' Prefer AuthRequest in combination with an Expo Development Client build of your application.' +
|
|
60
60
|
' To continue using the AuthSession proxy, specify the project full name (@owner/slug) using the projectNameForProxy option.';
|
|
61
61
|
}
|
|
62
62
|
throw new Error('Cannot use the AuthSession proxy because the project full name is not defined.' + nextSteps);
|