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
Property | Type | Notes |
---|---|---|
string | Defaults to 'https://www.arcgis.com/sharing/rest'. |
portal
Class Propertyportal: string
Defaults to 'https://www.arcgis.com/sharing/rest'.
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. |
Promise<ApplicationCredentialsManager> | Optional. Refresh the stored credentials. | |
refreshToken(requestOptions?) | Promise<string> | |
fromCredentials(options) | 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>
fromCredentials
fromCredentials(options: IApplicationCredentialsManagerOptions): ApplicationCredentialsManager
Preferred method for creating an ApplicationCredentialsManager
Parameters
Parameter | Type |
---|---|
options | IApplicationCredentialsManagerOptions |
Returns
ApplicationCredentialsManager