How to use @esri/arcgis-rest-auth - 10 common examples

To help you get started, we’ve selected a few @esri/arcgis-rest-auth examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Esri / arcgis-rest-js / demos / webmap-checker-sapper / src / utils.js View on Github external
.then(sessionInfo => {
        console.log(sessionInfo);
        const newSession = new UserSession(session);

        // if we are in a browser (client side) we are working with an instance
        // of `UserSession` otherwise (server side) we are working with a JSON
        // representation of a session.
        if (process.browser) {
          this.store.set({ session: newSession });

          // if we are in a browser we should also update IdentityManager
          loadModules(["esri/identity/IdentityManager"]).then(([esriId]) => {
            esriId.registerToken(session.toCredential());
          });
        } else {
          this.store.set({ session: sessionInfo });
        }

        return error.retry(newSession, 1);
github Esri / arcgis-rest-js / demos / webmap-checker-sapper / src / routes / webmaps / [webmapId].html View on Github external
preload({ params }) {
      const { session } = this.store.get();

      // redirect to the homepage unless the user is signed in
      if (!session) {
        this.redirect(302, "/");
        return;
      }

      const { webmapId } = params;

      // if we are on the server we won't have an actuall UserSession just a
      // JSON representation of one. So we need to hydrate a UserSession.
      const userSession = process.browser ? session : new UserSession(session);

      // next we can request both the webmap item and the webmap data (the JSON)
      // and process the data to get a list of layers.
      return Promise.all([
        getItem(webmapId, {
          authentication: userSession
        }).catch(error => {
          return retryWithNewSession(error, this.fetch);
        }),
        getItemData(webmapId, {
          authentication: userSession
        }).catch(error => {
          return retryWithNewSession(error, this.fetch);
        })
      ]).then(([item, webmap]) => {
        const layers = webmap.operationalLayers
github Esri / arcgis-rest-js / demos / webmap-checker-sapper / src / client.js View on Github external
store: data => {
    // `data` is whatever was in the Store on the server side.
    // if we have a session we can create a new UserSession that we can
    // use with ArcGIS REST JS on the client.
    return new Store({
      session: data && data.session ? new UserSession(data.session) : null,
      user: data.user,
      org: data.org
    });
  }
});
github Esri / arcgis-rest-js / demos / node-cli-item-management / index.js View on Github external
.then(({ username, password }) => {
      session = new UserSession({
        username,
        password
      });

      // this will generate a token and use it to get into about a user
      return session.getUser();
    })
    .then(self => {
github Esri / arcgis-rest-js / demos / webmap-checker-sapper / src / routes / webmaps / index.html View on Github external
preload() {
      const { session } = this.store.get();

      // redirect to the homepage unless the user is signed in
      if (!session) {
        this.redirect(302, "/");
        return;
      }

      // if we are on the server we won't have an actuall UserSession just a
      // JSON representation of one. So we need to hydrate a UserSession.
      const userSession = process.browser ? session : new UserSession(session);

      // now we can search for webmaps. Sapper will wait until this promise
      // resolves before rendering the page.
      return (
        searchItems({
          q: `owner:${session.username} type:"Web Map"`,
          num: 100,
          authentication: userSession
        })
          // if there is an error we can retry the request with a fresh session
          // from /auth/exchange-token
          .catch(error => {
            return retryWithNewSession(error, this.fetch);
          })
          // then we can process out response.
          .then(response => {
github Esri / arcgis-rest-js / demos / vue / src / components / App.vue View on Github external
signInWithPopup() {
      if (this.requireClientId()) {
        UserSession.beginOAuth2({
          clientId: this.clientId,
          // Passing the clientid here is only a requirement of this demo where we allow
          // dynamic clientids via input. Typically you would have this hard-coded on
          // the authorization callback.
          redirectUri: `${this.redirect_uri}#/authenticate?clientID=${
            this.clientId
          }`,
          popup: true
        })
          .then(session => {
            // Upon successful login, update the application's store with this new
            // session.
            this.$store.dispatch("updateSession", session);
          })
          .catch(error);
      }
github Esri / arcgis-rest-js / demos / vue / src / components / App.vue View on Github external
signInWithInlineRedirect() {
      if (this.requireClientId()) {
        UserSession.beginOAuth2({
          clientId: this.clientId,
          redirectUri: `${this.redirect_uri}#/authenticate?clientID=${
            this.clientId
          }`,
          popup: false
        });
      }
    },
    // Function to log the use out of the current session.
github Esri / arcgis-rest-js / demos / vue / src / main.js View on Github external
loadSerializedSession() {
      if (typeof Storage !== "undefined") {
        const serializedSession = localStorage.getItem(
          "__ARCGIS_REST_USER_SESSION__"
        );
        if (serializedSession !== null && serializedSession !== "undefined") {
          // If there is a serialized session, deserialize it into a new session object.
          store.dispatch(
            "updateSession",
            UserSession.deserialize(serializedSession)
          );
        }
      }
    }
  },
github Esri / arcgis-rest-js / demos / webmap-checker-sapper / src / routes / auth / post-sign-in.js View on Github external
export async function get(request, response, next) {
  // exchange the auth token for a full `UserSession`
  request.session.userSession = await UserSession.exchangeAuthorizationCode(
    {
      clientId: CLIENT_ID,
      redirectUri: REDIRECT_URI
    },
    request.query.code
  );

  // once we have the session set redirect the user to the /webmaps
  // route so they can use the app.
  response.redirect("/webmaps");
}
github Esri / arcgis-rest-js / demos / batch-geocoder-node / batch-geocode.js View on Github external
return locations.reduce((locMap, loc) => {
      const locFields = {};
      locFields['x'] = loc.location.x;
      locFields['y'] = loc.location.y;
      // ref: https://developers.arcgis.com/rest/geocode/api-reference/geocoding-service-output.htm#ESRI_SECTION1_42D7D3D0231241E9B656C01438209440
      locFields['geocode_score'] = loc.score;
      locFields['match_type'] = loc.attributes.Addr_type;
      locMap[loc.attributes.ResultID] = locFields;
      return locMap;
    }, resMap);
  }, {});

// IMPLEMENTATION!

// Instantiate an ApplicationSession to run Geocoding service
const session = new ApplicationSession({
  clientId: config.clientId,
  clientSecret: config.clientSecret
});

// Parse and geocode
parseCsv(config.csv)
  .then(data => {
    // Build address requests
    const addrs = getAddresses(data, config.fieldmap);
    const chunks = chunkGeocode(addrs, 1000);

    // Geocode
    const promises = chunks.map(chunk =>
      bulkGeocode({
        addresses: chunk,
        authentication: session