From 6e6986f3bf5ac20b82f20e2520ff972564ae4ab4 Mon Sep 17 00:00:00 2001 From: geovannifuentesQred Date: Wed, 24 Jul 2024 10:36:47 +0200 Subject: [PATCH 1/3] fix redirect issue on Android --- .../auth/src/providers/cognito/apis/signInWithRedirect.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/auth/src/providers/cognito/apis/signInWithRedirect.ts b/packages/auth/src/providers/cognito/apis/signInWithRedirect.ts index cab4f018ee7..30e8f5de584 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithRedirect.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithRedirect.ts @@ -1,6 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +import { Platform } from 'react-native'; import { Amplify, OAuthConfig } from '@aws-amplify/core'; import { AuthAction, @@ -87,7 +88,11 @@ const oauthSignIn = async ({ : randomState; const { value, method, toCodeChallenge } = generateCodeVerifier(128); - const redirectUri = getRedirectUrl(oauthConfig.redirectSignIn); + + const redirectUri = + Platform.OS === 'android' + ? oauthConfig.redirectSignIn[0] + : getRedirectUrl(oauthConfig.redirectSignIn); if (isBrowser()) oAuthStore.storeOAuthInFlight(true); oAuthStore.storeOAuthState(state); From 1c4fd1d56725c7c270329e279fe67ebe01eb55ab Mon Sep 17 00:00:00 2001 From: geovannifuentesQred Date: Wed, 24 Jul 2024 10:58:06 +0200 Subject: [PATCH 2/3] add option to skip redirect url validation --- .../providers/cognito/apis/signInWithRedirect.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/auth/src/providers/cognito/apis/signInWithRedirect.ts b/packages/auth/src/providers/cognito/apis/signInWithRedirect.ts index 30e8f5de584..41eb99d124a 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithRedirect.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithRedirect.ts @@ -1,7 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { Platform } from 'react-native'; import { Amplify, OAuthConfig } from '@aws-amplify/core'; import { AuthAction, @@ -34,9 +33,11 @@ import { listenForOAuthFlowCancellation } from '../utils/oauth/cancelOAuthFlow'; * * @throws AuthTokenConfigException - Thrown when the user pool config is invalid. * @throws OAuthNotConfigureException - Thrown when the oauth config is invalid. + * @param skipRedirectUrlValidation - Skip the redirect URL validation. Default is false. */ export async function signInWithRedirect( input?: SignInWithRedirectInput, + skipRedirectUrlValidation = false, ): Promise { const authConfig = Amplify.getConfig().Auth?.Cognito; assertTokenProviderConfig(authConfig); @@ -58,6 +59,7 @@ export async function signInWithRedirect( provider, customState: input?.customState, preferPrivateSession: input?.options?.preferPrivateSession, + skipRedirectUrlValidation, }); } @@ -67,12 +69,14 @@ const oauthSignIn = async ({ clientId, customState, preferPrivateSession, + skipRedirectUrlValidation, }: { oauthConfig: OAuthConfig; provider: string; clientId: string; customState?: string; preferPrivateSession?: boolean; + skipRedirectUrlValidation?: boolean; }) => { const { domain, redirectSignIn, responseType, scopes } = oauthConfig; const randomState = generateState(); @@ -89,10 +93,9 @@ const oauthSignIn = async ({ const { value, method, toCodeChallenge } = generateCodeVerifier(128); - const redirectUri = - Platform.OS === 'android' - ? oauthConfig.redirectSignIn[0] - : getRedirectUrl(oauthConfig.redirectSignIn); + const redirectUri = skipRedirectUrlValidation + ? oauthConfig.redirectSignIn[0] + : getRedirectUrl(oauthConfig.redirectSignIn); if (isBrowser()) oAuthStore.storeOAuthInFlight(true); oAuthStore.storeOAuthState(state); From 77493cc36b1a18900a266764e08ecef019cd128d Mon Sep 17 00:00:00 2001 From: geovannifuentesQred Date: Wed, 24 Jul 2024 14:09:16 +0200 Subject: [PATCH 3/3] increase package size limit for OAuth Auth Flow --- packages/aws-amplify/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/aws-amplify/package.json b/packages/aws-amplify/package.json index b35b2ba395f..bf1e2d3eeb0 100644 --- a/packages/aws-amplify/package.json +++ b/packages/aws-amplify/package.json @@ -455,7 +455,7 @@ "name": "[Auth] OAuth Auth Flow (Cognito)", "path": "./dist/esm/auth/index.mjs", "import": "{ signInWithRedirect, signOut, fetchAuthSession }", - "limit": "21.47 kB" + "limit": "21.52 kB" }, { "name": "[Storage] copy (S3)",