esri-fetch-utils
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

esri-fetch-utils

Utility functions for interacting with ArcGIS Server and Portal/AGOL REST APIs

CI

Install

$ npm install esri-fetch-utils

# or

$ yarn add esri-fetch-utils

Usage

session: Auth via OAuth or Token

session provides utility methods for managing OAuth login flow and accessing the user object. For use in the browser.

// manage OAuth session in the browser
import { session as browserSession } from 'esri-fetch-utils';

//  init session
const config = {
  clientId: 'string', // registered app client id
  redirectUri: 'string', // callback url
  portalUrl: 'string', // optional - defaults to https://www.arcgis.com
  tokenDuration: 'number', // optional - defaults to 20160
  state: 'string', // optional
};
const session = browserSession.create(config);

// generate url to direct user to agol/portal login
const oAuthUrl = session.oAuthUrl();
console.log(oAuthUrl);
// https://www.arcgis.com/sharing/rest/oauth2/authorize?client_id=1234&response_type=token...

// parse hash when user redirected back to your app on successful login
const user = session.onRedirect();
console.log(user);
// {
//   username: 'grill',
//   portalUrl: 'https://www.arcgis.com',
//   clientId: '1234',
//   token: '2YotnFZFEjr1zCsicMWpAA',
//   tokenDuration: 20160,
//   tokenExpires: moment('2020-04-17T13:54:30.248'),
//   state: 'qyxmpg9e5uWUPbxw',
// };

// check is token is expired - will return true if expired
const expired = session.tokenExpired(moment('2020-04-17T13:54:30.248'));
console.log(expired);
// true

genToken TODO - will generate a token via username/password. For use in scripts/server.

portal: TODO - working with users/items/groups

service: TODO - query services

Examples

Browser Login:
Edit esri-fetch-utils-browser-example

Readme

Keywords

Package Sidebar

Install

npm i esri-fetch-utils

Weekly Downloads

0

Version

0.1.2

License

MIT

Unpacked Size

10.2 kB

Total Files

13

Last publish

Collaborators

  • brygrill