Skip to content

Commit

Permalink
feat(auth): add getCredential() method to UserSession for jsapi
Browse files Browse the repository at this point in the history
AFFECTS PACKAGES:
@esri/arcgis-rest-auth

ISSUES CLOSED: #208
  • Loading branch information
jgravois committed Jun 13, 2018
1 parent 0cc7aaa commit c03430d
Show file tree
Hide file tree
Showing 11 changed files with 384 additions and 10 deletions.
6 changes: 3 additions & 3 deletions demos/feature-service-browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ <h1>query features!</h1>
</div>

<!-- load arcgis rest libraries -->
<script src="node_modules/@esri/arcgis-rest-request/dist/umd/arcgis-rest-request.umd.js"></script>
<script src="node_modules/@esri/arcgis-rest-feature-service/dist/umd/arcgis-rest-feature-service.umd.js"></script>
<script src="node_modules/@esri/arcgis-rest-request/dist/umd/request.umd.js"></script>
<script src="node_modules/@esri/arcgis-rest-feature-service/dist/umd/feature-service.umd.js"></script>

<script>
// respond when a user fills out the query form and
Expand Down Expand Up @@ -114,7 +114,7 @@ <h1>query features!</h1>
// show/hide additional messages
var suggestedTermsMessageDisplay = recordCount > 0 ? 'none' : 'block';
var additionalRowsMessageDisplay = response.exceededTransferLimit ? 'block' : 'none';
document.getElementById('suggestedTermsMessage').style.display = suggestedTermsMessageDisplay;
document.getElementById('suggestedTermsMessage').style.display = suggestedTermsMessageDisplay;
document.getElementById('additionalRowsMessage').style.display = additionalRowsMessageDisplay;
}
</script>
Expand Down
6 changes: 3 additions & 3 deletions demos/geocoder-browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ <h1>get to geocodin!</h1>
</div>

<script src="config.js"></script>
<script src="node_modules/@esri/arcgis-rest-request/dist/umd/arcgis-rest-request.umd.js"></script>
<script src="node_modules/@esri/arcgis-rest-auth/dist/umd/arcgis-rest-auth.umd.js"></script>
<script src="node_modules/@esri/arcgis-rest-geocoder/dist/umd/arcgis-rest-geocoder.umd.js"></script>
<script src="node_modules/@esri/arcgis-rest-request/dist/umd/request.umd.js"></script>
<script src="node_modules/@esri/arcgis-rest-auth/dist/umd/auth.umd.js"></script>
<script src="node_modules/@esri/arcgis-rest-geocoder/dist/umd/geocoder.umd.js"></script>

<script>
var auth;
Expand Down
8 changes: 8 additions & 0 deletions demos/jsapi-integration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Passing authentication to the JSAPI

This demo shows how to pass an authenticated session from `arcgis-rest-js` to the ArcGIS API for JavaScript.

## 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).
82 changes: 82 additions & 0 deletions demos/jsapi-integration/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<title>Share auth between rest-js and the jsapi</title>

<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
</style>

<link rel="stylesheet" href="https://js.arcgis.com/4.7/esri/css/main.css">

<script>
dojoConfig = {
paths: {
"@esri/arcgis-rest-request": "/node_modules/@esri/arcgis-rest-request/dist/umd/request.umd",
"@esri/arcgis-rest-auth": "/node_modules/@esri/arcgis-rest-auth/dist/umd/auth.umd",
"@esri/arcgis-rest-items": "/node_modules/@esri/arcgis-rest-items/dist/umd/items.umd"
}
};
</script>

