SessionManager

Class

The SessionManager is used to manage user sign in sessions.

Methods

MethodReturnsNotes
void

Clear all sessions

generateSeverSessionByPortalSession(portalSession, serverUrl, credentialsParamForGenerateToken)
Promise<UserSession>

Generate server session with owning system portal session.

generateToken(portalUrl, getTokenParam, credentialsParam)
Promise<any>

Generate token.

getClientIdByUrl(portalUrl)
string

Get a valid client id for portal url

UserSession

Return main session.

UserSession

Return session by url.

string

Get session key from a session.

UserSession[]

Return all sessions.

handleAuthError(error, popup)
Promise<UserSession>

When you need to handle the error caused by sign in, you can catch the error and call this method. This method will try to sign in to get a new session.

removeSession(session)
boolean

Remove the session from session manager.

signIn(fromUrl, popup, desUrl, clientId?)
Promise<UserSession>

Start OAuth sign in flow and return the user session.

void

Sign out from main portal.

useDialogToSetClientIdToConnectiosOfAppConfigAndSignIn(portalUrl, needToSignIn?, serviceUrl?)
Promise<any>

Popup a dialog to set client id to app config

getInstance()
 static 

Get singleton instance.

clearSessions

clearSessions(): void

Clear all sessions

Returns 
void

generateSeverSessionByPortalSession

generateSeverSessionByPortalSession(portalSessionUserSession, serverUrlstring, credentialsParamForGenerateTokenstring): Promise<UserSession>

Generate server session with owning system portal session.

Parameters
ParameterTypeDefaultNotes
portalSession
UserSession

A session of ArcGIS REST JS 'UserSession' representing a logged in user.

serverUrl
string
credentialsParamForGenerateToken
string
'same-origin'
Returns 
Promise<UserSession>

generateToken

generateToken(portalUrlstring, getTokenParamstring, credentialsParamstring): Promise<any>

Generate token.

Parameters
ParameterTypeDefault
portalUrl
string
getTokenParam
string
''
credentialsParam
string
Returns 
Promise<any>

getClientIdByUrl

getClientIdByUrl(portalUrlstring): string

Get a valid client id for portal url

Parameters
ParameterType
portalUrl
string
Returns 
string

getMainSession

getMainSession(): UserSession

Return main session.

The main session is session of the portal that the app connects to.

Returns 
UserSession

(https://esri.github.io/arcgis-rest-js/api/auth/UserSession) representing a logged in user.

getSessionByUrl

getSessionByUrl(urlstring): UserSession

Return session by url.

Parameters
ParameterType
url
string
Returns 
UserSession

(https://esri.github.io/arcgis-rest-js/api/auth/UserSession) representing a logged in user.

getSessionKeyFromSession

getSessionKeyFromSession(sessionUserSession): string

Get session key from a session.

Parameters
ParameterTypeNotes
session
UserSession

A session of ArcGIS REST JS 'UserSession' representing a logged in user.

Returns 
string

getSessions

getSessions(): UserSession[]

Return all sessions.

Returns 
UserSession[]

Array of ArcGIS REST JS 'UserSession' representing the logged in users.

handleAuthError

handleAuthError(errorany, popupboolean): Promise<UserSession>

When you need to handle the error caused by sign in, you can catch the error and call this method. This method will try to sign in to get a new session.

Parameters
ParameterTypeDefault
error
any
popup
boolean
true
Returns 
Promise<UserSession>

removeSession

removeSession(sessionUserSession): boolean

Remove the session from session manager.

Parameters
ParameterTypeNotes
session
UserSession

A session of ArcGIS REST JS 'UserSession' representing a logged in user.

Returns 
boolean

signIn

signIn(fromUrlstring, popupboolean, desUrlstring, clientId?string): Promise<UserSession>

Start OAuth sign in flow and return the user session.

Parameters
ParameterTypeDefaultNotes
fromUrl
string
'/'

The page you start sign in

popup
boolean
true

If 'true', the window will popup, or, it will redirect to sign in page

desUrl
string
...

The url you want to sign in

clientId
string
Returns 
Promise<UserSession>

signOut

signOut(): void

Sign out from main portal.

Returns 
void

useDialogToSetClientIdToConnectiosOfAppConfigAndSignIn

useDialogToSetClientIdToConnectiosOfAppConfigAndSignIn(portalUrlstring, needToSignIn?boolean, serviceUrl?string): Promise<any>

Popup a dialog to set client id to app config

Parameters
ParameterTypeNotes
portalUrl
string

portal url

needToSignIn
boolean

indicates whether need to sign-in

serviceUrl
string

service url

Returns 
Promise<any>

getInstance static

getInstance(): SessionManager

Get singleton instance.

Returns 
SessionManager

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.