@@ -24,6 +24,7 @@ import { createOAuthError } from '../../../src/providers/cognito/utils/oauth/cre
24
24
import { signInWithRedirect } from '../../../src/providers/cognito/apis/signInWithRedirect' ;
25
25
import type { OAuthStore } from '../../../src/providers/cognito/utils/types' ;
26
26
import { mockAuthConfigWithOAuth } from '../../mockData' ;
27
+ import { type AuthPrompt } from '../../../src/types/inputs' ;
27
28
28
29
jest . mock ( '@aws-amplify/core/internals/utils' , ( ) => ( {
29
30
...jest . requireActual ( '@aws-amplify/core/internals/utils' ) ,
@@ -107,6 +108,13 @@ describe('signInWithRedirect', () => {
107
108
const mockCodeChallenge = 'code_challenge' ;
108
109
const mockToCodeChallenge = jest . fn ( ( ) => mockCodeChallenge ) ;
109
110
111
+ const promptTypes = [
112
+ 'NONE' ,
113
+ 'LOGIN' ,
114
+ 'CONSENT' ,
115
+ 'SELECT_ACCOUNT' ,
116
+ ] as const satisfies readonly AuthPrompt [ ] ;
117
+
110
118
beforeAll ( ( ) => {
111
119
mockGenerateState . mockReturnValue ( mockState ) ;
112
120
mockGenerateCodeVerifier . mockReturnValue ( {
@@ -189,6 +197,42 @@ describe('signInWithRedirect', () => {
189
197
expect ( mockUrlSafeEncode ) . toHaveBeenCalledWith ( expectedCustomState ) ;
190
198
} ) ;
191
199
200
+ it ( 'includes prompt parameter in authorization URL' , async ( ) => {
201
+ for ( const prompt of promptTypes ) {
202
+ const expectedCustomProvider = 'PieAuth' ;
203
+ await signInWithRedirect ( {
204
+ provider : { custom : expectedCustomProvider } ,
205
+ options : { prompt } ,
206
+ } ) ;
207
+ const [ oauthUrl ] = mockOpenAuthSession . mock . calls [ 0 ] ;
208
+ const cognitoPrompt = prompt . toLowerCase ( ) ;
209
+ expect ( oauthUrl ) . toStrictEqual (
210
+ `https://oauth.domain.com/oauth2/authorize?redirect_uri=http%3A%2F%2Flocalhost%3A3000%2F&response_type=code&client_id=userPoolClientId&identity_provider=${ expectedCustomProvider } &scope=phone%20email%20openid%20profile%20aws.cognito.signin.user.admin&prompt=${ cognitoPrompt } &state=oauth_state&code_challenge=code_challenge&code_challenge_method=S256` ,
211
+ ) ;
212
+ mockOpenAuthSession . mockClear ( ) ;
213
+ }
214
+ } ) ;
215
+
216
+ it ( 'calls assertUserNotAuthenticated based on prompt value' , async ( ) => {
217
+ for ( const prompt of promptTypes ) {
218
+ const expectedCustomProvider = 'PieAuth' ;
219
+ await signInWithRedirect ( {
220
+ provider : { custom : expectedCustomProvider } ,
221
+ options : { prompt } ,
222
+ } ) ;
223
+
224
+ expect ( mockAssertUserNotAuthenticated ) . not . toHaveBeenCalled ( ) ;
225
+
226
+ mockAssertUserNotAuthenticated . mockClear ( ) ;
227
+ mockOpenAuthSession . mockClear ( ) ;
228
+ }
229
+
230
+ // Test no options at all
231
+ await signInWithRedirect ( ) ;
232
+ expect ( mockAssertUserNotAuthenticated ) . toHaveBeenCalled ( ) ;
233
+ mockAssertUserNotAuthenticated . mockClear ( ) ;
234
+ } ) ;
235
+
192
236
describe ( 'specifications on Web' , ( ) => {
193
237
describe ( 'side effect' , ( ) => {
194
238
it ( 'attaches oauth listener to the Amplify singleton' , async ( ) => {
0 commit comments