How to access user information

You can connect your map.apps for Developers project to an Identity Service instance. Doing this enables you to access user information from ArcGIS Online, an ArcGIS Enterprise portal or a Keycloak instance while developing bundles.

In this how-to…​
This guide demonstrates, how to connect a map.apps for Developers app with the Identity Service. The app will then show user information about the logged in user.

Checklist

To follow this guide, you need:
  • A project based on map.apps for Developers version 4.15.0 or higher.

  • An Identity Service instance set up and running. Check the Identity Service documentation for more information.

  • map.apps for Developers and Identity Service both running under HTTPS. Alternatively, both can run under localhost for development purposes.

Step 1: Connect the Identity Service

First, you need to configure map.apps for Developers to connect to the Identity Service.

  1. Open the application.properties file of your map.apps for Developers project.

  2. Add the following required properties to connect to the Identity Service as described below.

    # Enable the Identity Service integration
    security.mode=IDENTITY
    
    # Base URL of the Identity Service
    security.login.base=http://localhost:8080
    
    # This has to be the URL of the ArcGIS Online organization or
    # the URL of the ArcGIS Enterprise portal
    # The value must match the configuration from the Identity Service
    # security.oauth.provider.arcgis.url
    esri.api.arcgisPortalUrl=https://myhost.example.com/portal
    # Necessary to send cookie via proxy
    proxy.allowedServerUrls=http://localhost:8080/**,trusted:true;

    Replace the URLs with the actual URLs of your Identity Service and your ArcGIS Online organization or ArcGIS Enterprise portal.

  3. If Identity Service runs on a host in a different domain than map.apps for Developers, you need to add the Identity Service hostname to the property cors.request.trustedServers like this:

    # (Optional) Add the Identity Service as 'trustedServer',
    # so that the cookie is also sent for cross domain requests
    cors.request.trustedServers=https://identity.example.com
  4. Save the file and restart the development server.

  5. If you use a fully qualified hostname instead of localhost to access map.apps for Developers in your browser, then you may need to add the hostname to the property security.login.redirect.trusted.hosts at the Identity Service configuration. See the Identity Service documentation for more information about that property.

Step 2: Enable authentication in the app

To make use of authentication in your map.apps for Developers app, you need to prepare your app accordingly.

  1. Open the app.json file of your project.

  2. Add the authentication bundle to your app like this:

    ...
        "allowedBundles": [
            ...,
            "authentication"
        ]
    },
    ...
  3. Save the file and reload the app in your browser.

You should now see a login button in the top right corner of the app. When clicking the button, the browser redirects you to the Identity Provider as specified in the Identity Service configuration. On successful login, the browser redirects you back to your app showing your username in the top right corner.