-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #379 from Esri/doc/jsapi-to-rest-js
docs: demo how to retrieve credentials from the jsapi too
- Loading branch information
Showing
2 changed files
with
24 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,25 @@ | ||
# Passing authentication to the JSAPI | ||
|
||
This demo shows how to use `arcgis-rest-js` with the ArcGIS API for JavaScript. A typical use case would be when you need to query items or feature data _before_ you are ready to display a map or scene view. In this scenario, you should load the light-weight `arcgis-rest-js` libraries first and use them to perform your queries and/or authenticate with the ArcGIS platform. Then when you are ready to show a map or scene view, you would lazy-load the ArcGIS API for JavaScript with something like [esri-loader](https://github.com/Esri/esri-loader) and use it to create the map. | ||
This demo shows how to use `arcgis-rest-js` with the ArcGIS API for JavaScript. A typical use case would be when you need to query items or feature data _before_ you are ready to display a map or scene view. In this scenario, you should load the light-weight `arcgis-rest-js` libraries first and use them to perform your queries and/or authenticate with the ArcGIS platform. Then when you are ready to show a map or scene view, you would lazy-load the ArcGIS API for JavaScript with something like [esri-loader](https://github.com/Esri/esri-loader) and use it to create the map. | ||
|
||
## Running this demo | ||
1. Run `npm run bootstrap` in the repository's root directory. | ||
1. Run `npm start` to spin up the development server. | ||
1. Visit [http://localhost:8080](http://localhost:8080). | ||
|
||
```js | ||
// from rest-js | ||
const session = new UserSession(/* */); | ||
|
||
// session wont fetch a token until a request is a made | ||
session.getToken("https://www.arcgis.com/sharing/rest") | ||
.then(() => { | ||
esriId.registerToken(session.toCredential()); // JSAPI Identity Manager | ||
}) | ||
|
||
// from jsapi | ||
esriId.getCredential("https://www.arcgis.com/sharing/rest") | ||
.then(cred => { | ||
const session = new UserSession.fromCredential(cred); | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters