How to implement App Login?

790
2
03-12-2019 08:42 PM
Rupam_RanjanRana
New Contributor II

Hi,

We have a hybrid mobile app, UI running on web view. We're migrating the app from google maps for JS to ArcGis 4.10 for JS. Google maps signs in with a developer token. Is there an equivalent in ArcGis? Named user login is not viable for us. We want all the user be using a corporate licence. We have created a developer account and registered the app as a web application, and we got the Client ID, Client Secret, 

2 Replies
RobertScheitlin__GISP
MVP Emeritus

Rupam,

  So do you want the end user presented with a login screen or not?

0 Kudos
Rupam_RanjanRana
New Contributor II

Robert, 

The end user doesn't need to go through any login screen. Login has to happen in background with one enterprise licence. But we figured it out. So here is code below if anyone has the same question.

authenticateAPI: function () {
	var me = this;
	return new Promise(function (resolve, reject) {
		try {
			require(["esri/request", "esri/identity/IdentityManager"], function (esriRequest, identityManager) {
				var serverAdr = 'https://www.arcgis.com/sharing/rest';
				var requestURL = serverAdr + '/oauth2/token?client_id=' + me.client_id + '&client_secret=' + me.client_secret + '&grant_type=client_credentials';				
				esriRequest(requestURL, {
					responseType: "json"
				}).then(function (responce) {
					identityManager.registerToken({
						token: responce.data.access_token,
						expires: responce.data.expires_in,
						server: serverAdr
					});
					identityManager.checkSignInStatus('https://www.arcgis.com/sharing').then(function () {						
						return resolve();
					}).catch(function (error) {						
						return reject();
					});
				}).catch(function (error) {					
					return reject();
				});
			});
		} catch (exception) {			
			return reject();
		}
	});
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Thanks

0 Kudos