IafSession
se the IafSession API to manage session data, auth tokens, clients, session users, applications, and error messages on the platform.
clearLastError#
Clears the latest session error messages.
| Parameter | Required | Type | Description |
|---|---|---|---|
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
const res = await IafSession.clearLastError(ctx);deleteSession#
Deletes the current User and Auth token from the session.
| Parameter | Required | Type | Description |
|---|---|---|---|
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
const res = await IafSession.deleteSession(ctx);extractToken#
Extracts the OAuth2 token's value when a user redirects from an OAuth2 provider, which includes the Passport Service.
| Parameter | Required | Type | Description |
|---|---|---|---|
| hash | Yes | String | Enter the URL's URI fragment identifier, which is the series of characters after the hash symbol. |
String -
getAccountSettingsUrl#
Gets a URL redirect for the Account Settings page.
| Parameter | Required | Type | Description |
|---|---|---|---|
| returnUrl | No | String | The client application's URL. When the end user exits the account settings, this URL returns the user to the application. |
String - Account settings URL
const url = IafPassSvc.getAccountSettingsUrl("https://general-dev.company.com/ipa-dt");getAppToken#
Gets a token for a specific application for a User by exchanging any valid access token.
| Parameter | Required | Type | Description |
|---|---|---|---|
| appId | Yes | String | Pass the Application's id |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
const appToken = await IafSession.getAppToken(app._id, ctx);getAuth#
Gets the Authorization header's value from the session Auth token.
| Parameter | Required | Type | Description |
|---|---|---|---|
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Object - The Authorization header as a JSON object.
const authToken = await IafSession.getAuthToken(ctx);getAuthToken#
Gets an Auth token from the session context.
| Parameter | Required | Type | Description |
|---|---|---|---|
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Object -
const authToken = await IafSession.getAuthToken(ctx);getAuthUrl#
Gets the OAuth2 Auth URL for the implicit client.
| Parameter | Required | Type | Description |
|---|---|---|---|
| clientUrl | Yes | String | Pass the client application's URL. If the login is successful, the user is redirected to the URL with the access token. |
| appId | Yes | String | Pass an application id. The app must be registered with passport service to get a token specific to the app. |
String - The Auth URL
const url = IafSession.getAuthUrl('https://general-dev.company.com/ipa-dt', app._id)getConfig#
Gets the IafFetch config that contains REST end point base URLs.
{itemServiceOrigin, passportServiceOrigin, fileServiceOrigin, datasourceServiceOrigin, requestErrorCallback} -
getCurrentUser#
Gets the current User from the session storage.
| Parameter | Required | Type | Description |
|---|---|---|---|
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Promise<Object> - A JSON object that contains the current user's data
const currentUser = await IafSession.getCurrentUser(ctx);getLastError#
Gets the latest session error messages.
| Parameter | Required | Type | Description |
|---|---|---|---|
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
const lastError = await IafSession.getLastError(ctx);getSessionStorage#
Gets a property's value from an object in the session storage.
| Parameter | Required | Type | Description |
|---|---|---|---|
| object | Yes | String | Pass the property name. |
| key | No | String | Use to access a key a nested object |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Object -
// Store the project in the session and retrieve its namespacesIafSession.setSessionStorage('project', project);const namespaces = IafSession.getSessionStorage('project', '_namespaces', ctx);loggedIn#
Checks if the User is currently logged in by checking if the User's token is in the session.
| Parameter | Required | Type | Description |
|---|---|---|---|
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
boolean - Returns true if the user is currently logged and false if the user is not.
const loggedIn = await IafSession.loggedIn(ctx);loggedIn && console.log('user logged in')loggedInAs#
Get the logged in User's email.
| Parameter | Required | Type | Description |
|---|---|---|---|
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
String - The logged in User's email address.
const userEmail = await IafSession.getSessionStorage(ctx);logout#
Logs out the current User and invalidates the Auth token.
| Parameter | Required | Type | Description |
|---|---|---|---|
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
IafSession.logout(ctx);setAuthToken#
Sets an Auth token in the session. Method calls from the IafFetch API use this Auth token for REST API calls.
| Parameter | Required | Type | Description |
|---|---|---|---|
| token | Yes | String | Pass an Auth token. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
IafSession.setAuthToken(token, ctx);setConfig#
Sets an IafFetch config with the REST endpoint base URLs that you call from the IafFetch API.
| Parameter | Required | Type | Description |
|---|---|---|---|
| config | Yes | Object |
let config = { itemServiceOrigin: 'https://general-dev.company.com', passportServiceOrigin: 'https://general-dev.company.com', fileServiceOrigin: 'https://general-dev.company.com', datasourceServiceOrigin: 'https://general-dev.company.com', graphicsServiceOrigin: 'https://general-dev.company.com', appRoot: 'http://localhost:8082/ipa-dev'};
IafSession.setConfig(config);setCurrentUser#
Sets a user as the current session user.
| Parameter | Required | Type | Description |
|---|---|---|---|
| userInfo | Yes | User | Pass a User object. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
await IafSession.setCurrentUser(user, ctx);setErrorCallback#
Sets a custom error handling callback function you pass in the IafFetch config object.
| Parameter | Required | Type | Description |
|---|---|---|---|
| func | Yes | function | errorCallbackFunc(error) |
setSessionData#
Sets the session data for the current User when you pass an Auth token.
| Parameter | Required | Type | Description |
|---|---|---|---|
| token | Yes | String | Auth token |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
const res = await IafSession.setSessionData(token, ctx);setSessionStorage#
Sets an object in the session. In a browser environment, the object stores in the sessionStorage. In non-browser environments, the object stores in ctx storage.
| Parameter | Required | Type | Description |
|---|---|---|---|
| key | Yes | String | Key |
| value | Yes | Object | Value |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
any - void
IafSession.setSessionStorage(key, value, ctx);