From cbddd4d2c7e89e1472c417e996f7d911247c9499 Mon Sep 17 00:00:00 2001 From: Jonathan Ruddell Date: Mon, 15 Nov 2021 22:30:14 -0500 Subject: [PATCH] optimize useProxy var --- generators/app/templates/app/config/app-config.js.ejs | 5 +++-- .../app/templates/app/modules/login/login.utils.ts.ejs | 10 +++------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/generators/app/templates/app/config/app-config.js.ejs b/generators/app/templates/app/config/app-config.js.ejs index 1a356192b..2232646df 100644 --- a/generators/app/templates/app/config/app-config.js.ejs +++ b/generators/app/templates/app/config/app-config.js.ejs @@ -1,3 +1,4 @@ +import { Platform } from 'react-native'; import Constants from 'expo-constants'; // load extra config from the app.json file @@ -9,8 +10,8 @@ export default { <%_ if (context.authenticationType === 'oauth2') { _%> // leave blank if using Keycloak nativeClientId: '', - // use expo auth proxy with login, disable to log completely out of oauth provider - useExpoAuthProxy: true, + // use expo auth proxy with login, disable to enable logout completely from oauth provider + useExpoAuthProxy: Platform.select({ web: false, default: true }), <%_ } _%> // use fixtures instead of real API requests useFixtures: false, diff --git a/generators/app/templates/app/modules/login/login.utils.ts.ejs b/generators/app/templates/app/modules/login/login.utils.ts.ejs index 206bbad7e..9ff9b4564 100644 --- a/generators/app/templates/app/modules/login/login.utils.ts.ejs +++ b/generators/app/templates/app/modules/login/login.utils.ts.ejs @@ -68,10 +68,8 @@ export async function getDiscovery(issuer: string): Promise { } export async function doOauthPkceFlow(clientId: string, issuer: string): Promise { - // whether or not to use the expo proxy - const useProxy = Platform.select({ web: false, default: AppConfig.useExpoAuthProxy }); // set up redirect uri - const redirectUri = makeRedirectUri({ useProxy }); + const redirectUri = makeRedirectUri({ useProxy: AppConfig.useExpoAuthProxy }); // fetch oauth issuer information from discovery endpoint const discovery = await getDiscovery(issuer); // set up the IDP url, prepare codeVerifier and state @@ -86,13 +84,11 @@ export async function doOauthPkceFlow(clientId: string, issuer: string): Promise export async function logoutFromIdp(clientId: string, issuer: string, idToken: string) { // logging out of IDP is not supported by the expo auth proxy - if (Platform.OS === 'web' || !AppConfig.useExpoAuthProxy) { + if (!AppConfig.useExpoAuthProxy) { const discovery = await getDiscovery(issuer); const { endSessionEndpoint } = discovery; - // whether or not to use the expo proxy - const useProxy = Platform.select({ web: false, default: AppConfig.useExpoAuthProxy }); // set up redirect uri - const redirectUri = makeRedirectUri({ useProxy }); + const redirectUri = makeRedirectUri({ useProxy: AppConfig.useExpoAuthProxy }); await WebBrowser.openAuthSessionAsync(`${endSessionEndpoint}?id_token_hint=${idToken}&client_id=${clientId}&post_logout_redirect_uri=${redirectUri}`, redirectUri); } }