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.
import { ApplicationCredentialsManager } from '@esri/arcgis-rest-request';
const session = ApplicationCredentialsManager.fromCredentials({
clientId: "abc123",
clientSecret: "••••••"
})
Implements
Constructors
constructor
Class Constructornew ApplicationCredentialsManager(options: IApplicationCredentialsManagerOptions): ApplicationCredentialsManager
Parameters
Parameter | Type |
---|---|
options | IApplicationCredentialsManagerOptions |
Returns
ApplicationCredentialsManager
Properties
Accessors
Accessor | Returns | Notes |
---|---|---|
get username() | string | The username of the currently authenticated user. |
Methods
Method | Returns | Notes |
---|---|---|
clearCachedUserInfo() inherited | void | Clear the cached user infornation. Usefull to ensure that the most recent user information from |
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 |
toJSON() | { clientId: string; clientSecret: string; duration: number; expires: Date; portal: string; token: string; type: string } | Converts the |
deserialize(serialized) | ApplicationCredentialsManager | Deserializes a JSON string previously created with |
fromCredentials(options) | ApplicationCredentialsManager | Preferred method for creating an |
clearCachedUserInfo
clearCachedUserInfo(): void
Clear the cached user infornation. Usefull to ensure that the most recent user information from AuthenticationManagerBase.getUser
is used.
Returns
void
getToken
Class MethodgetToken(url: string, requestOptions?: ITokenRequestOptions): Promise<string>
Returns the proper token for a given URL and request options.
Parameters
Parameter | Type |
---|---|
url | string |
request | ITokenRequestOptions |
Returns
Promise<string>
getUser
getUser(requestOptions?: IRequestOptions): Promise<IUser>
Returns information about the currently logged in user. Subsequent calls will not result in additional web traffic.
manager.getUser()
.then(response => {
console.log(response.role); // "org_admin"
})
Parameters
Parameter | Type | Notes |
---|---|---|
request | IRequestOptions | Options for the request. NOTE: |
Returns
Promise<IUser>
A Promise that will resolve with the data from the response.
getUsername
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.
manager.getUsername()
.then(response => {
console.log(response); // "casey_jones"
})
Returns
Promise<string>
refreshCredentials
Class MethodrefreshCredentials(): Promise<ApplicationCredentialsManager>
Optional. Refresh the stored credentials.
Returns
Promise<ApplicationCredentialsManager>
refreshToken
Class MethodrefreshToken(requestOptions?: ITokenRequestOptions): Promise<string>
Parameters
Parameter | Type |
---|---|
request | ITokenRequestOptions |
Returns
Promise<string>
serialize
Class Methodserialize(): string
Serializes the ApplicationCredentialsManager
instance to a JSON string.
Returns
string
The serialized JSON string.
toJSON
Class MethodtoJSON(): { 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()
.
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
deserialize(serialized: string): ApplicationCredentialsManager
Deserializes a JSON string previously created with ApplicationCredentialsManager.serialize
to an ApplicationCredentialsManager
instance.
Parameters
Parameter | Type | Notes |
---|---|---|
serialized | string | The serialized JSON string. |
Returns
ApplicationCredentialsManager
An instance of ApplicationCredentialsManager
.
fromCredentials
fromCredentials(options: IApplicationCredentialsManagerOptions): ApplicationCredentialsManager
Preferred method for creating an ApplicationCredentialsManager
Parameters
Parameter | Type |
---|---|
options | IApplicationCredentialsManagerOptions |
Returns
ApplicationCredentialsManager