Class
The  SessionManager  is used to manage user sign in sessions.
Methods
| Method | Returns | Notes | 
|---|---|---|
| addFromCredential(credential, from, serverInfo?, oAuthInfo?) | Promise<ArcGISIdentityManager> | Create a session from ArcGIS Maps SDK for JavaScript credential | 
| clearSessions() | void | Clear all sessions | 
| generateSeverSessionByPortalSession(portalSession, serverUrl, credentialsParamForGenerateToken) | Promise<ArcGISIdentityManager> | 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 | 
| getMainSession() | ArcGISIdentityManager | Return main session. | 
| getSessionByUrl(url) | ArcGISIdentityManager | Return session by url. | 
| getSessionKeyFromSession(session) | string | Get session key from a session. | 
| getSessions() | ArcGISIdentityManager[] | Return all sessions. | 
| getSessionType(session) | SessionType | Return session type according to a session | 
| getSignInErrorByCode(errorCode) | SignInError | Get the sign-in error by providing the sign-in error code. | 
| getSignInErrorCodeByAuthError(error) | SignInErrorCode | Get the sign-in error by providing the authentication error. | 
| handleAuthError(error, popup) | Promise<ArcGISIdentityManager> | 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. | 
| isSameSession(session1, session2) | boolean | Return true if the two sessions are equal. | 
| isSignInPromptBlocked() | boolean | return true if the sign-in prompt is blocked only effects on app env, always return false in builder env | 
| isValidTokenFromStorage(portalUrl) | Promise<boolean> | Sends a request to check the token of the session from storage. | 
| nonOAuthSignIn(desUrl, forceLogin?) | Promise<any> | Start non-OAuth sign in flow and return the user session. It use esri request to sign-in resource | 
| removeSession(session) | boolean | Remove the session from session manager. | 
| signIn(signInParams) | Promise<ArcGISIdentityManager> | Start OAuth2 sign-in flow and return the user session. | 
| signInByResourceUrl(resourceUrl, owningSystemUrl?, forceLogin?) | Promise<ArcGISIdentityManager> | Start OAuth sign in flow by a resource url and return the user session. | 
| signOut() | void | Sign out from main portal. | 
| useDialogToSetClientIdToConnectionsOfAppConfig(portalUrl) | Promise<any> | Popup a dialog to set client id to app config | 
| getInstance() | SessionManager | Get singleton instance. | 
addFromCredential
Class MethodaddFromCredential(credential: ICredential | Credential, from: SessionChangedReasonType, serverInfo?: ArcGISServerInfo, oAuthInfo?: any): Promise<ArcGISIdentityManager>Create a session from ArcGIS Maps SDK for JavaScript credential
Parameters
| Parameter | Type | 
|---|---|
| credential | ICredential | Credential | 
| from | SessionChangedReasonType | 
| server | ArcGISServerInfo | 
| o | any | 
Returns
Promise<ArcGISIdentityManager>generateSeverSessionByPortalSession
Class MethodgenerateSeverSessionByPortalSession(portalSession: ArcGISIdentityManager, serverUrl: string, credentialsParamForGenerateToken: string): Promise<ArcGISIdentityManager>Generate server session with owning system portal session.
Parameters
| Parameter | Type | Default | Notes | 
|---|---|---|---|
| portal | ArcGISIdentityManager |  | A session of ArcGIS REST JS 'ArcGISIdentityManager' representing a logged in user. | 
| server | string |  | |
| credentials | string | 'same-origin' | 
Returns
Promise<ArcGISIdentityManager>generateToken
Class MethodgenerateToken(portalUrl: string, getTokenParam: string, credentialsParam: string): Promise<any>Generate token.
Parameters
| Parameter | Type | Default | 
|---|---|---|
| portal | string |  | 
| get | string | '' | 
| credentials | string | 'same-origin' | 
Returns
Promise<any>getClientIdByUrl
Class MethodgetClientIdByUrl(portalUrl: string): stringGet a valid client id for portal url
Parameters
| Parameter | Type | Notes | 
|---|---|---|
| portal | string | portal url | 
Returns
stringgetMainSession
Class MethodgetMainSession(): ArcGISIdentityManagerReturn main session.
The main session is session of the portal that the app connects to.
Returns
ArcGISIdentityManagerArcGIS REST JS 'ArcGISIdentityManager' representing a logged in user.
getSessionByUrl
Class MethodgetSessionByUrl(url: string): ArcGISIdentityManagerReturn session by url.
Parameters
| Parameter | Type | 
|---|---|
| url | string | 
Returns
ArcGISIdentityManagerArcGIS REST JS 'ArcGISIdentityManager' representing a logged in user.
getSessionKeyFromSession
Class MethodgetSessionKeyFromSession(session: ArcGISIdentityManager): stringGet session key from a session.
Parameters
| Parameter | Type | Notes | 
|---|---|---|
| session | ArcGISIdentityManager | A session of ArcGIS REST JS 'ArcGISIdentityManager' representing a logged in user. | 
Returns
stringgetSessions
Class MethodgetSessions(): ArcGISIdentityManager[]Return all sessions.
Returns
ArcGISIdentityManager[]Array of ArcGIS REST JS 'ArcGISIdentityManager' representing the logged in users.
getSessionType
Class MethodgetSessionType(session: ArcGISIdentityManager): SessionTypeReturn session type according to a session
Parameters
| Parameter | Type | 
|---|---|
| session | ArcGISIdentityManager | 
Returns
SessionTypegetSignInErrorByCode
Class MethodgetSignInErrorByCode(errorCode: SignInErrorCode): SignInErrorGet the sign-in error by providing the sign-in error code.
Parameters
| Parameter | Type | Default | Notes | 
|---|---|---|---|
| error | SignInErrorCode | Sign | The sign-in error code. | 
Returns
SignInErrorgetSignInErrorCodeByAuthError
Class MethodgetSignInErrorCodeByAuthError(error: any): SignInErrorCodeGet the sign-in error by providing the authentication error.
Parameters
| Parameter | Type | Notes | 
|---|---|---|
| error | any | 
 | 
