Last active
September 19, 2016 12:36
-
-
Save zhenyanghua/5e7ca19c509c4154c0082945a76bfc6d to your computer and use it in GitHub Desktop.
ArcGIS Online login flow through JS 3.x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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