The Esri Identity manager provides a very handy way to authenticate an ArcGIS Maps SDK for JavaScript application with ArcGIS Portal, but the instructions are a little vague. Here is a step-by-step guide to using Esri IdentityManager:

1. In the Content section of ArcGIS Portal, Add a new Application:

add application

Enter the URL for the application (it must be HTTPS) and add a title and tags:

enter URL

Go to the Settings page for the new application, and scroll down to the App Registration section. Use the Register button:

Enter the URL(s) for any pages/sites which will be using this application, then hit Add to add to the list. Hit Register when finished:

add new application

This will generate a unique AppID for this application:

add new application

Use that AppID in the demo at https://jsfiddle.net/slead/wb8e3mh9/, which uses the ArcGIS Portal to authenticate the user, before attempting to query a secure layer. This query step is a quick way to force the login prompt to appear.

Update the placeholder variables with the relevant values:

var appId = ‘enter-the-app-id’
var portalUrl = ‘enter-the-portal-url’;
var testUrl = ‘enter-the-full-path-to-the-secure-layer’

add new application