@@ -172,6 +172,7 @@ describe('routeFor SSO authentication ', () => {
172172 it ( 'Options added through settings should be passed in the url' , ( ) => {
173173 const settings = {
174174 auth : {
175+ flow : 'authorization-code' ,
175176 options : [ 'one' ] ,
176177 } ,
177178 baseUrl : 'https://localhost/' ,
@@ -192,6 +193,7 @@ describe('routeFor SSO authentication ', () => {
192193 it ( 'should fallback to the originUrl if returnUrl is not provided' , ( ) => {
193194 const settings = {
194195 auth : {
196+ flow : 'authorization-code' ,
195197 options : [ 'one' ] ,
196198 } ,
197199 baseUrl : 'https://localhost/' ,
@@ -210,6 +212,7 @@ describe('routeFor SSO authentication ', () => {
210212 it ( 'should use the returnUrl if provided' , ( ) => {
211213 const settings = {
212214 auth : {
215+ flow : 'authorization-code' ,
213216 options : [ 'one' ] ,
214217 } ,
215218 baseUrl : 'https://localhost/' ,
@@ -229,6 +232,7 @@ describe('routeFor SSO authentication ', () => {
229232 it ( "should not add the options from the search param if they don't exist in the current url params" , ( ) => {
230233 const settings = {
231234 auth : {
235+ flow : 'authorization-code' ,
232236 options : [ 'one' ] ,
233237 } ,
234238 baseUrl : 'https://localhost/' ,
@@ -245,7 +249,10 @@ describe('routeFor SSO authentication ', () => {
245249 } ) ;
246250
247251 it ( 'Should render a login url' , ( ) => {
248- const settings = { auth : { } , baseUrl : 'https://localhost' } ;
252+ const settings = {
253+ auth : { flow : 'authorization-code' } ,
254+ baseUrl : 'https://localhost' ,
255+ } ;
249256 const searchParams = new URLSearchParams ( ) ;
250257
251258 const sso = routeForAuthentication ( { settings, searchParams } ) ;
@@ -254,7 +261,10 @@ describe('routeFor SSO authentication ', () => {
254261 } ) ;
255262
256263 it ( 'Should add return URL search param' , ( ) => {
257- const settings = { auth : { } , baseUrl : 'https://localhost' } ;
264+ const settings = {
265+ auth : { flow : 'authorization-code' } ,
266+ baseUrl : 'https://localhost' ,
267+ } ;
258268
259269 const searchParams = new URLSearchParams ( ) ;
260270 searchParams . set ( 'returnUrl' , 'https://localhost/some/path' ) ;
@@ -271,7 +281,10 @@ describe('routeFor SSO authentication ', () => {
271281 } ) ;
272282
273283 it ( 'Should not add return URL search param if undefined' , ( ) => {
274- const settings = { auth : { } , baseUrl : 'https://localhost' } ;
284+ const settings = {
285+ auth : { flow : 'authorization-code' } ,
286+ baseUrl : 'https://localhost' ,
287+ } ;
275288
276289 const searchParams = new URLSearchParams ( ) ;
277290 const sso = routeForAuthentication ( { settings, searchParams } ) ;
@@ -283,6 +296,7 @@ describe('routeFor SSO authentication ', () => {
283296 it ( 'test of the signin flow' , ( ) => {
284297 const settings = {
285298 auth : {
299+ flow : 'authorization-code' ,
286300 options : [ 'organization_name' , 'invitation' ] ,
287301 } ,
288302 baseUrl : 'https://localhost/' ,
@@ -302,6 +316,56 @@ describe('routeFor SSO authentication ', () => {
302316 ) ;
303317 } ) ;
304318
319+ describe ( 'implicit oidc flow' , ( ) => {
320+ it ( 'should add a nonce' , ( ) => {
321+ const settings = {
322+ auth : {
323+ flow : 'implicit' ,
324+ authorizationUrl : 'https://accounts.google.com/o/oauth2/v2/auth' ,
325+ scopes : [ 'openid' , 'email' , 'profile' ] ,
326+ } ,
327+ baseUrl : 'https://localhost' ,
328+ } ;
329+
330+ const searchParams = new URLSearchParams ( ) ;
331+
332+ const sso = routeForAuthentication ( {
333+ settings,
334+ searchParams,
335+ } ) ;
336+
337+ const ssoUrl = new URL ( sso ) ;
338+ expect ( window . localStorage . getItem ( 'nonce' ) ) . toBe (
339+ ssoUrl . searchParams . get ( 'nonce' ) ,
340+ ) ;
341+ } ) ;
342+
343+ it ( 'should manage state' , ( ) => {
344+ const settings = {
345+ auth : {
346+ flow : 'implicit' ,
347+ authorizationUrl : 'https://accounts.google.com/o/oauth2/v2/auth' ,
348+ scopes : [ 'openid' , 'email' , 'profile' ] ,
349+ } ,
350+ baseUrl : 'https://localhost' ,
351+ } ;
352+
353+ const searchParams = new URLSearchParams ( ) ;
354+ searchParams . set ( 'returnUrl' , 'https://localhost/some/path' ) ;
355+
356+ const sso = routeForAuthentication ( {
357+ settings,
358+ searchParams,
359+ } ) ;
360+
361+ const ssoUrlStateKey = new URL ( sso ) . searchParams . get ( 'state' ) ;
362+ expect ( ssoUrlStateKey ) . not . toBeNull ( ) ;
363+ expect ( window . sessionStorage . getItem ( ssoUrlStateKey as string ) ) . toBe (
364+ 'https://localhost/some/path' ,
365+ ) ;
366+ } ) ;
367+ } ) ;
368+
305369 describe ( 'routeForLoginPage' , ( ) => {
306370 afterEach ( ( ) => {
307371 vi . clearAllMocks ( ) ;
0 commit comments