Esri / arcgis-rest-js

compact, modular JavaScript wrappers for the ArcGIS REST API
https://developers.arcgis.com/arcgis-rest-js/
Apache License 2.0
354 stars 119 forks source link

Add support for portal service operations with API keys/App authentication #1182

Open gowin20 opened 1 week ago

gowin20 commented 1 week ago

Describe the problem

As of the latest ArcGIS Online release, both API keys and app authentication (with Online+Location Platform accounts) now support performing portal service operations, e.g. managing items, users, groups, etc... They also support spatial analysis operations.

REST JS supports portal operations but requires a username for many/all of them. This property is currently accessed through the username property and getUsername method of IdentityManager: https://github.com/Esri/arcgis-rest-js/blob/bfd7ce977d9879077e92fabfc491240d8f230844/packages/arcgis-rest-portal/src/items/helpers.ts#L264

All of the portal service operations that require a username currently fail when using an API key/ApplicationCredentialsManager. The following error is what we're getting when running createItem with an API key: image

Describe the proposed solution

The ApiKeyManager and ApplicationCredentialsManager classes need to be updated to add support for a getUsername property. Hopefully this can be completed in a minimally breaking way. We should also update our internal codebase to rely on getUsername instead of the username method across the board, as getUsername is async.

Alternatives considered

No response

Additional Information

No response