From f220adf53dc414201d1a327ec508b8143de8fcdd Mon Sep 17 00:00:00 2001 From: omercs Date: Tue, 16 Dec 2014 13:48:29 -0800 Subject: [PATCH] update dist files --- dist/adal-angular.min.js | 2 ++ dist/adal.min.js | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 dist/adal-angular.min.js diff --git a/dist/adal-angular.min.js b/dist/adal-angular.min.js new file mode 100644 index 00000000..5c590a56 --- /dev/null +++ b/dist/adal-angular.min.js @@ -0,0 +1,2 @@ +/*! adal-angular v0.0.4 2014-12-16 */ +"use strict";if("undefined"!=typeof module&&module.exports){var window,localStorage,angular,document,AuthenticationContext;module.exports.inject=function(a,b,c,d,e,f){window=a,localStorage=b,document=c,Math=d,angular=e,AuthenticationContext=f}}!function(){if(angular){var a=angular.module("AdalAngular",[]);a.provider("adalAuthenticationService",function(){var a=null,b={isAuthenticated:!1,userName:"",loginError:"",profile:""},c=function(c){var d=a.getCachedToken(c);b.isAuthenticated=null!==d&&d.length>0;var e=a.getCachedUser()||{userName:""};b.userName=e.userName,b.profile=e.profile,b.loginError=a.getLoginError()};this.init=function(b,d){if(!b)throw new Error("You must set configOptions, when calling init");var e=window.location.hash,f=window.location.href;e&&(f=f.replace(e,"")),b.redirectUri=b.redirectUri||f,b.postLogoutRedirectUri=b.postLogoutRedirectUri||f,d&&d.interceptors&&d.interceptors.push("ProtectedResourceInterceptor"),a=new AuthenticationContext(b),c(a.config.loginResource)},this.$get=["$rootScope","$window","$q","$location","$timeout",function(d,e,f,g,h){var i=function(){var f=e.location.hash;if(a.isCallback(f)){var i=a.getRequestInfo(f);if(a.saveTokenFromHash(i),e.location.hash="",i.requestType!==a.REQUEST_TYPE.LOGIN&&(a.callback=e.parent.AuthenticationContext().callback),i.stateMatch)if("function"==typeof a.callback){if(i.requestType===a.REQUEST_TYPE.RENEW_TOKEN){if(i.parameters.access_token)return void a.callback(a._getItem(a.CONSTANTS.STORAGE.ERROR_DESCRIPTION),i.parameters.access_token);if(i.parameters.id_token)return void a.callback(a._getItem(a.CONSTANTS.STORAGE.ERROR_DESCRIPTION),i.parameters.id_token)}}else c(a.config.loginResource),b.userName?(h(function(){c(a.config.loginResource),d.userInfo=b;var e=a._getItem(a.CONSTANTS.STORAGE.START_PAGE);e&&g.path(e)},1),d.$broadcast("adal:loginSuccess")):d.$broadcast("adal:loginFailure",a._getItem(a.CONSTANTS.STORAGE.ERROR_DESCRIPTION))}else c(a.config.loginResource),a._renewActive||b.isAuthenticated||!b.userName||a._getItem(a.CONSTANTS.STORAGE.FAILED_RENEW)||a.acquireToken(a.config.loginResource,function(a,c){a?d.$broadcast("adal:loginFailure","auto renew failure"):c&&(b.isAuthenticated=!0)});h(function(){c(a.config.loginResource),d.userInfo=b},1)},j=function(c,e){e.$$route&&e.$$route.requireADLogin&&(b.isAuthenticated||(console.log("Route change event for:"+e.$$route.originalPath),a.config&&a.config.localLoginUrl?g.path(a.config.localLoginUrl):(a._saveItem(a.CONSTANTS.STORAGE.START_PAGE,e.$$route.originalPath),console.log("Start login at:"+window.location.href),d.$broadcast("adal:loginRedirect"),a.login())))};return d.$on("$routeChangeStart",j),d.$on("$locationChangeStart",i),c(a.config.loginResource),d.userInfo=b,{config:a.config,login:function(){a.login()},loginInProgress:function(){return a.loginInProgress()},logOut:function(){a.logOut()},getCachedToken:function(b){return a.getCachedToken(b)},userInfo:b,acquireToken:function(b){var c=f.defer();return a.acquireToken(b,function(b,d){b?(a._logstatus("err :"+b),c.reject(b)):c.resolve(d)}),c.promise},getUser:function(){var b=f.defer();return a.getUser(function(c,d){c?(a._logstatus("err :"+c),b.reject(c)):b.resolve(d)}),b.promise},getResourceForEndpoint:function(b){return a.getResourceForEndpoint(b)},clearCache:function(){a.clearCache()},clearCacheForResource:function(b){a.clearCacheForResource(b)}}}]}),a.factory("ProtectedResourceInterceptor",["adalAuthenticationService","$q","$rootScope",function(a,b,c){return{request:function(c){if(c){c.headers=c.headers||{};var d=a.getResourceForEndpoint(c.url),e=a.getCachedToken(d);if(e)return c.headers.Authorization="Bearer "+e,c;if(a.loginInProgress())return b.reject();if(a.config&&d!==a.config.clientId){var f=b.defer();return a.acquireToken(d).then(function(a){c.headers.Authorization="Bearer "+a,f.resolve(c)},function(a){f.reject(a)}),f.promise}return c}},responseError:function(d){if(d&&401===d.status){var e=a.getResourceForEndpoint(d.config.url);a.clearCacheForResource(e),c.$broadcast("adal:notAuthorized",d,e)}return b.reject(d)}}}])}else console.log("Angular.JS is not included")}(); \ No newline at end of file diff --git a/dist/adal.min.js b/dist/adal.min.js index adfc3f50..f462181c 100644 --- a/dist/adal.min.js +++ b/dist/adal.min.js @@ -1,2 +1,2 @@ -/* adal.js v.0.0.1 https://github.com/AzureAD/azure-activedirectory-library-for-js*/ -'use strict'; var AuthenticationContext; if (typeof module !== 'undefined' && module.exports) { var window, localStorage, angular, document; module.exports.inject = function (windowInj, localStorageInj, documentInj, MathInj, angularInj, conf) { window = windowInj; localStorage = localStorageInj; document = documentInj; Math = MathInj; angular = angularInj; return new AuthenticationContext(conf) } } AuthenticationContext = function (config) { this.REQUEST_TYPE = { LOGIN: 'LOGIN', RENEW_TOKEN: 'RENEW_TOKEN', ID_TOKEN: 'ID_TOKEN', UNKNOWN: 'UNKNOWN' }; this.CONSTANTS = { STORAGE: { TOKEN_KEYS: 'adal.token.keys', ACCESS_TOKEN_KEY: 'adal.access.token.key', EXPIRATION_KEY: 'adal.expiration.key', START_PAGE: 'adal.start.page', FAILED_RENEW: 'adal.failed.renew', STATE_LOGIN: 'adal.state.login', STATE_RENEW: 'adal.state.renew', STATE_RENEW_RESOURCE: 'adal.state.renew.resource', STATE_IDTOKEN: 'adal.state.idtoken', NONCE_IDTOKEN: 'adal.nonce.idtoken', SESSION_STATE: 'adal.session.state', USERNAME: 'adal.username', IDTOKEN: 'adal.idtoken', ERROR: 'adal.error', ERROR_DESCRIPTION: 'adal.error.description', LOGIN_REQUEST: 'adal.login.request', LOGIN_ERROR: 'adal.login.error' }, RESOURCE_DELIMETER: '|', ERR_MESSAGES: { NO_TOKEN: 'User is not authorized' } }; if (AuthenticationContext.prototype._singletonInstance) { return AuthenticationContext.prototype._singletonInstance } AuthenticationContext.prototype._singletonInstance = this; this.instance = 'https://login.windows.net/'; this.config = {}; this.callback = null; this.popUp = false; this._user = null; this._renewActive = false; this._loginInProgress = false; this._renewStates = []; if (config.displayCall && typeof config.displayCall !== 'function') { throw new Error('displayCall is not a function') } if (!config.clientId) { throw new Error('clientId is required') } this.config = this._cloneConfig(config); if (!this.config.loginResource) { this.config.loginResource = this.config.clientId } if (!this.config.redirectUri) { this.config.redirectUri = window.location.href } this.config.resource = this.config.loginResource || '' }; AuthenticationContext.prototype.login = function () { var expectedState = this._guid(); this.config.state = expectedState; this._idTokenNonce = this._guid(); this._logstatus('Expected state: ' + expectedState + ' startPage:' + window.location); this._saveItem(this.CONSTANTS.STORAGE.LOGIN_REQUEST, window.location); this._saveItem(this.CONSTANTS.STORAGE.LOGIN_ERROR, ''); this._saveItem(this.CONSTANTS.STORAGE.STATE_LOGIN, expectedState); this._saveItem(this.CONSTANTS.STORAGE.NONCE_IDTOKEN, this._idTokenNonce); this._saveItem(this.CONSTANTS.STORAGE.FAILED_RENEW, ''); this._saveItem(this.CONSTANTS.STORAGE.ERROR, ''); this._saveItem(this.CONSTANTS.STORAGE.ERROR_DESCRIPTION, ''); var urlNavigate = this._getNavigateUrl('id_token', null) + '&nonce=' + encodeURIComponent(this._idTokenNonce); this.frameCallInProgress = false; this._loginInProgress = true; if (this.config.displayCall) { this.config.displayCall(urlNavigate) } else { this.promptUser(urlNavigate) } }; AuthenticationContext.prototype.loginInProgress = function () { return this._loginInProgress }; AuthenticationContext.prototype._hasResource = function (key) { var keys = this._getItem(this.CONSTANTS.STORAGE.TOKEN_KEYS); return keys && !this._isEmpty(keys) && (keys.indexOf(key + this.CONSTANTS.RESOURCE_DELIMETER) > -1) }; AuthenticationContext.prototype.getCachedToken = function (resource) { if (!this._hasResource(resource)) { return null } var token = this._getItem(this.CONSTANTS.STORAGE.ACCESS_TOKEN_KEY + resource); var expired = this._getItem(this.CONSTANTS.STORAGE.EXPIRATION_KEY + resource); var offset = this.config.expireOffsetSeconds || 120; if (expired && (expired > this._now() + offset)) { return token } else { this._saveItem(this.CONSTANTS.STORAGE.ACCESS_TOKEN_KEY + resource, ''); this._saveItem(this.CONSTANTS.STORAGE.EXPIRATION_KEY + resource, 0); return null } }; AuthenticationContext.prototype.getCachedUser = function () { if (this._user) { return this._user } var idtoken = this._getItem(this.CONSTANTS.STORAGE.IDTOKEN); this._user = this._createUser(idtoken); return this._user }; AuthenticationContext.prototype._renewToken = function (resource, callback) { this._logstatus('renewToken is called for resource:' + resource); if (!this._hasResource(resource)) { var keys = this._getItem(this.CONSTANTS.STORAGE.TOKEN_KEYS) || ''; this._saveItem(this.CONSTANTS.STORAGE.TOKEN_KEYS, keys + resource + this.CONSTANTS.RESOURCE_DELIMETER) } var frameHandle = this._addAdalFrame('adalRenewFrame'); var expectedState = this._guid() + '|' + resource; this.config.state = expectedState; this._renewStates.push(expectedState); this._saveItem(this.CONSTANTS.STORAGE.FAILED_RENEW, ''); this._logstatus('Renew token Expected state: ' + expectedState); var urlNavigate = this._getNavigateUrl('token', resource) + '&prompt=none&login_hint=' + encodeURIComponent(this._user.userName); urlNavigate += '&domain_hint=' + encodeURIComponent(this._getDomainHint()); urlNavigate += '&nonce=' + encodeURIComponent(this._idTokenNonce); this.callback = callback; this.idTokenNonce = null; this._logstatus('Navigate to:' + urlNavigate); this._saveItem(this.CONSTANTS.STORAGE.LOGIN_REQUEST, ''); frameHandle.src = 'about:blank'; this._loadFrame(urlNavigate, 'adalRenewFrame') }; AuthenticationContext.prototype._renewIdToken = function (callback) { this._logstatus('renewIdToken is called'); if (!this._hasResource(this.config.clientId)) { var keys = this._getItem(this.CONSTANTS.STORAGE.TOKEN_KEYS) || ''; this._saveItem(this.CONSTANTS.STORAGE.TOKEN_KEYS, keys + this.config.clientId + this.CONSTANTS.RESOURCE_DELIMETER) } var frameHandle = this._addAdalFrame('adalIdTokenFrame'); var expectedState = this._guid() + '|' + this.config.clientId; this._idTokenNonce = this._guid(); this._saveItem(this.CONSTANTS.STORAGE.NONCE_IDTOKEN, this._idTokenNonce); this.config.state = expectedState; this._renewStates.push(expectedState); this._saveItem(this.CONSTANTS.STORAGE.STATE_RENEW, expectedState); this._saveItem(this.CONSTANTS.STORAGE.FAILED_RENEW, ''); this._logstatus('Renew token Expected state: ' + expectedState); var urlNavigate = this._getNavigateUrl('id_token', null) + '&prompt=none&login_hint=' + encodeURIComponent(this._user.userName); urlNavigate += '&domain_hint=' + encodeURIComponent(this._getDomainHint()); urlNavigate += '&nonce=' + encodeURIComponent(this._idTokenNonce); this.callback = callback; this.idTokenNonce = null; this._logstatus('Navigate to:' + urlNavigate); this._saveItem(this.CONSTANTS.STORAGE.LOGIN_REQUEST, ''); frameHandle.src = 'about:blank'; this._loadFrame(urlNavigate, 'adalIdTokenFrame') }; AuthenticationContext.prototype._loadFrame = function (urlNavigate, frameName) { var self = this; setTimeout(function () { var frameHandle = self._addAdalFrame(frameName); if (frameHandle.src === '' || frameHandle.src === 'about:blank') { frameHandle.src = urlNavigate; self._loadFrame(urlNavigate) } }, 500) }; AuthenticationContext.prototype.acquireToken = function (resource, callback) { if (this._isEmpty(resource)) { callback('resource is required', null); return } var token = this.getCachedToken(resource); if (token) { this._logstatus('Token in cache'); callback(null, token); return } if (this._getItem(this.CONSTANTS.STORAGE.FAILED_RENEW)) { this._logstatus('renewToken is failed:' + this._getItem(this.CONSTANTS.STORAGE.FAILED_RENEW)); callback(this._getItem(this.CONSTANTS.STORAGE.FAILED_RENEW), null); return } if (!this._user) { callback('User login is required', null); return } this._renewActive = true; if (resource === this.config.clientId) { this._logstatus('renewing idtoken'); this._renewIdToken(callback) } else { this._renewToken(resource, callback) } }; AuthenticationContext.prototype.promptUser = function (urlNavigate) { if (urlNavigate) { this._logstatus('Navigate to:' + urlNavigate); window.location.replace(urlNavigate) } else { this._logstatus('Navigate url is empty') } }; AuthenticationContext.prototype.clearCache = function () { this._saveItem(this.CONSTANTS.STORAGE.ACCESS_TOKEN_KEY, ''); this._saveItem(this.CONSTANTS.STORAGE.EXPIRATION_KEY, 0); this._saveItem(this.CONSTANTS.STORAGE.FAILED_RENEW, ''); this._saveItem(this.CONSTANTS.STORAGE.SESSION_STATE, ''); this._saveItem(this.CONSTANTS.STORAGE.STATE_LOGIN, ''); this._renewStates = []; this._saveItem(this.CONSTANTS.STORAGE.STATE_IDTOKEN, ''); this._saveItem(this.CONSTANTS.STORAGE.START_PAGE, ''); this._saveItem(this.CONSTANTS.STORAGE.USERNAME, ''); this._saveItem(this.CONSTANTS.STORAGE.IDTOKEN, ''); this._saveItem(this.CONSTANTS.STORAGE.ERROR, ''); this._saveItem(this.CONSTANTS.STORAGE.ERROR_DESCRIPTION, ''); var keys = this._getItem(this.CONSTANTS.STORAGE.TOKEN_KEYS); if (!this._isEmpty(keys)) { keys = keys.split(this.CONSTANTS.RESOURCE_DELIMETER); for (var i = 0; i < keys.length; i++) { this._saveItem(this.CONSTANTS.STORAGE.ACCESS_TOKEN_KEY + keys[i], ''); this._saveItem(this.CONSTANTS.STORAGE.EXPIRATION_KEY + keys[i], 0) } } this._saveItem(this.CONSTANTS.STORAGE.TOKEN_KEYS, '') }; AuthenticationContext.prototype.clearCacheForResource = function (resource) { this._saveItem(this.CONSTANTS.STORAGE.FAILED_RENEW, ''); this._saveItem(this.CONSTANTS.STORAGE.STATE_RENEW, ''); this._saveItem(this.CONSTANTS.STORAGE.STATE_IDTOKEN, ''); this._saveItem(this.CONSTANTS.STORAGE.ERROR, ''); this._saveItem(this.CONSTANTS.STORAGE.ERROR_DESCRIPTION, ''); if (this._hasResource(resource)) { this._saveItem(this.CONSTANTS.STORAGE.ACCESS_TOKEN_KEY + resource, ''); this._saveItem(this.CONSTANTS.STORAGE.EXPIRATION_KEY + resource, 0) } }; AuthenticationContext.prototype.logOut = function () { this.clearCache(); var tenant = 'common'; var logout = ''; this._user = null; if (this.config.tenant) { tenant = this.config.tenant } if (this.config.instance) { this.instance = this.config.instance } if (this.config.postLogoutRedirectUri) { logout = 'post_logout_redirect_uri=' + encodeURIComponent(this.config.postLogoutRedirectUri) } var urlNavigate = this.instance + tenant + '/oauth2/logout?' + logout; this._logstatus('Logout navigate to: ' + urlNavigate); this.promptUser(urlNavigate) }; AuthenticationContext.prototype._isEmpty = function (str) { return (typeof str === 'undefined' || !str || 0 === str.length) }; AuthenticationContext.prototype.getUser = function (callback) { if (typeof callback !== 'function') { throw new Error('callback is not a function') } this.callback = callback; if (this._user) { this.callback(null, this._user); return } var idtoken = this._getItem(this.CONSTANTS.STORAGE.IDTOKEN); if (!this._isEmpty(idtoken)) { this._logstatus('User exists in cache: '); this._user = this._createUser(idtoken); this.callback(null, this._user) } else { this.callback('User information is not available') } }; AuthenticationContext.prototype._getDomainHint = function () { if (this._user && this._user.userName && this._user.userName.indexOf('@') > -1) { var parts = this._user.userName.split('@'); return parts[parts.length - 1] } return '' }; AuthenticationContext.prototype._createUser = function (idToken) { var user = null; var parsedJson = this._extractIdToken(idToken); if (parsedJson && parsedJson.hasOwnProperty('aud')) { if (parsedJson.aud.toLowerCase() === this.config.clientId.toLowerCase()) { user = { userName: '', profile: parsedJson }; if (parsedJson.hasOwnProperty('upn')) { user.userName = parsedJson.upn } else if (parsedJson.hasOwnProperty('email')) { user.userName = parsedJson.email } } else { this._logstatus('IdToken has invalid aud field') } } return user }; AuthenticationContext.prototype._getHash = function (hash) { if (hash.indexOf('#/') > -1) { hash = hash.substring(hash.indexOf('#/') + 2) } else if (hash.indexOf('#') > -1) { hash = hash.substring(1) } return hash }; AuthenticationContext.prototype.isCallback = function (hash) { hash = this._getHash(hash); var parameters = this._deserialize(hash); return (parameters.hasOwnProperty('error_description') || parameters.hasOwnProperty('access_token') || parameters.hasOwnProperty('id_token')) }; AuthenticationContext.prototype.getLoginError = function () { return this._getItem(this.CONSTANTS.STORAGE.LOGIN_ERROR) }; AuthenticationContext.prototype.getRequestInfo = function (hash) { hash = this._getHash(hash); var parameters = this._deserialize(hash); var requestInfo = { valid: false, parameters: {}, stateMatch: false, stateResponse: '', requestType: this.REQUEST_TYPE.UNKNOWN }; if (parameters) { requestInfo.parameters = parameters; if (parameters.hasOwnProperty('error_description') || parameters.hasOwnProperty('access_token') || parameters.hasOwnProperty('id_token')) { requestInfo.valid = true; var stateResponse = ''; if (parameters.hasOwnProperty('state')) { this._logstatus('State: ' + parameters.state); stateResponse = parameters.state } else { this._logstatus('No state returned') } requestInfo.stateResponse = stateResponse; switch (stateResponse) { case this._getItem(this.CONSTANTS.STORAGE.STATE_LOGIN): requestInfo.requestType = this.REQUEST_TYPE.LOGIN; requestInfo.stateMatch = true; break; case this._getItem(this.CONSTANTS.STORAGE.STATE_IDTOKEN): requestInfo.requestType = this.REQUEST_TYPE.ID_TOKEN; this._saveItem(this.CONSTANTS.STORAGE.STATE_IDTOKEN, ''); requestInfo.stateMatch = true; break } if (!requestInfo.stateMatch && window.parent && window.parent.AuthenticationContext()) { var statesInParentContext = window.parent.AuthenticationContext()._renewStates; for (var i = 0; i < statesInParentContext.length; i++) { if (statesInParentContext[i] === requestInfo.stateResponse) { requestInfo.requestType = this.REQUEST_TYPE.RENEW_TOKEN; requestInfo.stateMatch = true; break } } } } } return requestInfo }; AuthenticationContext.prototype._getResourceFromState = function (state) { if (state) { var splitIndex = state.indexOf('|'); if (splitIndex > -1 && splitIndex + 1 < state.length) { return state.substring(splitIndex + 1) } } return '' }; AuthenticationContext.prototype.saveTokenFromHash = function (requestInfo) { this._logstatus('State status:' + requestInfo.stateMatch); this._saveItem(this.CONSTANTS.STORAGE.ERROR, ''); this._saveItem(this.CONSTANTS.STORAGE.ERROR_DESCRIPTION, ''); if (requestInfo.parameters.hasOwnProperty('error_description')) { this._logstatus('Error :' + requestInfo.parameters.error); this._logstatus('Error description:' + requestInfo.parameters['error_description']); this._saveItem(this.CONSTANTS.STORAGE.FAILED_RENEW, requestInfo.parameters['error_description']); this._saveItem(this.CONSTANTS.STORAGE.ERROR, requestInfo.parameters.error); this._saveItem(this.CONSTANTS.STORAGE.ERROR_DESCRIPTION, requestInfo.parameters['error_description']); if (requestInfo.requestType === this.REQUEST_TYPE.LOGIN) { this._loginInProgress = false; this._saveItem(this.CONSTANTS.STORAGE.LOGIN_ERROR, requestInfo.parameters.errorDescription) } else { this._renewActive = false } } else { if (requestInfo.stateMatch) { this._logstatus('State is right'); if (requestInfo.parameters.hasOwnProperty('session_state')) { this._saveItem(this.CONSTANTS.STORAGE.SESSION_STATE, requestInfo.parameters['session_state']) } var keys, resource; if (requestInfo.parameters.hasOwnProperty('access_token')) { this._logstatus('Fragment has access token'); this._renewActive = false; resource = this.config.loginResource; if (!this._hasResource(resource)) { keys = this._getItem(this.CONSTANTS.STORAGE.TOKEN_KEYS) || ''; this._saveItem(this.CONSTANTS.STORAGE.TOKEN_KEYS, keys + resource + this.CONSTANTS.RESOURCE_DELIMETER) } if (requestInfo.requestType === this.REQUEST_TYPE.RENEW_TOKEN) { resource = this._getResourceFromState(requestInfo.stateResponse) } this._saveItem(this.CONSTANTS.STORAGE.ACCESS_TOKEN_KEY + resource, requestInfo.parameters['access_token']); this._saveItem(this.CONSTANTS.STORAGE.EXPIRATION_KEY + resource, this._expiresIn(requestInfo.parameters['expires_in'])) } if (requestInfo.parameters.hasOwnProperty('id_token')) { this._loginInProgress = false; this._user = this._createUser(requestInfo.parameters['id_token']); if (this._user && this._user.profile) { if (this._user.profile.nonce !== this._getItem(this.CONSTANTS.STORAGE.NONCE_IDTOKEN)) { this._user = null; this._saveItem(this.CONSTANTS.STORAGE.LOGIN_ERROR, 'Nonce is not same as ' + this._idTokenNonce) } else { this._saveItem(this.CONSTANTS.STORAGE.IDTOKEN, requestInfo.parameters['id_token']); resource = this.config.clientId; if (!this._hasResource(resource)) { keys = this._getItem(this.CONSTANTS.STORAGE.TOKEN_KEYS) || ''; this._saveItem(this.CONSTANTS.STORAGE.TOKEN_KEYS, keys + resource + this.CONSTANTS.RESOURCE_DELIMETER) } this._saveItem(this.CONSTANTS.STORAGE.ACCESS_TOKEN_KEY + resource, requestInfo.parameters['id_token']); this._saveItem(this.CONSTANTS.STORAGE.EXPIRATION_KEY + resource, this._user.profile.exp) } } } } else { this._saveItem(this.CONSTANTS.STORAGE.ERROR, 'Invalid_state'); this._saveItem(this.CONSTANTS.STORAGE.ERROR_DESCRIPTION, 'Invalid_state'); if (requestInfo.requestType === this.REQUEST_TYPE.LOGIN) { this._saveItem(this.CONSTANTS.STORAGE.LOGIN_ERROR, 'State is not same as ' + requestInfo.stateResponse) } } } }; AuthenticationContext.prototype.getResourceForEndpoint = function (endpoint) { if (this.config && this.config.endpoints) { for (var configEndpoint in this.config.endpoints) { if (endpoint.indexOf(configEndpoint) > -1) { return this.config.endpoints[configEndpoint] } } } return this.config.loginResource }; AuthenticationContext.prototype.handleWindowCallback = function () { var hash = window.location.hash; if (this.isCallback(hash)) { var requestInfo = this.getRequestInfo(hash); this.saveTokenFromHash(requestInfo); var callback = null; if ((requestInfo.requestType === this.REQUEST_TYPE.RENEW_TOKEN || requestInfo.requestType === this.REQUEST_TYPE.ID_TOKEN) && window.parent) { console.log('Window is in iframe'); callback = window.parent.AuthenticationContext().callback; window.src = '' } else if (window && window.oauth2Callback) { console.log('Window is redirecting'); callback = this.callback } window.location.hash = ''; if (requestInfo.requestType === this.REQUEST_TYPE.RENEW_TOKEN) { callback(this._getItem(this.CONSTANTS.STORAGE.ERROR_DESCRIPTION), requestInfo.parameters['access_token']); return } else if (requestInfo.requestType === this.REQUEST_TYPE.ID_TOKEN) { callback(this._getItem(this.CONSTANTS.STORAGE.ERROR_DESCRIPTION), this._createUser(this._getItem(this.CONSTANTS.STORAGE.IDTOKEN))); return } } }; AuthenticationContext.prototype._getNavigateUrl = function (responseType, resource) { var tenant = 'common'; if (this.config.tenant) { tenant = this.config.tenant } if (this.config.instance) { this.instance = this.config.instance } var urlNavigate = this.instance + tenant + '/oauth2/authorize' + this._serialize(responseType, this.config, resource); console.log('Navigate url:' + urlNavigate); return urlNavigate }; AuthenticationContext.prototype._extractIdToken = function (encodedIdToken) { var decodedToken = this._decodeJwt(encodedIdToken); if (!decodedToken) { return null } try { var base64IdToken = decodedToken.JWSPayload; var base64Decoded = this._base64DecodeStringUrlSafe(base64IdToken); if (!base64Decoded) { this._logstatus('The returned id_token could not be base64 url safe decoded.'); return null } return JSON.parse(base64Decoded) } catch (err) { this._logstatus('The returned id_token could not be decoded: ' + err.stack) } return null }; AuthenticationContext.prototype._extractUserName = function (encodedIdToken) { try { var parsed = this._extractIdToken(encodedIdToken); if (parsed) { if (parsed.hasOwnProperty('upn')) { return parsed.upn } else if (parsed.hasOwnProperty('email')) { return parsed.email } } } catch (err) { this._logstatus('The returned id_token could not be decoded: ' + err.stack) } return null }; AuthenticationContext.prototype._base64DecodeStringUrlSafe = function (base64IdToken) { if (window.atob) { return window.atob(base64IdToken) } this._logstatus('Browser is not supported'); return null }; AuthenticationContext.prototype._decodeJwt = function (jwtToken) { var idTokenPartsRegex = /^([^\.\s]*)\.([^\.\s]+)\.([^\.\s]*)$/; var matches = idTokenPartsRegex.exec(jwtToken); if (!matches || matches.length < 4) { this._logstatus('The returned id_token is not parseable.'); return null } var crackedToken = { header: matches[1], JWSPayload: matches[2], JWSSig: matches[3] }; return crackedToken }; AuthenticationContext.prototype._convertUrlSafeToRegularBase64EncodedString = function (str) { return str.replace('-', '+').replace('_', '/') }; AuthenticationContext.prototype._serialize = function (responseType, obj, resource) { var str = []; if (obj !== null) { str.push('?response_type=' + responseType); str.push('client_id=' + encodeURIComponent(obj.clientId)); if (resource) { str.push('resource=' + encodeURIComponent(resource)) } str.push('redirect_uri=' + encodeURIComponent(obj.redirectUri)); str.push('state=' + encodeURIComponent(obj.state)); if (obj.hasOwnProperty('slice')) { str.push('slice=' + encodeURIComponent(obj.slice)) } if (obj.hasOwnProperty('extraQueryParameter')) { str.push(obj.extraQueryParameter) } } return str.join('&') }; AuthenticationContext.prototype._deserialize = function (query) { var match, pl = /\+/g, search = /([^&=]+)=?([^&]*)/g, decode = function (s) { return decodeURIComponent(s.replace(pl, ' ')) }, obj = {}; match = search.exec(query); while (match) { obj[decode(match[1])] = decode(match[2]); match = search.exec(query) } return obj }; AuthenticationContext.prototype._guid = function () { var guidHolder = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'; var hex = '0123456789abcdef'; var r = 0; var guidResponse = ""; for (var i = 0; i < 36; i++) { if (guidHolder[i] !== '-' && guidHolder[i] !== '4') { r = Math.random() * 16 | 0 } if (guidHolder[i] === 'x') { guidResponse += hex[r] } else if (guidHolder[i] === 'y') { r &= 0x3; r |= 0x8; guidResponse += hex[r] } else { guidResponse += guidHolder[i] } } return guidResponse }; AuthenticationContext.prototype._expiresIn = function (expires) { return this._now() + parseInt(expires, 10) }; AuthenticationContext.prototype._now = function () { return Math.round(new Date().getTime() / 1000.0) }; AuthenticationContext.prototype._addAdalFrame = function (iframeId) { this._logstatus('Add adal frame to document:' + iframeId); var adalFrame = document.getElementById(iframeId); if (!adalFrame) { if (document.createElement && document.documentElement && (window.opera || window.navigator.userAgent.indexOf('MSIE 5.0') === -1)) { var ifr = document.createElement('iframe'); ifr.setAttribute('id', iframeId); ifr.style.visibility = 'hidden'; ifr.style.position = 'absolute'; ifr.style.width = ifr.style.height = ifr.borderWidth = '0px'; adalFrame = document.getElementsByTagName('body')[0].appendChild(ifr) } else if (document.body && document.body.insertAdjacentHTML) { document.body.insertAdjacentHTML('beforeEnd', '') } if (window.frames && window.frames[iframeId]) { adalFrame = window.frames[iframeId] } } return adalFrame }; AuthenticationContext.prototype._logstatus = function (msg) { if (console) { console.log(msg) } }; AuthenticationContext.prototype._saveItem = function (key, obj) { if (!this._supportsLocalStorage()) { this._logStatus('Local storage is not supported'); return false } localStorage.setItem(key, obj); return true }; AuthenticationContext.prototype._getItem = function (key) { if (!this._supportsLocalStorage()) { this._logstatus('Local storage is not supported'); return null } return localStorage.getItem(key) }; AuthenticationContext.prototype._supportsLocalStorage = function () { try { return 'localStorage' in window && window['localStorage'] } catch (e) { return false } }; AuthenticationContext.prototype._cloneConfig = function (obj) { if (null === obj || 'object' !== typeof obj) { return obj } var copy = {}; for (var attr in obj) { if (obj.hasOwnProperty(attr)) { copy[attr] = obj[attr] } } return copy }; function adalAngularModules() { if (typeof angular !== 'undefined') { var AdalModule = angular.module('AdalAngular', []); AdalModule.factory('ProtectedResourceInterceptor', ['$q', '$rootScope', '$injector', function ($q, $rootScope, $injector) { var authService; var injectAuthService = function () { authService = authService || $injector.get('adalAuthenticationService') }; return { request: function (config) { if (config) { if (!$injector.has('adalAuthenticationService')) { return config } injectAuthService(); authService = authService || $injector.get('adalAuthenticationService'); config.headers = config.headers || {}; var resource = authService.getResourceForEndpoint(config.url); var tokenStored = authService.getCachedToken(resource); if (tokenStored) { config.headers.Authorization = 'Bearer ' + tokenStored; return config } else { if (authService.loginInProgress()) { $q.reject(); return } else if (authService.config && resource !== authService.config.clientId) { var delayedRequest = $q.defer(); authService.acquireToken(resource).then(function (token) { config.headers.Authorization = 'Bearer ' + token; delayedRequest.resolve(config) }, function (err) { delayedRequest.reject(err) }); return delayedRequest.promise } } return config } }, responseError: function (rejection) { if (rejection.status === 401) { injectAuthService(); var resource = authService.getResourceForEndpoint(rejection.config.url); authService.clearCacheForResource(resource); $rootScope.$broadcast('adal:notAuthorized', rejection, resource) } return $q.reject(rejection) } } }]); var AdalService = function () { var _adal = null; var _oauthData = { isAuthenticated: false, userName: '', loginError: '', profile: '' }; var updateDataFromCache = function (resource) { var token = _adal.getCachedToken(resource); _oauthData.isAuthenticated = token !== null && token.length > 0; var user = _adal.getCachedUser() || { userName: '' }; _oauthData.userName = user.userName; _oauthData.profile = user.profile; _oauthData.loginError = _adal.getLoginError() }; this.init = function (configOptions, httpProvider) { if (configOptions) { var existingHash = window.location.hash; var pathDefault = window.location.href; if (existingHash) { pathDefault = pathDefault.replace(existingHash, '') } configOptions.redirectUri = configOptions.redirectUri || pathDefault; configOptions.postLogoutRedirectUri = configOptions.postLogoutRedirectUri || pathDefault; if (httpProvider && httpProvider.interceptors) { httpProvider.interceptors.push('ProtectedResourceInterceptor') } _adal = new AuthenticationContext(configOptions) } else { throw new Error('You must set configOptions, when calling init') } updateDataFromCache(_adal.config.loginResource) }; this.$get = function ($rootScope, $window, $http, $q, $location, $timeout) { var locationChangeHandler = function () { var hash = $window.location.hash; if (_adal.isCallback(hash)) { var requestInfo = _adal.getRequestInfo(hash); _adal.saveTokenFromHash(requestInfo); $window.location.hash = ''; if (requestInfo.requestType !== _adal.REQUEST_TYPE.LOGIN) { _adal.callback = $window.parent.AuthenticationContext().callback } if (requestInfo.stateMatch) { if (typeof _adal.callback === 'function') { if (requestInfo.requestType === _adal.REQUEST_TYPE.RENEW_TOKEN) { if (requestInfo.parameters['access_token']) { _adal.callback(_adal._getItem(_adal.CONSTANTS.STORAGE.ERROR_DESCRIPTION), requestInfo.parameters['access_token']); return } else if (requestInfo.parameters['id_token']) { _adal.callback(_adal._getItem(_adal.CONSTANTS.STORAGE.ERROR_DESCRIPTION), requestInfo.parameters['id_token']); return } } } else { updateDataFromCache(_adal.config.loginResource); if (_oauthData.userName) { $timeout(function () { updateDataFromCache(_adal.config.loginResource); $rootScope.userInfo = _oauthData; var loginStartPage = _adal._getItem(_adal.CONSTANTS.STORAGE.START_PAGE); if (loginStartPage) { $location.path(loginStartPage) } }, 1); $rootScope.$broadcast('adal:loginSuccess') } else { $rootScope.$broadcast('adal:loginFailure', _adal._getItem(_adal.CONSTANTS.STORAGE.ERROR_DESCRIPTION)) } } } } else { updateDataFromCache(_adal.config.loginResource); if (!_adal._renewActive && !_oauthData.isAuthenticated && _oauthData.userName) { if (!_adal._getItem(_adal.CONSTANTS.STORAGE.FAILED_RENEW)) { _adal.acquireToken(_adal.config.loginResource, function (error, tokenOut) { if (error) { $rootScope.$broadcast('adal:loginFailure', 'auto renew failure') } else { if (tokenOut) { _oauthData.isAuthenticated = true } } }) } } } $timeout(function () { updateDataFromCache(_adal.config.loginResource); $rootScope.userInfo = _oauthData }, 1) }; var routeChangeHandler = function (e, nextRoute) { if (nextRoute.$$route && nextRoute.$$route.requireADLogin) { if (!_oauthData.isAuthenticated) { console.log('Route change event for:' + nextRoute.$$route.originalPath); if (_adal.config && _adal.config.localLoginUrl) { $location.path(_adal.config.localLoginUrl) } else { _adal._saveItem(_adal.CONSTANTS.STORAGE.START_PAGE, nextRoute.$$route.originalPath); console.log('Start login at:' + window.location.href); $rootScope.$broadcast('adal:loginRedirect'); _adal.login() } } } }; $rootScope.$on('$routeChangeStart', routeChangeHandler); $rootScope.$on('$locationChangeStart', locationChangeHandler); updateDataFromCache(_adal.config.loginResource); $rootScope.userInfo = _oauthData; return { config: _adal.config, login: function () { _adal.login() }, loginInProgress: function () { return _adal.loginInProgress() }, logOut: function () { _adal.logOut() }, getCachedToken: function (resource) { return _adal.getCachedToken(resource) }, userInfo: _oauthData, acquireToken: function (resource) { var deferred = $q.defer(); _adal.acquireToken(resource, function (error, tokenOut) { if (error) { _adal._logstatus('err :' + error); deferred.reject(error) } else { deferred.resolve(tokenOut) } }); return deferred.promise }, getUser: function () { var deferred = $q.defer(); _adal.getUser(function (error, user) { if (error) { _adal._logstatus('err :' + error); deferred.reject(error) } else { deferred.resolve(user) } }); return deferred.promise }, getResourceForEndpoint: function (endpoint) { return _adal.getResourceForEndpoint(endpoint) }, clearCache: function () { _adal.clearCache() }, clearCacheForResource: function (resource) { _adal.clearCacheForResource(resource) } } } }; AdalModule.provider('adalAuthenticationService', function () { return new AdalService() }) } else { console.log('Angular.JS is not included') } } adalAngularModules(); \ No newline at end of file +/*! adal-angular v0.0.4 2014-12-16 */ +"use strict";var AuthenticationContext;if("undefined"!=typeof module&&module.exports){var window,localStorage,angular,document;module.exports.inject=function(a,b,c,d,e,f){return window=a,localStorage=b,document=c,Math=d,angular=e,new AuthenticationContext(f)}}AuthenticationContext=function(a){if(this.REQUEST_TYPE={LOGIN:"LOGIN",RENEW_TOKEN:"RENEW_TOKEN",ID_TOKEN:"ID_TOKEN",UNKNOWN:"UNKNOWN"},this.CONSTANTS={ACCESS_TOKEN:"access_token",EXPIRES_IN:"expires_in",ID_TOKEN:"id_token",ERROR_DESCRIPTION:"error_description",SESSION_STATE:"session_state",STORAGE:{TOKEN_KEYS:"adal.token.keys",ACCESS_TOKEN_KEY:"adal.access.token.key",EXPIRATION_KEY:"adal.expiration.key",START_PAGE:"adal.start.page",FAILED_RENEW:"adal.failed.renew",STATE_LOGIN:"adal.state.login",STATE_RENEW:"adal.state.renew",STATE_RENEW_RESOURCE:"adal.state.renew.resource",STATE_IDTOKEN:"adal.state.idtoken",NONCE_IDTOKEN:"adal.nonce.idtoken",SESSION_STATE:"adal.session.state",USERNAME:"adal.username",IDTOKEN:"adal.idtoken",ERROR:"adal.error",ERROR_DESCRIPTION:"adal.error.description",LOGIN_REQUEST:"adal.login.request",LOGIN_ERROR:"adal.login.error"},RESOURCE_DELIMETER:"|",ERR_MESSAGES:{NO_TOKEN:"User is not authorized"}},AuthenticationContext.prototype._singletonInstance)return AuthenticationContext.prototype._singletonInstance;if(AuthenticationContext.prototype._singletonInstance=this,this.instance="https://login.windows.net/",this.config={},this.callback=null,this.popUp=!1,this._user=null,this._renewActive=!1,this._loginInProgress=!1,this._renewStates=[],a.displayCall&&"function"!=typeof a.displayCall)throw new Error("displayCall is not a function");if(!a.clientId)throw new Error("clientId is required");this.config=this._cloneConfig(a),this.config.loginResource||(this.config.loginResource=this.config.clientId),this.config.redirectUri||(this.config.redirectUri=window.location.href),this.config.resource=this.config.loginResource||""},AuthenticationContext.prototype.login=function(){var a=this._guid();this.config.state=a,this._idTokenNonce=this._guid(),this._logstatus("Expected state: "+a+" startPage:"+window.location),this._saveItem(this.CONSTANTS.STORAGE.LOGIN_REQUEST,window.location),this._saveItem(this.CONSTANTS.STORAGE.LOGIN_ERROR,""),this._saveItem(this.CONSTANTS.STORAGE.STATE_LOGIN,a),this._saveItem(this.CONSTANTS.STORAGE.NONCE_IDTOKEN,this._idTokenNonce),this._saveItem(this.CONSTANTS.STORAGE.FAILED_RENEW,""),this._saveItem(this.CONSTANTS.STORAGE.ERROR,""),this._saveItem(this.CONSTANTS.STORAGE.ERROR_DESCRIPTION,"");var b=this._getNavigateUrl("id_token",null)+"&nonce="+encodeURIComponent(this._idTokenNonce);this.frameCallInProgress=!1,this._loginInProgress=!0,this.config.displayCall?this.config.displayCall(b):this.promptUser(b)},AuthenticationContext.prototype.loginInProgress=function(){return this._loginInProgress},AuthenticationContext.prototype._hasResource=function(a){var b=this._getItem(this.CONSTANTS.STORAGE.TOKEN_KEYS);return b&&!this._isEmpty(b)&&b.indexOf(a+this.CONSTANTS.RESOURCE_DELIMETER)>-1},AuthenticationContext.prototype.getCachedToken=function(a){if(!this._hasResource(a))return null;var b=this._getItem(this.CONSTANTS.STORAGE.ACCESS_TOKEN_KEY+a),c=this._getItem(this.CONSTANTS.STORAGE.EXPIRATION_KEY+a),d=this.config.expireOffsetSeconds||120;return c&&c>this._now()+d?b:(this._saveItem(this.CONSTANTS.STORAGE.ACCESS_TOKEN_KEY+a,""),this._saveItem(this.CONSTANTS.STORAGE.EXPIRATION_KEY+a,0),null)},AuthenticationContext.prototype.getCachedUser=function(){if(this._user)return this._user;var a=this._getItem(this.CONSTANTS.STORAGE.IDTOKEN);return this._user=this._createUser(a),this._user},AuthenticationContext.prototype._renewToken=function(a,b){if(this._logstatus("renewToken is called for resource:"+a),!this._hasResource(a)){var c=this._getItem(this.CONSTANTS.STORAGE.TOKEN_KEYS)||"";this._saveItem(this.CONSTANTS.STORAGE.TOKEN_KEYS,c+a+this.CONSTANTS.RESOURCE_DELIMETER)}var d=this._addAdalFrame("adalRenewFrame"),e=this._guid()+"|"+a;this.config.state=e,this._renewStates.push(e),this._saveItem(this.CONSTANTS.STORAGE.FAILED_RENEW,""),this._logstatus("Renew token Expected state: "+e);var f=this._getNavigateUrl("token",a)+"&prompt=none&login_hint="+encodeURIComponent(this._user.userName);f+="&domain_hint="+encodeURIComponent(this._getDomainHint()),f+="&nonce="+encodeURIComponent(this._idTokenNonce),this.callback=b,this.idTokenNonce=null,this._logstatus("Navigate to:"+f),this._saveItem(this.CONSTANTS.STORAGE.LOGIN_REQUEST,""),d.src="about:blank",this._loadFrame(f,"adalRenewFrame")},AuthenticationContext.prototype._renewIdToken=function(a){if(this._logstatus("renewIdToken is called"),!this._hasResource(this.config.clientId)){var b=this._getItem(this.CONSTANTS.STORAGE.TOKEN_KEYS)||"";this._saveItem(this.CONSTANTS.STORAGE.TOKEN_KEYS,b+this.config.clientId+this.CONSTANTS.RESOURCE_DELIMETER)}var c=this._addAdalFrame("adalIdTokenFrame"),d=this._guid()+"|"+this.config.clientId;this._idTokenNonce=this._guid(),this._saveItem(this.CONSTANTS.STORAGE.NONCE_IDTOKEN,this._idTokenNonce),this.config.state=d,this._renewStates.push(d),this._saveItem(this.CONSTANTS.STORAGE.STATE_RENEW,d),this._saveItem(this.CONSTANTS.STORAGE.FAILED_RENEW,""),this._logstatus("Renew token Expected state: "+d);var e=this._getNavigateUrl("id_token",null)+"&prompt=none&login_hint="+encodeURIComponent(this._user.userName);e+="&domain_hint="+encodeURIComponent(this._getDomainHint()),e+="&nonce="+encodeURIComponent(this._idTokenNonce),this.callback=a,this.idTokenNonce=null,this._logstatus("Navigate to:"+e),this._saveItem(this.CONSTANTS.STORAGE.LOGIN_REQUEST,""),c.src="about:blank",this._loadFrame(e,"adalIdTokenFrame")},AuthenticationContext.prototype._loadFrame=function(a,b){var c=this;setTimeout(function(){var d=c._addAdalFrame(b);(""===d.src||"about:blank"===d.src)&&(d.src=a,c._loadFrame(a))},500)},AuthenticationContext.prototype.acquireToken=function(a,b){if(this._isEmpty(a))return void b("resource is required",null);var c=this.getCachedToken(a);return c?(this._logstatus("Token in cache"),void b(null,c)):this._getItem(this.CONSTANTS.STORAGE.FAILED_RENEW)?(this._logstatus("renewToken is failed:"+this._getItem(this.CONSTANTS.STORAGE.FAILED_RENEW)),void b(this._getItem(this.CONSTANTS.STORAGE.FAILED_RENEW),null)):this._user?(this._renewActive=!0,void(a===this.config.clientId?(this._logstatus("renewing idtoken"),this._renewIdToken(b)):this._renewToken(a,b))):void b("User login is required",null)},AuthenticationContext.prototype.promptUser=function(a){a?(this._logstatus("Navigate to:"+a),window.location.replace(a)):this._logstatus("Navigate url is empty")},AuthenticationContext.prototype.clearCache=function(){this._saveItem(this.CONSTANTS.STORAGE.ACCESS_TOKEN_KEY,""),this._saveItem(this.CONSTANTS.STORAGE.EXPIRATION_KEY,0),this._saveItem(this.CONSTANTS.STORAGE.FAILED_RENEW,""),this._saveItem(this.CONSTANTS.STORAGE.SESSION_STATE,""),this._saveItem(this.CONSTANTS.STORAGE.STATE_LOGIN,""),this._renewStates=[],this._saveItem(this.CONSTANTS.STORAGE.STATE_IDTOKEN,""),this._saveItem(this.CONSTANTS.STORAGE.START_PAGE,""),this._saveItem(this.CONSTANTS.STORAGE.USERNAME,""),this._saveItem(this.CONSTANTS.STORAGE.IDTOKEN,""),this._saveItem(this.CONSTANTS.STORAGE.ERROR,""),this._saveItem(this.CONSTANTS.STORAGE.ERROR_DESCRIPTION,"");var a=this._getItem(this.CONSTANTS.STORAGE.TOKEN_KEYS);if(!this._isEmpty(a)){a=a.split(this.CONSTANTS.RESOURCE_DELIMETER);for(var b=0;b-1){var a=this._user.userName.split("@");return a[a.length-1]}return""},AuthenticationContext.prototype._createUser=function(a){var b=null,c=this._extractIdToken(a);return c&&c.hasOwnProperty("aud")&&(c.aud.toLowerCase()===this.config.clientId.toLowerCase()?(b={userName:"",profile:c},c.hasOwnProperty("upn")?b.userName=c.upn:c.hasOwnProperty("email")&&(b.userName=c.email)):this._logstatus("IdToken has invalid aud field")),b},AuthenticationContext.prototype._getHash=function(a){return a.indexOf("#/")>-1?a=a.substring(a.indexOf("#/")+2):a.indexOf("#")>-1&&(a=a.substring(1)),a},AuthenticationContext.prototype.isCallback=function(a){a=this._getHash(a);var b=this._deserialize(a);return b.hasOwnProperty(this.CONSTANTS.ERROR_DESCRIPTION)||b.hasOwnProperty(this.CONSTANTS.ACCESS_TOKEN)||b.hasOwnProperty(this.CONSTANTS.ID_TOKEN)},AuthenticationContext.prototype.getLoginError=function(){return this._getItem(this.CONSTANTS.STORAGE.LOGIN_ERROR)},AuthenticationContext.prototype.getRequestInfo=function(a){a=this._getHash(a);var b=this._deserialize(a),c={valid:!1,parameters:{},stateMatch:!1,stateResponse:"",requestType:this.REQUEST_TYPE.UNKNOWN};if(b&&(c.parameters=b,b.hasOwnProperty(this.CONSTANTS.ERROR_DESCRIPTION)||b.hasOwnProperty(this.CONSTANTS.ACCESS_TOKEN)||b.hasOwnProperty(this.CONSTANTS.ID_TOKEN))){c.valid=!0;var d="";switch(b.hasOwnProperty("state")?(this._logstatus("State: "+b.state),d=b.state):this._logstatus("No state returned"),c.stateResponse=d,d){case this._getItem(this.CONSTANTS.STORAGE.STATE_LOGIN):c.requestType=this.REQUEST_TYPE.LOGIN,c.stateMatch=!0;break;case this._getItem(this.CONSTANTS.STORAGE.STATE_IDTOKEN):c.requestType=this.REQUEST_TYPE.ID_TOKEN,this._saveItem(this.CONSTANTS.STORAGE.STATE_IDTOKEN,""),c.stateMatch=!0}if(!c.stateMatch&&window.parent&&window.parent.AuthenticationContext())for(var e=window.parent.AuthenticationContext()._renewStates,f=0;f-1&&b+1-1)return this.config.endpoints[b];return this.config.loginResource},AuthenticationContext.prototype.handleWindowCallback=function(){var a=window.location.hash;if(this.isCallback(a)){var b=this.getRequestInfo(a);this.saveTokenFromHash(b);var c=null;if(b.requestType!==this.REQUEST_TYPE.RENEW_TOKEN&&b.requestType!==this.REQUEST_TYPE.ID_TOKEN||!window.parent?window&&window.oauth2Callback&&(console.log("Window is redirecting"),c=this.callback):(console.log("Window is in iframe"),c=window.parent.AuthenticationContext().callback,window.src=""),window.location.hash="",b.requestType===this.REQUEST_TYPE.RENEW_TOKEN)return void c(this._getItem(this.CONSTANTS.STORAGE.ERROR_DESCRIPTION),b.parameters[this.CONSTANTS.ACCESS_TOKEN]);if(b.requestType===this.REQUEST_TYPE.ID_TOKEN)return void c(this._getItem(this.CONSTANTS.STORAGE.ERROR_DESCRIPTION),this._createUser(this._getItem(this.CONSTANTS.STORAGE.IDTOKEN)))}},AuthenticationContext.prototype._getNavigateUrl=function(a,b){var c="common";this.config.tenant&&(c=this.config.tenant),this.config.instance&&(this.instance=this.config.instance);var d=this.instance+c+"/oauth2/authorize"+this._serialize(a,this.config,b)+this._addClientId();return console.log("Navigate url:"+d),d},AuthenticationContext.prototype._extractIdToken=function(a){var b=this._decodeJwt(a);if(!b)return null;try{var c=b.JWSPayload,d=this._base64DecodeStringUrlSafe(c);return d?JSON.parse(d):(this._logstatus("The returned id_token could not be base64 url safe decoded."),null)}catch(e){this._logstatus("The returned id_token could not be decoded: "+e.stack)}return null},AuthenticationContext.prototype._extractUserName=function(a){try{var b=this._extractIdToken(a);if(b){if(b.hasOwnProperty("upn"))return b.upn;if(b.hasOwnProperty("email"))return b.email}}catch(c){this._logstatus("The returned id_token could not be decoded: "+c.stack)}return null},AuthenticationContext.prototype._base64DecodeStringUrlSafe=function(a){return window.atob?window.atob(a):(this._logstatus("Browser is not supported"),null)},AuthenticationContext.prototype._decodeJwt=function(a){var b=/^([^\.\s]*)\.([^\.\s]+)\.([^\.\s]*)$/,c=b.exec(a);if(!c||c.length<4)return this._logstatus("The returned id_token is not parseable."),null;var d={header:c[1],JWSPayload:c[2],JWSSig:c[3]};return d},AuthenticationContext.prototype._convertUrlSafeToRegularBase64EncodedString=function(a){return a.replace("-","+").replace("_","/")},AuthenticationContext.prototype._serialize=function(a,b,c){var d=[];return null!==b&&(d.push("?response_type="+a),d.push("client_id="+encodeURIComponent(b.clientId)),c&&d.push("resource="+encodeURIComponent(c)),d.push("redirect_uri="+encodeURIComponent(b.redirectUri)),d.push("state="+encodeURIComponent(b.state)),b.hasOwnProperty("slice")&&d.push("slice="+encodeURIComponent(b.slice)),b.hasOwnProperty("extraQueryParameter")&&d.push(b.extraQueryParameter)),d.join("&")},AuthenticationContext.prototype._deserialize=function(a){var b,c=/\+/g,d=/([^&=]+)=?([^&]*)/g,e=function(a){return decodeURIComponent(a.replace(c," "))},f={};for(b=d.exec(a);b;)f[e(b[1])]=e(b[2]),b=d.exec(a);return f},AuthenticationContext.prototype._guid=function(){for(var a="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",b="0123456789abcdef",c=0,d="",e=0;36>e;e++)"-"!==a[e]&&"4"!==a[e]&&(c=16*Math.random()|0),"x"===a[e]?d+=b[c]:"y"===a[e]?(c&=3,c|=8,d+=b[c]):d+=a[e];return d},AuthenticationContext.prototype._expiresIn=function(a){return this._now()+parseInt(a,10)},AuthenticationContext.prototype._now=function(){return Math.round((new Date).getTime()/1e3)},AuthenticationContext.prototype._addAdalFrame=function(a){this._logstatus("Add adal frame to document:"+a);var b=document.getElementById(a);if(!b){if(document.createElement&&document.documentElement&&(window.opera||-1===window.navigator.userAgent.indexOf("MSIE 5.0"))){var c=document.createElement("iframe");c.setAttribute("id",a),c.style.visibility="hidden",c.style.position="absolute",c.style.width=c.style.height=c.borderWidth="0px",b=document.getElementsByTagName("body")[0].appendChild(c)}else document.body&&document.body.insertAdjacentHTML&&document.body.insertAdjacentHTML("beforeEnd",'');window.frames&&window.frames[a]&&(b=window.frames[a])}return b},AuthenticationContext.prototype._logstatus=function(a){console&&console.log(a)},AuthenticationContext.prototype._saveItem=function(a,b){return this._supportsLocalStorage()?(localStorage.setItem(a,b),!0):(this._logStatus("Local storage is not supported"),!1)},AuthenticationContext.prototype._getItem=function(a){return this._supportsLocalStorage()?localStorage.getItem(a):(this._logstatus("Local storage is not supported"),null)},AuthenticationContext.prototype._supportsLocalStorage=function(){try{return"localStorage"in window&&window.localStorage}catch(a){return!1}},AuthenticationContext.prototype._cloneConfig=function(a){if(null===a||"object"!=typeof a)return a;var b={};for(var c in a)a.hasOwnProperty(c)&&(b[c]=a[c]);return b},AuthenticationContext.prototype._libVersion=function(){return"0.0.3"},AuthenticationContext.prototype._addClientId=function(){return"&x-client-SKU=Js&x-client-Ver="+this._libVersion()}; \ No newline at end of file