new AuthenticationContext(config)
Creates a new AuthenticationContext object.
Parameters:
Name | Type | Description |
---|---|---|
config |
config | Configuration options for AuthenticationContext |
Members
-
CONSTANTS :string
-
Enum for storage constants
Type:
- string
- Source:
Properties:
Name Type Default Description ACCESS_TOKEN
string access_token EXPIRES_IN
string expires_in ID_TOKEN
string id_token ERROR_DESCRIPTION
string error_description SESSION_STATE
string session_state STORAGE
string OBJECTLIT RESOURCE_DELIMETER
string | LOADFRAME_TIMEOUT
string 6000 TOKEN_RENEW_STATUS_CANCELED
string Canceled TOKEN_RENEW_STATUS_COMPLETED
string Completed TOKEN_RENEW_STATUS_IN_PROGRESS
string In Progress LOGGING_LEVEL
string OBJECTLIT LEVEL_STRING_MAP
string OBJECTLIT POPUP_WIDTH
string 483 POPUP_HEIGHT
string 600 -
REQUEST_TYPE :string
-
Enum for request type
Type:
- string
Methods
-
acquireToken(resource, callback)
-
Acquires token from the cache if it is not expired. Otherwise sends request to AAD to obtain a new token.
Parameters:
Name Type Description resource
string ResourceUri identifying the target resource callback
tokenCallback The callback provided by the caller. It will be called with token or error. -
acquireTokenPopup(resource, extraQueryParameters, callback)
-
Acquires token (interactive flow using a popUp window) by sending request to AAD to obtain a new token.
Parameters:
Name Type Description resource
string ResourceUri identifying the target resource extraQueryParameters
string extraQueryParameters to add to the authentication request callback
tokenCallback The callback provided by the caller. It will be called with token or error. -
acquireTokenRedirect(resource, extraQueryParameters)
-
Acquires token (interactive flow using a redirect) by sending request to AAD to obtain a new token. In this case the callback passed in the Authentication request constructor will be called.
Parameters:
Name Type Description resource
string ResourceUri identifying the target resource extraQueryParameters
string extraQueryParameters to add to the authentication request -
clearCache()
-
Clears cache items.
-
clearCacheForResource(resource)
-
Clears cache items for a given resource.
Parameters:
Name Type Description resource
string a URI that identifies the resource. -
error(message, error)
-
Logs messages when Logging Level is set to 0.
Parameters:
Name Type Description message
string Message to log. error
string Error to log. -
getCachedToken(resource) → {string}
-
Gets token for the specified resource from the cache.
Parameters:
Name Type Description resource
string A URI that identifies the resource for which the token is requested. Returns:
token if if it exists and not expired, otherwise null.- Type
- string
-
getCachedUser() → {User}
-
If user object exists, returns it. Else creates a new user object by decoding id_token from the cache.
Returns:
user object- Type
- User
-
getLoginError() → {string}
-
Gets login error
Returns:
error message related to login.- Type
- string
-
getRequestInfo() → {RequestInfo}
-
Creates a requestInfo object from the URL fragment and returns it.
Returns:
an object created from the redirect response from AAD comprising of the keys - parameters, requestType, stateMatch, stateResponse and valid.- Type
- RequestInfo
-
getResourceForEndpoint(endpoint) → {string}
-
Gets resource for given endpoint if mapping is provided with config.
Parameters:
Name Type Description endpoint
string The URI for which the resource Id is requested. Returns:
resource for this API endpoint.- Type
- string
-
getUser(callback)
-
Calls the passed in callback with the user object or error message related to the user.
Parameters:
Name Type Description callback
userCallback The callback provided by the caller. It will be called with user or error. -
handleWindowCallback(hash)
-
This method must be called for processing the response received from AAD. It extracts the hash, processes the token or error, saves it in the cache and calls the registered callbacks with the result.
Parameters:
Name Type Argument Default Description hash
string <optional>
window.location.hash Hash fragment of Url. -
info(message)
-
Logs messages when Logging Level is set to 2.
Parameters:
Name Type Description message
string Message to log. -
isCallback(hash) → {Boolean}
-
Checks if the URL fragment contains access token, id token or error_description.
Parameters:
Name Type Description hash
string Hash passed from redirect page Returns:
true if response contains id_token, access_token or error, false otherwise.- Type
- Boolean
-
log(level, message, error)
-
Checks the Logging Level, constructs the Log message and logs it. Users need to implement/override this method to turn on Logging.
Parameters:
Name Type Description level
number Level can be set 0,1,2 and 3 which turns on 'error', 'warning', 'info' or 'verbose' level logging respectively. message
string Message to log. error
string Error to log. -
login()
-
Initiates the login process by redirecting the user to Azure AD authorization endpoint.
-
logOut()
-
Redirects user to logout endpoint. After logout, it will redirect to postLogoutRedirectUri if added as a property on the config object.
-
promptUser(urlNavigate)
-
Redirects the browser to Azure AD authorization endpoint.
Parameters:
Name Type Description urlNavigate
string Url of the authorization endpoint. -
registerCallback(resource, expectedState, callback)
-
Adds the passed callback to the array of callbacks for the specified resource and puts the array on the window object.
Parameters:
Name Type Description resource
string A URI that identifies the resource for which the token is requested. expectedState
string A unique identifier (guid). callback
tokenCallback The callback provided by the caller. It will be called with token or error. -
saveTokenFromHash()
-
Saves token or error received in the response from AAD in the cache. In case of id_token, it also creates the user object.
-
verbose(message)
-
Logs messages when Logging Level is set to 3.
Parameters:
Name Type Description message
string Message to log. -
warn(message)
-
Logs messages when Logging Level is set to 1.
Parameters:
Name Type Description message
string Message to log.