<script src="https://js.arcgis.com/4.7/"></script>
<script>
require([
"@esri/arcgis-rest-request",
"@esri/arcgis-rest-auth",
"@esri/arcgis-rest-items",
"esri/identity/IdentityManager",
"esri/views/MapView",
"esri/WebMap",
"dojo/domReady!"
], function(
arcgis, arcgisAuth, arcgisItems, esriId, MapView, WebMap
) {

// private item
// https://geosaurus.maps.arcgis.com/home/item.html?id=728043ac6a574a00b8f1cd5ee0eae8cd
const itemId = "728043ac6a574a00b8f1cd5ee0eae8cd";

// canned username/password from
// https://developers.arcgis.com/python/sample-notebooks/chennai-floods-analysis/
const session = new arcgisAuth.UserSession({
username: "arcgis_python",
password: "P@ssword123"
});

// fetch the private item's data, not just the metadata
arcgisItems.getItemData(itemId, { authentication: session })
.then(response => {
// pass the authenticated session over to the JSAPI Identity Manager
esriId.registerToken(session.getCredential());

// dig the webmap id out of the response
var webmap = new WebMap({
portalItem: {
id: response.map.itemId
}
});

// and pass it to the map view
var view = new MapView({
map: webmap,
container: "viewDiv"
});
});
});
</script>
</head>

<body>
<div id="viewDiv"></div>
</body>
</html>
184 changes: 184 additions & 0 deletions demos/jsapi-integration/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions demos/jsapi-integration/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@esri/jsapi-integration",
"version": "1.4.0",
"private": true,
"description": "to do",
"author": "",
"license": "Apache-2.0",
"dependencies": {
"@esri/arcgis-rest-auth": "^1.4.0",
"@esri/arcgis-rest-request": "^1.4.0",
"@esri/arcgis-rest-items": "^1.4.0"
},
"devDependencies": {
"http-server": "*"
},
"scripts": {
"start": "http-server ."
}
}
3 changes: 2 additions & 1 deletion docs/acetate.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,11 @@ module.exports = function(acetate) {
return inspect(obj, { depth: 3 });
});

// without the '.js' on the end, for the benefit of the AMD sample
acetate.helper("cdnUrl", function(context, package) {
return `https://unpkg.com/${
package.name
}@${package.version}/dist/umd/${package.name.replace("@esri/arcgis-rest-", "")}.umd.js`;
}@${package.version}/dist/umd/${package.name.replace("@esri/arcgis-rest-", "")}.umd`;
});

acetate.helper("npmInstallCmd", function(context, package) {
Expand Down
31 changes: 31 additions & 0 deletions docs/src/guides/amd-requirejs-dojo.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,34 @@ group: 1-get-started
---

# Get Started with ArcGIS REST JS and AMD

```html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>ArcGIS REST JS - AMD</title>
</head>
<body>
Open your console to see the demo.
</body>
<!-- require polyfills for fetch and Promise from https://polyfill.io -->
<script src="https://cdn.polyfill.io/v2/polyfill.js?features=es5,Promise,fetch"></script>
<script>
dojoConfig = {
paths: {
"@esri/arcgis-rest-request": "{% cdnUrl data.typedoc | findPackage('@esri/arcgis-rest-request') %}"
}
};
</script>
<script src="https:////ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
<script>
require(["@esri/arcgis-rest-request"], function(arcgis) {
arcgis.request("https://www.arcgis.com/sharing/rest/info").then(response => {
console.log(response);
});
});
</script>
</html>
```
2 changes: 1 addition & 1 deletion docs/src/guides/from-a-cdn.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ArcGIS REST JS is hosted on [unpkg](https://unpkg.com/). You can find URLs for i
<script src="https://cdn.polyfill.io/v2/polyfill.js?features=es5,Promise,fetch"></script>

<!-- require ArcGIS REST JS libraries from https://unpkg.com -->
<script src="{% cdnUrl data.typedoc | findPackage('@esri/arcgis-rest-request') %}"></script>
<script src="{% cdnUrl data.typedoc | findPackage('@esri/arcgis-rest-request') %}.js"></script>

<script>
// when including ArcGIS REST JS all exports are available from an arcgisRest global
Expand Down
Loading

0 comments on commit c03430d

Please sign in to comment.