Skip to content

Commit

Permalink
optimize useProxy var
Browse files Browse the repository at this point in the history
  • Loading branch information
ruddell committed Nov 22, 2021
1 parent e1c741b commit cbddd4d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
5 changes: 3 additions & 2 deletions generators/app/templates/app/config/app-config.js.ejs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Platform } from 'react-native';
import Constants from 'expo-constants';

// load extra config from the app.json file
Expand All @@ -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,
Expand Down
10 changes: 3 additions & 7 deletions generators/app/templates/app/modules/login/login.utils.ts.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ export async function getDiscovery(issuer: string): Promise<DiscoveryDocument> {
}

export async function doOauthPkceFlow(clientId: string, issuer: string): Promise<AuthSession.TokenResponse> {
// 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
Expand All @@ -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);
}
}

0 comments on commit cbddd4d

Please sign in to comment.