1import Constants, { ExecutionEnvironment } from 'expo-constants'; 2import * as Linking from 'expo-linking'; 3import { Platform } from 'expo-modules-core'; 4import { dismissAuthSession } from 'expo-web-browser'; 5import { AuthRequest } from './AuthRequest'; 6import { CodeChallengeMethod, Prompt, ResponseType, } from './AuthRequest.types'; 7import { fetchDiscoveryAsync, resolveDiscoveryAsync, } from './Discovery'; 8import { generateHexStringAsync } from './PKCE'; 9import sessionUrlProvider from './SessionUrlProvider'; 10// @needsAudit 11/** 12 * Cancels an active `AuthSession` if there is one. 13 */ 14export function dismiss() { 15 dismissAuthSession(); 16} 17export const getDefaultReturnUrl = sessionUrlProvider.getDefaultReturnUrl; 18// @needsAudit @docsMissing 19/** 20 * 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. 21 * > **Note** This method will throw an exception if you're using the bare workflow on native. 22 * 23 * @param path 24 * @return 25 * 26 * @example 27 * ```ts 28 * const url = AuthSession.getRedirectUrl('redirect'); 29 * 30 * // Managed: https://auth.expo.io/@your-username/your-app-slug/redirect 31 * // Web: https://localhost:19006/redirect 32 * ``` 33 * 34 * @deprecated Use `makeRedirectUri()` instead. 35 */ 36export function getRedirectUrl(path) { 37 return sessionUrlProvider.getRedirectUrl({ urlPath: path }); 38} 39// @needsAudit 40/** 41 * Create a redirect url for the current platform and environment. You need to manually define the redirect that will be used in 42 * a bare workflow React Native app, or an Expo standalone app, this is because it cannot be inferred automatically. 43 * - **Web:** Generates a path based on the current `window.location`. For production web apps, you should hard code the URL as well. 44 * - **Managed workflow:** Uses the `scheme` property of your app config. 45 * - **Bare workflow:** Will fallback to using the `native` option for bare workflow React Native apps. 46 * 47 * @param options Additional options for configuring the path. 48 * @return The `redirectUri` to use in an authentication request. 49 * 50 * @example 51 * ```ts 52 * const redirectUri = makeRedirectUri({ 53 * scheme: 'my-scheme', 54 * path: 'redirect' 55 * }); 56 * // Development Build: my-scheme://redirect 57 * // Expo Go: exp://127.0.0.1:8081/--/redirect 58 * // Web dev: https://localhost:19006/redirect 59 * // Web prod: https://yourwebsite.com/redirect 60 * 61 * const redirectUri2 = makeRedirectUri({ 62 * scheme: 'scheme2', 63 * preferLocalhost: true, 64 * isTripleSlashed: true, 65 * }); 66 * // Development Build: scheme2:/// 67 * // Expo Go: exp://localhost:8081 68 * // Web dev: https://localhost:19006 69 * // Web prod: https://yourwebsite.com 70 * ``` 71 */ 72export function makeRedirectUri({ native, scheme, isTripleSlashed, queryParams, path, preferLocalhost, } = {}) { 73 if (Platform.OS !== 'web' && 74 native && 75 [ExecutionEnvironment.Standalone, ExecutionEnvironment.Bare].includes(Constants.executionEnvironment)) { 76 // Should use the user-defined native scheme in standalone builds 77 return native; 78 } 79 const url = Linking.createURL(path || '', { 80 isTripleSlashed, 81 scheme, 82 queryParams, 83 }); 84 if (preferLocalhost) { 85 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/); 86 // Only replace if an IP address exists 87 if (ipAddress?.length) { 88 const [protocol, path] = url.split(ipAddress[0]); 89 return `${protocol}localhost${path}`; 90 } 91 } 92 return url; 93} 94// @needsAudit 95/** 96 * Build an `AuthRequest` and load it before returning. 97 * 98 * @param config A valid [`AuthRequestConfig`](#authrequestconfig) that specifies what provider to use. 99 * @param issuerOrDiscovery A loaded [`DiscoveryDocument`](#discoverydocument) or issuer URL. 100 * (Only `authorizationEndpoint` is required for requesting an authorization code). 101 * @return Returns an instance of `AuthRequest` that can be used to prompt the user for authorization. 102 */ 103export async function loadAsync(config, issuerOrDiscovery) { 104 const request = new AuthRequest(config); 105 const discovery = await resolveDiscoveryAsync(issuerOrDiscovery); 106 await request.makeAuthUrlAsync(discovery); 107 return request; 108} 109export { useAutoDiscovery, useAuthRequest } from './AuthRequestHooks'; 110export { AuthError, TokenError } from './Errors'; 111export { AuthRequest, CodeChallengeMethod, Prompt, ResponseType, resolveDiscoveryAsync, fetchDiscoveryAsync, generateHexStringAsync, }; 112export { 113// Token classes 114TokenResponse, AccessTokenRequest, RefreshTokenRequest, RevokeTokenRequest, 115// Token methods 116revokeAsync, refreshAsync, exchangeCodeAsync, fetchUserInfoAsync, } from './TokenRequest'; 117// Token types 118export * from './TokenRequest.types'; 119//# sourceMappingURL=AuthSession.js.map