Returns
SignInErrorCodehandleAuthError
Class MethodhandleAuthError(error: any, popup: boolean): Promise<ArcGISIdentityManager>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
| Parameter | Type | Default | 
|---|---|---|
| error | any |  | 
| popup | boolean | true | 
Returns
Promise<ArcGISIdentityManager>isSameSession
Class MethodisSameSession(session1: ArcGISIdentityManager, session2: ArcGISIdentityManager): booleanReturn true if the two sessions are equal.
Parameters
| Parameter | Type | 
|---|---|
| session1 | ArcGISIdentityManager | 
| session2 | ArcGISIdentityManager | 
Returns
booleanisSignInPromptBlocked
Class MethodisSignInPromptBlocked(): booleanreturn true if the sign-in prompt is blocked only effects on app env, always return false in builder env
Returns
booleanisValidTokenFromStorage
Class MethodisValidTokenFromStorage(portalUrl: string): Promise<boolean>Sends a request to check the token of the session from storage.
Parameters
| Parameter | Type | 
|---|---|
| portal | string | 
Returns
Promise<boolean>nonOAuthSignIn
Class MethodnonOAuthSignIn(desUrl: string, forceLogin?: boolean): Promise<any>Start non-OAuth sign in flow and return the user session. It use esri request to sign-in resource
Parameters
| Parameter | Type | Notes | 
|---|---|---|
| des | string | The url you want to sign in | 
| force | boolean | 
Returns
Promise<any>removeSession
Class MethodremoveSession(session: ArcGISIdentityManager): booleanRemove the session from session manager.
Parameters
| Parameter | Type | Notes | 
|---|---|---|
| session | ArcGISIdentityManager | A session of ArcGIS REST JS 'ArcGISIdentityManager' representing a logged in user. | 
Returns
booleansignIn
Class MethodsignIn(signInParams: SignInParams): Promise<ArcGISIdentityManager>Start OAuth2 sign-in flow and return the user session.
Parameters
| Parameter | Type | Default | Notes | 
|---|---|---|---|
| sign | SignInParams | {} | The properties for sign in. | 
Returns
Promise<ArcGISIdentityManager>signInByResourceUrl
Class MethodsignInByResourceUrl(resourceUrl: string, owningSystemUrl?: string, forceLogin?: boolean): Promise<ArcGISIdentityManager>Start OAuth sign in flow by a resource url and return the user session.
Parameters
| Parameter | Type | Notes | 
|---|---|---|
| resource | string | a resource url can be: service url: federated or non-federated; portal item url; | 
| owning | string | owning system url for federated service url | 
| force | boolean | 
Returns
Promise<ArcGISIdentityManager>useDialogToSetClientIdToConnectionsOfAppConfig
Class MethoduseDialogToSetClientIdToConnectionsOfAppConfig(portalUrl: string): Promise<any>Popup a dialog to set client id to app config
Parameters
| Parameter | Type | Notes | 
|---|---|---|
| portal | string | portal url | 
Returns
Promise<any>getInstance
getInstance(): SessionManagerGet singleton instance.
Returns
SessionManager