Skip to main content
Version: v4.6

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.

ParameterRequiredTypeDescription
ctxNoCtxContext, such as namespaces and authentication token information.
Examples
const res = await IafSession.clearLastError(ctx);

deleteSession

Deletes the current User and Auth token from the session.

ParameterRequiredTypeDescription
ctxNoCtxContext, such as namespaces and authentication token information.
Examples
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.

ParameterRequiredTypeDescription
hashYesStringEnter the URL's URI fragment identifier, which is the series of characters after the hash symbol.
Returns

String -

getAccountSettingsUrl

Gets a URL redirect for the Account Settings page.

ParameterRequiredTypeDescription
returnUrlNoStringThe client application's URL. When the end user exits the account settings, this URL returns the user to the application.
Returns

String - Account settings URL

Examples
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.

ParameterRequiredTypeDescription
appIdYesStringPass the Application's id
ctxNoCtxContext, such as namespaces and authentication token information.
Examples
const appToken = await IafSession.getAppToken(app._id, ctx);

getAuth

Gets the Authorization header's value from the session Auth token.

ParameterRequiredTypeDescription
ctxNoCtxContext, such as namespaces and authentication token information.
Returns

Object - The Authorization header as a JSON object.

Examples
const authToken = await IafSession.getAuthToken(ctx);

getAuthToken

Gets an Auth token from the session context.

ParameterRequiredTypeDescription
ctxNoCtxContext, such as namespaces and authentication token information.
Returns

Object -

Examples
const authToken = await IafSession.getAuthToken(ctx);

getAuthUrl

Gets the OAuth2 Auth URL for the implicit client.

ParameterRequiredTypeDescription
clientUrlYesStringPass the client application's URL. If the login is successful, the user is redirected to the URL with the access token.
appIdYesStringPass an application id. The app must be registered with passport service to get a token specific to the app.
Returns

String - The Auth URL

Examples
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.

Returns

{```itemServiceOrigin```, ```passportServiceOrigin```, ```fileServiceOrigin```, ```datasourceServiceOrigin```, ```requestErrorCallback```} -

getCurrentUser

Gets the current User from the session storage.

ParameterRequiredTypeDescription
ctxNoCtxContext, such as namespaces and authentication token information.
Returns

Promise<Object> - A JSON object that contains the current user's data

Examples
const currentUser = await IafSession.getCurrentUser(ctx);

getLastError

Gets the latest session error messages.

ParameterRequiredTypeDescription
ctxNoCtxContext, such as namespaces and authentication token information.
Examples
const lastError = await IafSession.getLastError(ctx);

getSessionStorage

Gets a property's value from an object in the session storage.

ParameterRequiredTypeDescription
objectYesStringPass the property name.
keyNoStringUse to access a key a nested object
ctxNoCtxContext, such as namespaces and authentication token information.
Returns

Object -

Examples
// Store the project in the session and retrieve its namespaces
IafSession.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.

ParameterRequiredTypeDescription
ctxNoCtxContext, such as namespaces and authentication token information.
Returns

boolean - Returns true if the user is currently logged and false if the user is not.

Examples
const loggedIn = await IafSession.loggedIn(ctx);
loggedIn && console.log('user logged in')

loggedInAs

Get the logged in User's email.

ParameterRequiredTypeDescription
ctxNoCtxContext, such as namespaces and authentication token information.
Returns

String - The logged in User's email address.

Examples
const userEmail = await IafSession.getSessionStorage(ctx);

logout

Logs out the current User and invalidates the Auth token.

ParameterRequiredTypeDescription
ctxNoCtxContext, such as namespaces and authentication token information.
Examples
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.

ParameterRequiredTypeDescription
tokenYesStringPass an Auth token.
ctxNoCtxContext, such as namespaces and authentication token information.
Examples
IafSession.setAuthToken(token, ctx);

setConfig

Sets an IafFetch config with the REST endpoint base URLs that you call from the IafFetch API.

ParameterRequiredTypeDescription
configYesObject
Examples
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.

ParameterRequiredTypeDescription
userInfoYesUserPass a User object.
ctxNoCtxContext, such as namespaces and authentication token information.
Examples
await IafSession.setCurrentUser(user, ctx);

setErrorCallback

Sets a custom error handling callback function you pass in the IafFetch config object.

ParameterRequiredTypeDescription
funcYesfunctionerrorCallbackFunc(error)

setSessionData

Sets the session data for the current User when you pass an Auth token.

ParameterRequiredTypeDescription
tokenYesStringAuth token
ctxNoCtxContext, such as namespaces and authentication token information.
Returns

Promise<User> -

Examples
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.

ParameterRequiredTypeDescription
keyYesStringKey
valueYesObjectValue
ctxNoCtxContext, such as namespaces and authentication token information.
Returns

any - void

Examples
IafSession.setSessionStorage(key, value, ctx);