Skip to content

Commit 4e128d4

Browse files
committed
fix(expo): parse AppAuth redirect URL schemes
1 parent 44c1c52 commit 4e128d4

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

.changeset/fix-expo-swift-appdelegate.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"react-native-app-auth": patch
33
---
44

5-
Fix Expo config plugin support for Swift AppDelegate templates that omit `public` before the AppDelegate class declaration.
5+
Fix Expo config plugin support for Swift AppDelegate templates that omit `public` before the AppDelegate class declaration, and correctly extract URL schemes from AppAuth redirect URLs that use a single slash.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { getRedirectUrlScheme } from '../index';
2+
3+
describe('getRedirectUrlScheme', () => {
4+
it('extracts a scheme from single-slash AppAuth redirect URLs', () => {
5+
expect(getRedirectUrlScheme('io.identityserver.demo:/oauthredirect')).toBe('io.identityserver.demo');
6+
});
7+
8+
it('extracts a scheme from double-slash redirect URLs', () => {
9+
expect(getRedirectUrlScheme('rnaa-demo://oauthredirect')).toBe('rnaa-demo');
10+
});
11+
});

packages/react-native-app-auth/plugin/src/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,20 @@ import { withAppAuthAppBuildGradle } from './android';
1111

1212
const packageJson = require('../../package.json');
1313

14+
export const getRedirectUrlScheme = (redirectUrl?: string): string | undefined => {
15+
return redirectUrl?.split(':')[0];
16+
};
17+
1418
const withAppAuth: AppAuthConfigPlugin = (config, props) => {
19+
const redirectUrlScheme = getRedirectUrlScheme(props?.redirectUrls?.[0]);
20+
1521
// Transform redirectUrls configuration to platform-specific format
1622
const transformedProps: AppAuthProps = props?.redirectUrls ? {
1723
ios: {
18-
urlScheme: props.redirectUrls[0]?.split('://')[0], // Extract scheme from first URL
24+
urlScheme: redirectUrlScheme,
1925
},
2026
android: {
21-
appAuthRedirectScheme: props.redirectUrls[0]?.split('://')[0], // Extract scheme from first URL
27+
appAuthRedirectScheme: redirectUrlScheme,
2228
},
2329
...props,
2430
} : (props || {});
@@ -36,4 +42,4 @@ const withAppAuth: AppAuthConfigPlugin = (config, props) => {
3642
]);
3743
};
3844

39-
export default createRunOncePlugin(withAppAuth, packageJson.name, packageJson.version);
45+
export default createRunOncePlugin(withAppAuth, packageJson.name, packageJson.version);

0 commit comments

Comments
 (0)