Skip to content

Instantly share code, notes, and snippets.

@zhenyanghua
Last active September 19, 2016 12:36
Show Gist options
  • Save zhenyanghua/5e7ca19c509c4154c0082945a76bfc6d to your computer and use it in GitHub Desktop.
Save zhenyanghua/5e7ca19c509c4154c0082945a76bfc6d to your computer and use it in GitHub Desktop.
ArcGIS Online login flow through JS 3.x
require([
'app/config',
'dojo/ready',
'dojo/on',
'dojo/dom',
'esri/arcgis/OAuthInfo',
'esri/IdentityManager'],
function(
config,
ready,
on,
dom,
OAuthInfo,
IdentityManager
) {
checkLogin(config);
function checkLogin(config) {
IdentityManager.registerOAuthInfos([info]);
IdentityManager.checkSignInStatus(info.portalUrl + '/sharing')
.then(loginSuccess)
.otherwise(loginFail);
}
function loginSuccess(credential) {
console.debug('credential', credential);
ready(function () {
// Init the app UI.
// ...
on(dom.byId('signOut'), 'click', signOut);
});
}
function loginFail(response) {
console.debug('Login Failed', response);
IdentityManager.getCredential(info.portalUrl + "/sharing");
}
function signOut() {
IdentityManager.destroyCredentials();
window.location = window.location.origin + window.location.pathname;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment