AnsweredAssumed Answered

IdentityManager: keep user signed in after browser refresh

Question asked by eemeli.pyottio on Feb 5, 2020
Latest reply on Aug 6, 2020 by City_of_Melbourne

Hi,

 

I have developed an application that shows a WebMap from ArcGIS portal by using the ArcGIS JS API. I implemented authentication flow by using the IdentityManager. I'm able to get the token and register it and the secured resource then loads correctly.

 

However, when I refresh the page in browser the registered token/credential is not available anymore. Is there a way to keep the sign in status as long as the token is valid? Or is it so that I need to store the access token (and possibly other needed details) my self in client side and then just validate the token before request to JS API and register it again?

 

What is the recommended way to do this?

 

Regards,

Eemeli

 

identityManager.checkSignInStatus( portalUrl + "/sharing" ).then( function ( credential ) {

               // User is already authenticated.
               identityManager.registerToken( {
                    token: credential.token,
                    server: portalUrl
               } );
               resolve( true );

          } ).catch( function( error ) {

               // User not authenticated, login the user.
               identityManager.getCredential( portalUrl + "/sharing" ).then( function ( credential ) {

                    // Register the token after authentication.
                    // The token is valid 60 min by default.
                    identityManager.registerToken( {
                         token: credential.token,
                         server: portalUrl + "/sharing/rest",
                         expires: credential.expires,
                         ssl: credential.ssl,
                         userId: credential.userId
                    } );
                    resolve( true );

               } );
          } );

Outcomes