require(["esri/identity/OAuthInfo"], (OAuthInfo) => { /* code goes here */ });
import OAuthInfo from "@arcgis/core/identity/OAuthInfo.js";
esri/identity/OAuthInfo
This class contains information about an OAuth 2.0 configuration. Use it in combination with the IdentityManager widget to aid in working with OAuth 2.0 authentication.
One-step authentication has been superseded by the recommended two-step approach with Proof Key for Code Exchange (PKCE).
This update coincides with recommendations in the OAuth 2.1 specification. Although one-step authentication is still supported, the API will no longer default to this. If needing to retain this setting, it is necessary to set flowType to implicit
.
Please refer to the 4.23 Release Notes for additional information regarding this update.
- See also
Constructors
-
Parameterproperties Objectoptional
See the properties for a list of all the properties that may be passed into the constructor.
Examplerequire(["esri/identity/OAuthInfo", "esri/identity/IdentityManager"], function (OAuthInfo, esriId) { // Create a new OAuthInfo object. // The OAuth sign-in page will be shown in a popup window and use the specified callback URL. const info = new OAuthInfo({ appId: "<put client id here>", popup: true, // If using a callback page other than the default one, // make sure it supports the authentication type used. popupCallbackUrl: "<url to callback page>" }); // Add this OAuthInfo object to the IdentityManager. esriId.registerOAuthInfos([info]); })
Property Overview
Name | Type | Summary | Class |
---|---|---|---|
The registered application id. | OAuthInfo | ||
Applications with the same value will share the stored token on the same host. | OAuthInfo | ||
The name of the class. | Accessor | ||
The number of minutes that the token is valid. | OAuthInfo | ||
Set this property to specify the type of authentication to use. | OAuthInfo | ||
Set this property to | OAuthInfo | ||
The locale for the OAuth sign-in page. | OAuthInfo | ||
The minimum time in minutes before a saved token is due to expire that should still be considered valid for use. | OAuthInfo | ||
Set to | OAuthInfo | ||
Applicable if working with the popup user-login workflow. | OAuthInfo | ||
The window features passed to window.open(). | OAuthInfo | ||
The ArcGIS Enterprise portal URL. | OAuthInfo | ||
Set this property to | OAuthInfo | ||
The user id used when | OAuthInfo |
Property Details
-
appId
appId String
-
The registered application id.
-
authNamespace
authNamespace String
-
Applications with the same value will share the stored token on the same host.
- Default Value:/ (forward slash)
-
expiration
expiration Number
-
The number of minutes that the token is valid.
- Default Value:20160 (two weeks)
-
flowType
flowType String
Since: ArcGIS Maps SDK for JavaScript 4.23OAuthInfo since 4.0, flowType added at 4.23. -
Set this property to specify the type of authentication to use. One-step authentication has been superseded in favor of the recommended two-step approach (ie.
grant_type=authorization-code
).This update coincides with recommendations in the OAuth 2.1 recommendation.
Possible Value Description auto Recommended. Automatically defaults to two-step authentication with PKCE if accessing resources from ArcGIS Online or ArcGIS Enterprise version 10.9 or higher. One-step authentication is used if accessing an earlier version of ArcGIS Enterprise. authorization-code Similar to auto
, this also uses two-step authentication with PKCE, but this does not check the server version. Do not use this type if accessing resources on older server versions without PKCE support.implicit One-step authentication. This is no longer a recommended approach and has been superseded by two-step authentication. Use this type if working with older server versions (ie. prior to 10.9). Please refer to OAuth 2.0 Security Best Current Practices for additional information. When signing into an application via a popup, the referenced callback page should be compatible for whatever authentication type is used. The default oauth-callback.html has been updated to allow for these updates in the two-step approach, although it will still work if using the one-step flow.
Possible Values:"auto" |"authorization-code" |"implicit"
- Default Value:"auto"
Examples// The `flowType` defaults to `auto`. // If using a supported server/portal version, two-step authentication is used. // If not, reverts to one-step. const infoAuto = new OAuthInfo({ appId: "<put client id here>" });
// One-step workflow - no longer recommended. // Should only be used if working with older versions of Server/Portal, (ie. < 10.9). const infoImplicit = new OAuthInfo({ appId: "<put client id here>", flowType: "implicit", popup: true, // Updated callback page works with both two-step and one-step authentication popupCallbackUrl: "oauth-callback.html" });
-
forceUserId
forceUserId Boolean
Since: ArcGIS Maps SDK for JavaScript 4.18OAuthInfo since 4.0, forceUserId added at 4.18. -
Set this property to
true
to force the user to sign in with the id in userId. If the userId is not set, it will update after the user signs in. If the token expires, the same user will be required to sign in again.- Default Value:false
- See also
-
locale
locale String
-
The locale for the OAuth sign-in page. The default locale is based on your browser/OS and the organization locale. You can use this property to change this. The locale needs to follow the language dash country code syntax supported by ArcGIS.com.
- Default Value:// Based on your browser/OS and the organization locale.
- See also
-
minTimeUntilExpiration
minTimeUntilExpiration Number
-
The minimum time in minutes before a saved token is due to expire that should still be considered valid for use.
- Default Value:30
-
popup
popup Boolean
-
Set to
true
to show the OAuth sign-in page in a popup window. Make certain to have a valid callback page referenced in thepopupCallbackUrl
. A sample callback page, oauth-callback.html, is provided to help with this. The referenced callback page should be compatible for whatever authentication type is used. The default oauth-callback.html has been updated to allow for these updates in the two-step approach, although it will still work if using the one-step flow.- Default Value:false
- See also
-
popupCallbackUrl
popupCallbackUrl String
-
Applicable if working with the popup user-login workflow. This is a relative page URL that redirects the user back to the secured application after successful login.
The referenced callback page should be compatible for whatever authentication type is used. The default oauth-callback.html has been updated to allow for these updates in the two-step approach, although it will still work if using the one-step flow.
- Default Value:"oauth-callback.html"
- See also
-
popupWindowFeatures
popupWindowFeatures String
-
The window features passed to window.open().
- Default Value:"height=490,width=800,resizable,scrollbars,status"
-
portalUrl
portalUrl String
-
The ArcGIS Enterprise portal URL.
- Default Value:"https://www.arcgis.com"
-
userId
userId String
Since: ArcGIS Maps SDK for JavaScript 4.18OAuthInfo since 4.0, userId added at 4.18. -
The user id used when
forceUserId
istrue
. This is updated after a user signs in, or it can be preset to a specific id.- See also
Method Overview
Name | Return Type | Summary | Class |
---|---|---|---|
Adds one or more handles which are to be tied to the lifecycle of the object. | Accessor | ||
Creates a copy of the OAuthInfo object. | OAuthInfo | ||
* | Creates a new instance of this class and initializes it with values from a JSON object generated from an ArcGIS product. | OAuthInfo | |
Returns true if a named group of handles exist. | Accessor | ||
Removes a group of handles owned by the object. | Accessor | ||
Converts an instance of this class to its ArcGIS portal JSON representation. | OAuthInfo |
Method Details
-
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25Accessor since 4.0, addHandles added at 4.25. -
Adds one or more handles which are to be tied to the lifecycle of the object. The handles will be removed when the object is destroyed.
// Manually manage handles const handle = reactiveUtils.when( () => !view.updating, () => { wkidSelect.disabled = false; }, { once: true } ); this.addHandles(handle); // Destroy the object this.destroy();
ParametershandleOrHandles WatchHandle|WatchHandle[]Handles marked for removal once the object is destroyed.
groupKey *optionalKey identifying the group to which the handles should be added. All the handles in the group can later be removed with Accessor.removeHandles(). If no key is provided the handles are added to a default group.
-
Creates a new instance of this class and initializes it with values from a JSON object generated from an ArcGIS product. The object passed into the input
json
parameter often comes from a response to a query operation in the REST API or a toJSON() method from another ArcGIS product. See the Using fromJSON() topic in the Guide for details and examples of when and how to use this function.Parameterjson ObjectA JSON representation of the instance in the ArcGIS format. See the ArcGIS REST API documentation for examples of the structure of various input JSON objects.
ReturnsType Description * Returns a new instance of this class.
-
hasHandles
InheritedMethodhasHandles(groupKey){Boolean}
Inherited from AccessorSince: ArcGIS Maps SDK for JavaScript 4.25Accessor since 4.0, hasHandles added at 4.25. -
Returns true if a named group of handles exist.
ParametergroupKey *optionalA group key.
ReturnsType Description Boolean Returns true
if a named group of handles exist.Example// Remove a named group of handles if they exist. if (obj.hasHandles("watch-view-updates")) { obj.removeHandles("watch-view-updates"); }
-
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25Accessor since 4.0, removeHandles added at 4.25. -
Removes a group of handles owned by the object.
ParametergroupKey *optionalA group key or an array or collection of group keys to remove.
Exampleobj.removeHandles(); // removes handles from default group obj.removeHandles("handle-group"); obj.removeHandles("other-handle-group");
-
toJSON
toJSON(){Object}
-
Converts an instance of this class to its ArcGIS portal JSON representation. See the Using fromJSON() guide topic for more information.
ReturnsType Description Object The ArcGIS portal JSON representation of an instance of this class.