SessionManager
Class
The SessionManager
is used to manage user sign in sessions.
Methods
Method | Returns | Notes |
---|---|---|
| void | Clear all sessions |
| Promise<UserSession> | Generate server session with owning system portal session. |
| Promise<any> | Generate token. |
| 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. |
| SignInError | Get the sign-in error by providing the sign-in error code. |
| SignInErrorCode | Get the sign-in error by providing the authentication error. |
| 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. |
| boolean | Remove the session from session manager. |
| Promise<UserSession> | Start OAuth sign in flow and return the user session. |
| void | Sign out from main portal. |
| Promise<any> | Popup a dialog to set client id to app config |
| Get singleton instance. |
generateSeverSessionByPortalSession
generateSeverSessionByPortalSession(portalSession: UserSession, serverUrl: string, credentialsParamForGenerateToken: string): Promise<UserSession>
Generate server session with owning system portal session.
Parameters
Parameter | Type | Default | Notes |
---|---|---|---|
portal | UserSession |
| A session of ArcGIS REST JS 'UserSession' representing a logged in user. |
server | string |
| |
credentials | string | 'same-origin' |
Returns
Promise<UserSession>
generateToken
generateToken(portalUrl: string, getTokenParam: string, credentialsParam: string): Promise<any>
Generate token.
Parameters
Parameter | Type | Default | Notes |
---|---|---|---|
portal | string |
| |
get | string | '' | |
credentials | string |
|
Returns
Promise<any>
getClientIdByUrl
getClientIdByUrl(portalUrl: string): string
Get a valid client id for portal url
Parameters
Parameter | Type |
---|---|
portal | 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(url: string): UserSession
Return session by url.
Parameters
Parameter | Type | Notes |
---|---|---|
url | string |
Returns
UserSession
(https://esri.github.io/arcgis-rest-js/api/auth/UserSession) representing a logged in user.
getSessionKeyFromSession
getSessionKeyFromSession(session: UserSession): string
Get session key from a session.
Parameters
Parameter | Type | Notes |
---|---|---|
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.
getSignInErrorByCode
getSignInErrorByCode(errorCode: SignInErrorCode): SignInError
Get the sign-in error by providing the sign-in error code.
Parameters
Parameter | Type | Notes |
---|---|---|
error | SignInErrorCode | The sign-in error code. |
Returns
SignInError
getSignInErrorCodeByAuthError
getSignInErrorCodeByAuthError(error: any): SignInErrorCode
Get the sign-in error by providing the authentication error.
Parameters
Parameter | Type | Notes |
---|---|---|
error | any |
|
Returns
SignInErrorCode
handleAuthError
handleAuthError(error: any, popup: boolean): 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
Parameter | Type | Default |
---|---|---|
error | any |
|
popup | boolean | true |
Returns
Promise<UserSession>
removeSession
removeSession(session: UserSession): boolean
Remove the session from session manager.
Parameters
Parameter | Type | Notes |
---|---|---|
session | UserSession | A session of ArcGIS REST JS 'UserSession' representing a logged in user. |
Returns
boolean
signIn
signIn(fromUrl: string, popup: boolean, desUrl: string, clientId?: string, forceLogin?: boolean): Promise<UserSession>
Start OAuth sign in flow and return the user session.
Parameters
Parameter | Type | Default | Notes |
---|---|---|---|
from | string | window.jimu | The page you start sign in |
popup | boolean | true | If 'true', the window will popup, or, it will redirect to sign in page |
des | string | ... | The url you want to sign in |
client | string |
| |
force | boolean |
|
Returns
Promise<UserSession>
useDialogToSetClientIdToConnectiosOfAppConfigAndSignIn
useDialogToSetClientIdToConnectiosOfAppConfigAndSignIn(portalUrl: string, needToSignIn?: boolean, serviceUrl?: string): Promise<any>
Popup a dialog to set client id to app config
Parameters
Parameter | Type | Notes |
---|---|---|
portal | string | portal url |
need | boolean | indicates whether need to sign-in |
service | string | service url |
Returns
Promise<any>