Skip to content

ApplicationCredentialsManager

Class

Used to authenticate methods in ArcGIS REST JS with oAuth 2.0 application credentials. The instance of ApplicationCredentialsManager can be passed to IRequestOptions.authentication to authenticate requests.

Use dark colors for code blocksCopy
1
2
3
4
5
6
import { ApplicationCredentialsManager } from '@esri/arcgis-rest-request';

const session = ApplicationCredentialsManager.fromCredentials({
  clientId: "abc123",
  clientSecret: "••••••"
})

Implements

Inheritance: ApplicationCredentialsManagerAuthenticationManagerBase

Constructors

constructor

Class Constructor
new ApplicationCredentialsManager(optionsIApplicationCredentialsManagerOptions): ApplicationCredentialsManager
Parameters
Returns 
ApplicationCredentialsManager

Properties

PropertyTypeNotes
clientIdstring
clientSecretstring
durationnumber
expiresDate
portalstring

Defaults to 'https://www.arcgis.com/sharing/rest'.

tokenstring

clientId

Class Property
clientId: string

clientSecret

Class Property
clientSecret: string

duration

Class Property
duration: number

expires

Class Property
expires: Date

portal

Class Property
portal: string

Defaults to 'https://www.arcgis.com/sharing/rest'.

token

Class Property
token: string

Accessors

AccessorReturnsNotes
get username()string

The username of the currently authenticated user.

username

Class Accessor
get username(): string

The username of the currently authenticated user.

Returns 
string

Methods

Hide inherited methods
MethodReturnsNotes
void

Clear the cached user infornation. Usefull to ensure that the most recent user information from AuthenticationManagerBase.getUser is used.

getToken(url, requestOptions?)Promise<string>

Returns the proper token for a given URL and request options.

getUser(requestOptions?)
inherited
Promise<IUser>

Returns information about the currently logged in user. Subsequent calls will not result in additional web traffic.

getUsername()
inherited
Promise<string>

Returns the username for the currently logged in user. Subsequent calls will not result in additional web traffic. This is also used internally when a username is required for some requests but is not present in the options.

refreshCredentials()Promise<ApplicationCredentialsManager>

Optional. Refresh the stored credentials.

refreshToken(requestOptions?)Promise<string>
serialize()string

Serializes the ApplicationCredentialsManager instance to a JSON string.

toJSON(){ clientId: string; clientSecret: string; duration: number; expires: Date; portal: string; token: string; type: string }

Converts the ApplicationCredentialsManager instance to a JSON object. This is called when the instance is serialized to JSON with JSON.stringify().

deserialize(serialized)ApplicationCredentialsManager

Deserializes a JSON string previously created with ApplicationCredentialsManager.serialize to an ApplicationCredentialsManager instance.

fromCredentials(options)ApplicationCredentialsManager

Preferred method for creating an ApplicationCredentialsManager

clearCachedUserInfo

inherited
Class Method
clearCachedUserInfo(): void

Clear the cached user infornation. Usefull to ensure that the most recent user information from AuthenticationManagerBase.getUser is used.

Returns 
void
Inherited from AuthenticationManagerBase.clearCachedUserInfo

getToken

Class Method
getToken(urlstring, requestOptions?ITokenRequestOptions): Promise<string>

Returns the proper token for a given URL and request options.

Parameters
ParameterType
urlstring
requestOptionsITokenRequestOptions
Returns 
Promise<string>

getUser

inherited
Class Method
getUser(requestOptions?IRequestOptions): Promise<IUser>

Returns information about the currently logged in user. Subsequent calls will not result in additional web traffic.

Use dark colors for code blocksCopy
1
2
3
4
manager.getUser()
  .then(response => {
    console.log(response.role); // "org_admin"
  })
Parameters
ParameterTypeNotes
requestOptionsIRequestOptions

Options for the request. NOTE: rawResponse is not supported by this operation.

Returns 
Promise<IUser>

A Promise that will resolve with the data from the response.

Inherited from AuthenticationManagerBase.getUser

getUsername

inherited
Class Method
getUsername(): Promise<string>

Returns the username for the currently logged in user. Subsequent calls will not result in additional web traffic. This is also used internally when a username is required for some requests but is not present in the options.

Use dark colors for code blocksCopy
1
2
3
4
manager.getUsername()
  .then(response => {
    console.log(response); // "casey_jones"
  })
Returns 
Promise<string>
Inherited from AuthenticationManagerBase.getUsername

refreshCredentials

Class Method
refreshCredentials(): Promise<ApplicationCredentialsManager>

Optional. Refresh the stored credentials.

Returns 
Promise<ApplicationCredentialsManager>

refreshToken

Class Method
refreshToken(requestOptions?ITokenRequestOptions): Promise<string>
Parameters
ParameterType
requestOptionsITokenRequestOptions
Returns 
Promise<string>

serialize

Class Method
serialize(): string

Serializes the ApplicationCredentialsManager instance to a JSON string.

Returns 
string

The serialized JSON string.

toJSON

Class Method
toJSON(): { clientId: string; clientSecret: string; duration: number; expires: Date; portal: string; token: string; type: string }

Converts the ApplicationCredentialsManager instance to a JSON object. This is called when the instance is serialized to JSON with JSON.stringify().

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
import { ApplicationCredentialsManager } from '@esri/arcgis-rest-request';

const session = ApplicationCredentialsManager.fromCredentials({
  clientId: "abc123",
  clientSecret: "••••••"
})

const json = JSON.stringify(session);
Returns 
{ clientId: string; clientSecret: string; duration: number; expires: Date; portal: string; token: string; type: string }

A plain object representation of the instance.

    deserialize

    static
    Class Method
    deserialize(serializedstring): ApplicationCredentialsManager

    Deserializes a JSON string previously created with ApplicationCredentialsManager.serialize to an ApplicationCredentialsManager instance.

    Parameters
    ParameterTypeNotes
    serializedstring

    The serialized JSON string.

    Returns 
    ApplicationCredentialsManager

    An instance of ApplicationCredentialsManager.

    fromCredentials

    static
    Class Method
    fromCredentials(optionsIApplicationCredentialsManagerOptions): ApplicationCredentialsManager

    Preferred method for creating an ApplicationCredentialsManager

    Parameters
    Returns 
    ApplicationCredentialsManager

    Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.