ESM: import esriId from "@arcgis/core/identity/IdentityManager.js";
CDN: const esriId = await $arcgis.import("@arcgis/core/identity/IdentityManager.js");
Class: @arcgis/core/identity/IdentityManager
Since: ArcGIS Maps SDK for JavaScript 4.0
This object provides the framework and helper methods used in managing user credentials for the following resources:
Secured ArcGIS.com or ArcGIS Enterprise portal resources (e.g. web maps).
ArcGIS Server resources secured using token-based authentication. Note that only ArcGIS Server versions 10 SP 1 and greater are supported. If your application accesses services from different domains, it is deemed a cross-domain request and you need to setup a proxy or use CORS (if supported by browser). If CORS is supported, the Identity Manager knows to make a request to the token service over https.
Authentication requests over http are prevented because sensitive data sent via GET can be viewed in server logs. To prevent this, the Identity Manager requires that you use POST over https to ensure your credentials are secure. View the proxy pages and CORS help topic for more details.
The IdentityManager module is slightly different than other modules in the API. Instead of returning a class constructor, it returns a singleton instance that has already been created by this module.
Dialog box widget used to challenge the user for their credentials when the application attempts to access a secure resource.
IdentityManager tokenValidity NumberThe suggested lifetime of the token in minutes.
IdentityManager Property DetailsDialog box widget used to challenge the user for their credentials when the application attempts to access a secure resource. This property is available after the dialog-create event has fired.
tokenValidity Number
The suggested lifetime of the token in minutes.
Returns a credential if the user has already signed in to access the given resource and is allowed to do so when using the given application id.
IdentityManager checkSignInStatus() Promise<Credential>Returns the Credential if the user has already signed in to access the given resource.
IdentityManager destroyCredentials()Destroys all credentials.
IdentityManager disablePostMessageAuth()Disables the use of window.postMessage
to serve authentication requests that were enabled by enablePostMessageAuth.
Emits an event on the instance.
IdentityManager enablePostMessageAuth()Enables the IdentityManager to serve authentication requests for the given resource from apps running in child iframes.
IdentityManager findCredential() CredentialReturns the Credential for the resource identified by the specified url.
IdentityManager findOAuthInfo() OAuthInfoReturns the OAuthInfo configuration for the passed in Portal server URL.
IdentityManager findServerInfo() ServerInfoReturns information about the server that is hosting the specified URL.
IdentityManager generateToken() Promise<Object>Returns an object containing a token and its expiration time.
IdentityManager getCredential() Promise<Credential>Returns a Credential object that can be used to access the secured resource identified by the input URL.
IdentityManager hasEventListener() BooleanIndicates whether there is an event listener on the instance that matches the provided event name.
IdentityManager initialize()Call this method during application initialization with the JSON previously obtained from the toJSON() method used to re-hydrate the state of IdentityManager.
IdentityManager isBusy() BooleanIndicates if the IdentityManager is busy accepting user input.
IdentityManager on() ObjectRegisters an event handler on the instance.
IdentityManager registerOAuthInfos()Registers OAuth 2.0 configurations.
IdentityManager registerServers()Register secure servers and the token endpoints.
IdentityManager registerToken()Registers the given OAuth 2.0 access token or ArcGIS Server token with the IdentityManager.
IdentityManager setOAuthRedirectionHandler()Once a user successfully logs in, they are redirected back to the application.
IdentityManager setOAuthResponseHash()Use this method in the popup callback page to pass the token and other values back to the IdentityManager.
IdentityManager setProtocolErrorHandler()When accessing secured resources, the IdentityManager may prompt for username and password and send them to the server using a secure connection.
IdentityManager toJSON() ObjectReturn properties of this object in JSON format.
IdentityManager Method Details checkAppAccess(resUrl, appId){Promise<Object>}
Since: ArcGIS Maps SDK for JavaScript 4.10 IdentityManager since 4.0, checkAppAccess added at 4.10.
Returns a credential if the user has already signed in to access the given resource and is allowed to do so when using the given application id. In addition, it also returns a boolean
, viewOnly
, property that indicates whether the app is only viewable. The default is false
. If the user has not signed in or does not have access, then the promise will be rejected and its error callback will be called.
This scenario is generally not common unless you are building a licensed app. Also, please note that this method should only be used if your application is on the same domain as *.arcgis.com
or ArcGIS Enterprise Server and is only applicable to applications registered as items in the Esri
organization.
Parameters
The resource URL.
The registered OAuth application id.
Returns
Type Description Promise<Object> Resolves to an object which contains the following properties: Property Type Description credential Credential The credential of the user. viewOnly boolean Indicates whether the app is only viewable. Default isfalse
.
checkSignInStatus(resUrl){Promise<Credential>}
Returns the Credential if the user has already signed in to access the given resource. If the user has not signed in, then the promise will be rejected and its error callback will be called.
Returns
Type Description Promise<Credential> Resolves to the returned credential of the signed-in user. destroyCredentials()
Destroys all credentials. It is good practice to call this method if working with an application that contains sign-out functionality as any tokens generated via OAuth will automatically be revoked.
disablePostMessageAuth()
Since: ArcGIS Maps SDK for JavaScript 4.19 IdentityManager since 4.0, disablePostMessageAuth added at 4.19.
Disables the use of window.postMessage
to serve authentication requests that were enabled by enablePostMessageAuth. This should be called to prevent memory leaks in SPA routing apps when they need to transition routes. Setting this this helps clean up and remove any windows's
message
event listeners that enablePostMessageAuth added.
Please refer to the topic, Passing authentication to IFramed apps for additional information. The main differences are:
Embed App boots and Requests Auth
, does not apply when using the ArcGIS Maps SDK for JavaScript. emit(type, event){Boolean}
Since: ArcGIS Maps SDK for JavaScript 4.5 IdentityManager since 4.0, emit added at 4.5.
Emits an event on the instance. This method should only be used when creating subclasses of this class.
Parameters
The name of the event.
optionalThe event payload.
Returns
Type Description Booleantrue
if a listener was notified
enablePostMessageAuth(resUrl)
Since: ArcGIS Maps SDK for JavaScript 4.19 IdentityManager since 4.0, enablePostMessageAuth added at 4.19.
Enables the IdentityManager to serve authentication requests for the given resource from apps running in child iframes. The only apps that will be allowed to request the credential are ones that are either running at *.arcgis.com
, or are running at the same origin as the host app. Requests from other apps will be ignored.
Only one resource may be authenticated in this manner at any one time. The URL of the resource should be used as the value of a parameter named arcgis-auth-portal
that is included in the iframe's src
URL. The iframe's src
URL should also include another parameter named arcgis-auth-origin
with a value of window.location.origin
. Both of these parameter values should be URL-encoded using encodeURIComponent
. These parameters are used by the IdentityManager, or the UserSession running in the iframe app when it needs the user's authentication to access a given resource.
Please refer to the topic, Passing authentication to IFramed apps for additional information. The main differences are:
Embed App boots and Requests Auth
, does not apply when using the ArcGIS Maps SDK for JavaScript.Parameter
optionalThe resource URL. Default value is https://www.arcgis.com/sharing/rest
.
findCredential(url, userId){Credential}
Returns the Credential for the resource identified by the specified url. Optionally, you can provide a userId to find credentials for a specific user.
Parameters
The URL to a server.
optionalThe userId for which you want to obtain credentials.
Returns
Type Description Credential The credential for the resource identified by the specified URL. findOAuthInfo(url){OAuthInfo}
Returns the OAuthInfo configuration for the passed in Portal server URL.
Returns
Type Description OAuthInfo The OAuthInfo configuration for the passed in Portal server URL.Example
const esriId = await $arcgis.import("@arcgis/core/identity/IdentityManager.js");
let portalURL = "https://host.arcgis.com";
findOAuthInfo = function (){
let oAuthInfo = esriId.findOAuthInfo(portalURL)
console.log(oAuthInfo.toJSON())
}
findServerInfo(url){ServerInfo}
Returns information about the server that is hosting the specified URL.
Returns
Type Description ServerInfo The ServerInfo configuration for the passed in server URL. generateToken(serverInfo, userInfo, options){Promise<Object>}
Returns an object containing a token and its expiration time. It is necessary to provide the ServerInfo object that contains a token service URL and a user info object containing username and password. This is a helper method typically called by sub-classes to generate tokens.
Parameters
Specification
A ServerInfo object that contains a token service URL.
A user info object containing a user name and password.
optionalSee the table below for the structure of this object.
Specification
The server URL.
The server token.
Indicates if the server requires SSL.
Returns
Type Description Promise<Object> Resolves to an object containing a token and expiration time. getCredential(url, options){Promise<Credential>}
Returns a Credential object that can be used to access the secured resource identified by the input URL.
Parameters
Specification
The URL for the secure resource
optionalSee the table below for the structure of the options object.
Specification
optionalError object returned by the server from a previous attempt to fetch the given URL.
optionalDefault Value: true
If set to false, the user will not be shown a dialog before the OAuth popup window is opened.
optionalToken used for a previous unsuccessful attempt to fetch the given URL.
Returns
Type Description Promise<Credential> Resolves to an object containing a Credential that can be used to access the secured resource identified by the input URL. hasEventListener(type){Boolean}
Indicates whether there is an event listener on the instance that matches the provided event name.
Returns
Type Description Boolean Returns true if the class supports the input event. initialize(json)
Call this method during application initialization with the JSON previously obtained from the toJSON() method used to re-hydrate the state of IdentityManager.
Indicates if the IdentityManager is busy accepting user input. For example, it returns true
if the user has invoked signIn and is waiting for a response.
Returns
Type Description Boolean Whether IdentityManager is currently accepting user input. on(type, listener){Object}
Registers an event handler on the instance. Call this method to hook an event with a listener.
Returns
Type Description Object Returns an event handler with aremove()
method that should be called to stop listening for the event(s). Property Type Description remove Function When called, removes the listener from the event.
Example
view.on("click", function(event){
// event is the event handle returned after the event fires.
console.log(event.mapPoint);
});
registerOAuthInfos(oAuthInfos)
Registers OAuth 2.0 configurations.
Parameter
An array of OAuthInfo objects that defines the OAuth configurations.
Example
const [OAuthInfo, esriId] = await $arcgis.import([
"@arcgis/core/identity/OAuthInfo.js",
"@arcgis/core/identity/IdentityManager.js"
]);
let oAuthInfo = new OAuthInfo({
appId: "<registered client id>"
}); // required parameter
esriId.registerOAuthInfos([oAuthInfo]);
registerServers(serverInfos)
Register secure servers and the token endpoints.
Parameter
An array of ServerInfos objects that defines the secure service and token endpoint. The IdentityManager makes its best guess to determine the location of the secure server and token endpoint. Therefore, in most cases calling this method is not necessary. However, if the location of your server or token endpoint is not standard, use this method to register the location.
Example
const [ServerInfo, esriId] = await $arcgis.import(["@arcgis/core/identity/ServerInfo.js", "@arcgis/core/identity/IdentityManager.js"]);
let serverInfo = new ServerInfo();
serverInfo.server = "https://sampleserver6.arcgisonline.com";
serverInfo.tokenServiceUrl = "https://sampleserver6.arcgisonline.com/arcgis/tokens/generateToken";
serverInfo.hasServer = true;
esriId.registerServers([serverInfo]);
registerToken(properties)
Registers the given OAuth 2.0 access token or ArcGIS Server token with the IdentityManager. See registerOAuthInfos for additional information. The registerToken
method is an advanced workflow for pre-registering long-term tokens for when you don't want users to sign in.
Once a user logs in, the access token is registered with the IdentityManager. Subsequently, every request made by the application forwards this token when accessing web maps and other items stored in ArcGIS Online, or resources on your server.
Parameters
Specification
See the table below for the structure of the properties object.
setOAuthRedirectionHandler(handlerFunction)
Once a user successfully logs in, they are redirected back to the application. Use this method if the application needs to execute custom logic before the page is redirected. The IdentityManager calls the custom handler function with an object containing redirection properties.
Parameter
When called, the callback passed to setOAuthRedirectionHandler
receives an object containing the redirection properties.
Example
const esriId = await $arcgis.import("@arcgis/core/identity/IdentityManager.js");
esriId.setOAuthRedirectionHandler(function(info)
{
// Execute custom logic then perform redirect
window.location = info.authorizeUrl + "?" + new URLSearchParams(info.authorizeParams).toString();
});
setOAuthResponseHash(hash)
Use this method in the popup callback page to pass the token and other values back to the IdentityManager.
Parameter
The token information in addition to any other values needed to be passed back to the IdentityManager.
setProtocolErrorHandler(handlerFunction)
When accessing secured resources, the IdentityManager may prompt for username and password and send them to the server using a secure connection. Due to potential browser limitations, it may not be possible to establish a secure connection with the server if the application is being run over HTTP protocol. In such cases, the Identity Manager will abort the request to fetch the secured resource. To resolve this issue, configure your web application server with HTTPS support and run the application over HTTPS. This is the recommended solution for production environments. However, for internal development environments that don't have HTTPS support, you can define a protocol error handler that allows the Identity Manager to continue with the process over HTTP protocol.
Parameters
Specification
The function to call when the protocol is mismatched.
Specification
The secure resource URL.
ServerInfo object describing the server where the secure resource is hosted.
toJSON(){Object}
Return properties of this object in JSON format. It can be stored in a cookie or persisted in HTML5 LocalStorage and later used to:
Returns
Type Description Object The JSON object representing the IdentityManager instance calling this method. handlerCallback(info)
The callback to execute when setOAuthRedirectionHandler() is called.
Parameters
Specification
An object containing parameter values for the handlerCallback
.
Specification
Object containing authorization parameters used to access the secure service.
Specification
The application ID of the registered application.
The type of response returned.
The state parameter passed back as the object in the Credential's oAuthState property.
The expiration time in minutes.
The locale being used.
The redirect URL represents the valid places that a user can be redirected to after a successful sign in.
The OAuth 2.0 authorization URL for the portal.
A reference to the OAuthInfo object.
The URL to the accessed resource.
The ServerInfo object describing the server where the secure resource is hosted.
credential-create
Fires when a credential is created.
dialog-create
Fires when the IdentityManager dialog is created. This is used to prompt users for their credentials.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4