UNPKG

react-native-app-auth

Version:

React Native bridge for AppAuth for supporting any OAuth 2 provider

44 lines (43 loc) 2.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.withAppAuthAppDelegate = void 0; const config_plugins_1 = require("@expo/config-plugins"); const expo_version_1 = require("../expo-version"); const codeModIOs = require('@expo/config-plugins/build/ios/codeMod'); const withAppDelegateSwift = rootConfig => { return (0, config_plugins_1.withAppDelegate)(rootConfig, config => { let { contents } = config.modResults; if (!contents.includes('RNAppAuthAuthorizationFlowManager')) { const replaceText = 'class AppDelegate: ExpoAppDelegate'; contents = contents.replace(replaceText, `${replaceText}, RNAppAuthAuthorizationFlowManager`); const replaceText2 = 'return super.application(app, open: url, options: options) || RCTLinkingManager.application(app, open: url, options: options)'; contents = contents.replace(replaceText2, `if let authorizationFlowManagerDelegate = self.authorizationFlowManagerDelegate { if authorizationFlowManagerDelegate.resumeExternalUserAgentFlow(with: url) { return true } } ${replaceText2}`); const replaceText3 = 'var reactNativeFactory: RCTReactNativeFactory?'; contents = contents.replace(replaceText3, `${replaceText3}\n\n public weak var authorizationFlowManagerDelegate: RNAppAuthAuthorizationFlowManagerDelegate?`); } config.modResults.contents = contents; return config; }); }; const withAppAuthAppDelegate = rootConfig => { if ((0, expo_version_1.isExpo53OrLater)(rootConfig)) { return withAppDelegateSwift(rootConfig); } return (0, config_plugins_1.withAppDelegate)(rootConfig, config => { let { contents } = config.modResults; // insert the code that handles the custom scheme redirections contents = codeModIOs.insertContentsInsideObjcFunctionBlock(contents, 'application:openURL:options:', `// react-native-app-auth if ([self.authorizationFlowManagerDelegate resumeExternalUserAgentFlowWithURL:url]) { return YES; } `, { position: 'head' }); config.modResults.contents = contents; return config; }); }; exports.withAppAuthAppDelegate = withAppAuthAppDelegate;