1(function () { 2 (function (root, factory) { 3 var _, dependencies; 4 _ = root._ || require('lodash'); 5 dependencies = ['bluebird', 'oboe', 'lodash', 'jquery', './utils']; 6 if (typeof define === 'function' && define.amd) { 7 return define(dependencies, factory); 8 } else if (typeof exports === 'object') { 9 return module.exports = factory.apply(this, _.map(dependencies, require)); 10 } else { 11 root.FS || (root.FS = {}); 12 return root.FS.Auth = factory(root.Promise, root.oboe, root._, root.jQuery, root.utils); 13 } 14 })(this, function (Promise, oboe, _, $, utils) { 15 var config, root, Auth; 16 if (!Promise) { 17 throw new Error('Bluebird.js is not available'); 18 } 19 if (!oboe) { 20 throw new Error('oboe.js is not available'); 21 } 22 if (!_) { 23 throw new Error('lodash.js is not available'); 24 } 25 if (!$) { 26 throw new Error('jquery.js is not available'); 27 } 28 if (!utils) { 29 throw new Error('utils is not available'); 30 } 31 config = this.config || utils.defaultConfig; 32 root = this.window || this; 33 Auth = (function () { 34 Auth.displayName = 'Auth'; 35 var prototype = Auth.prototype, constructor = Auth; 36 function Auth(overrideConfig) { 37 this.config = _.extend(config, overrideConfig); 38 this.apiUrlRoot = this.config.authApiUrl.replace(/\/isauthenticated$/i, '/'); 39 this.session = {}; 40 } 41 prototype.toString = function () { 42 return 'FS.Auth'; 43 }; 44 prototype.withConfig = function (overrideConfig) { 45 return new Auth(overrideConfig); 46 }; 47 prototype.apiUrl = function (api, returnUrl, params) { 48 var query, ref$; 49 returnUrl = encodeURIComponent(returnUrl); 50 if (api == null) { 51 throw new Error('API not specified for FS.Auth.apiUrl'); 52 } 53 query = _.extend({ 54 uri: returnUrl || this.config.returnUrl || root.location && root.location.href.replace(/\/[^\/]*$/, '/'), 55 hostname: encodeURIComponent(this.config.hostname || ((ref$ = root.location) != null ? ref$.hostname : void 8)) 56 }, params || {}); 57 if (!query.uri) { 58 throw new Error('Return URL not specified for FS.Auth.apiUrl'); 59 } 60 if (!query.hostname) { 61 throw new Error('Hostname not specified for FS.Auth.apiUrl'); 62 } 63 return [this.apiUrlRoot, api, '?', utils.makeQueryString(query)].join(''); 64 }; 65 prototype.apiCall = function () { 66 var apiArgs, task; 67 apiArgs = arguments; 68 task = Promise.defer(); 69 if (!this.config.streamingEnabled) { 70 $.ajax({ 71 dataType: 'json', 72 url: this.apiUrl.apply(this, apiArgs), 73 data: { 74 withCredentials: true 75 }, 76 success: function (response) { 77 return task.resolve(response); 78 } 79 }); 80 } else { 81 oboe({ 82 url: this.apiUrl.apply(this, apiArgs), 83 data: 'json', 84 xhrFields: { 85 withCredentials: true 86 } 87 }).done(_.bind(task.resolve, task)).fail(_.bind(task.reject, task)); 88 } 89 return task.promise; 90 }; 91 prototype._getWidgetSession = _.memoize(function (widgetKey) { 92 return Promise.attempt(function () { 93 var widgetKey; 94 widgetKey = JSON.parse(root.getItem(widgetKey)); 95 if (!widgetKey) { 96 throw new Error('Widget Key is not exist'); 97 } else { 98 return widgetKey; 99 } 100 }).bind(this).caught(function () { 101 return this.apiCall('iswidgetauthenticated', '', { 102 widgetkey: widgetKey 103 }).then(function (session) { 104 if (session.is_authenticated) { 105 root.setItem(widgetKey, JSON.stringify(session)); 106 } 107 return session; 108 }); 109 }); 110 }); 111 prototype.getWidgetSession = function (widgetKey) {
112 return this._getWidgetSession(widgetKey).bind(this).then(function (session) { 113 var this$ = this; 114 if (!session['auth-session']) { 115 throw { 116 name: 'InvalidSessionError', 117 message: 'No session ID was supplied by the Auth API' 118 }; 119 } 120 if (!session.is_authenticated) { 121 return this._loginWidget(session['auth-session'], widgetKey).bind(this).then(function (data) { 122 if (data.is_authenticated) { 123 return this$._getWidgetSession(widgetKey); 124 } 125 }); 126 } else { 127 return session; 128 } 129 }); 130 }; 131 prototype._loginWidget = function (authSession, widgetKey) { 132 return this.apiCall('widgetauth', '', { 133 provider: 'ssauth', 134 widgetkey: widgetKey, 135 auth_session: authSession 136 }); 137 }; 138 prototype._getSession = _.memoize(function (returnUrl, appName) { 139 var this$ = this; 140 returnUrl || (returnUrl = (self === top 141 ? window 142 : window.top).location.href); 143 if (returnUrl.match(/profileForm/g)) { 144 returnUrl = window.top.location.origin; 145 } 146 return this.apiCall('isauthenticated', returnUrl, appName 147 ? { 148 appName: appName 149 } 150 : {}).then(function (data) { 151 if (data.Error) { 152 throw new Error(data.Error); 153 } 154 data || (data = {}); 155 this$.session = data; 156 if (typeof root.setItem === 'function') { 157 root.setItem('authKey', this$.session['auth-session']); 158 } 159 return data; 160 }).caught(function (e) { 161 if (e instanceof Error) { 162 throw e; 163 } 164 e = new Error('Authentication Error'); 165 e.name = 'IsAuthenticatedError'; 166 throw e; 167 }); 168 }, function (returnUrl) { 169 return returnUrl || '<empty>'; 170 }); 171 prototype.hasSession = function (location, appName) { 172 return this._getSession(location, appName).then(function (session) { 173 var e; 174 if (session) { 175 return session; 176 } 177 e = new Error('No session ID was supplied by the Auth API'); 178 e.name = 'InvalidSessionError'; 179 throw e; 180 }); 181 }; 182 prototype.setSession = function (session_data) { 183 session_data == null && (session_data = null); 184 if (!session_data) { 185 return false; 186 } 187 this.session = session_data; 188 if (typeof root.setItem === 'function') { 189 root.setItem('authKey', this.session['auth-session']); 190 } 191 return session_data; 192 }; 193 prototype.isLoggedIn = function (location) { 194 return this.hasSession(location).then(function (session) { 195 var e; 196 if (session) { 197 return session; 198 } 199 e = new Error('User not authenticated'); 200 e.name = 'NotAuthenticatedError'; 201 throw e; 202 }); 203 }; 204 prototype.logout = function (uri) { 205 var ref$, ref1$, this$ = this; 206 uri == null && (uri = null); 207 return (((ref$ = root.FS) != null ? (ref1$ = ref$.Auth) != null ? typeof ref1$.isLoggedIn === 'function' ? ref1$.isLoggedIn(window.location.href) : void 8 : void 8 : void 8) || this.isLoggedIn(window.location.href)).then(function (session) { 208 var e, redirectUrl; 209 if (!(root.location && session.logout)) { 210 e = new Error('Cannot logout when not in a browser session'); 211 e.name = 'NotInBrowserError'; 212 throw e; 213 } 214 if (root.localStorage) { 215 root.localStorage.clear(); 216 } 217 if (root.sessionStorage) { 218 root.sessionStorage.clear(); 219 }
220 if (uri) { 221 redirectUrl = "?uri=" + uri; 222 } else { 223 redirectUrl = "?uri=//" + root.location.hostname; 224 } 225 return root.location.href = session.logout + redirectUrl; 226 }).caught(function (error) { 227 if ((error != null ? error.name : void 8) !== 'NotAuthenticatedError') { 228 throw error; 229 } 230 return false; 231 }); 232 }; 233 prototype.getRoles = function () { 234 var ref$, ref1$; 235 return (((ref$ = root.FS) != null ? (ref1$ = ref$.Auth) != null ? typeof ref1$.isLoggedIn === 'function' ? ref1$.isLoggedIn() : void 8 : void 8 : void 8) || this.isLoggedIn()).then(function () { 236 var API, ref$; 237 API = ((ref$ = root.FS) != null ? ref$.API : void 8) || require('./api'); 238 return API.get('GetUserRoles'); 239 }).then(function (roles) { 240 return _.map(roles, function (props) { 241 var keys; 242 keys = _.flatten(_.map(props, _.keys)); 243 return _.object(keys, _.map(keys, function (key, i) { 244 return props[i][key]; 245 })); 246 }); 247 }).caught(function (error) { 248 if ((error != null ? error.name : void 8) !== 'NotAuthenticatedError') { 249 throw error; 250 } 251 return []; 252 }); 253 }; 254 prototype.getProviders = function () { 255 var task; 256 task = Promise.defer(); 257 if (!this.config.streamingEnabled) { 258 $.ajax({ 259 dataType: 'json', 260 url: window.location.protocol + "//" + window.location.host + "/authapi/getproviders", 261 data: { 262 withCredentials: true 263 }, 264 success: function (response) { 265 return task.resolve(response); 266 } 267 }); 268 } else { 269 oboe({ 270 url: window.location.protocol + "//" + window.location.host + "/authapi/getproviders", 271 data: 'json', 272 xhrFields: { 273 withCredentials: true 274 } 275 }).done(_.bind(task.resolve, task)).fail(_.bind(task.reject, task)); 276 } 277 return task.promise; 278 }; 279 prototype.register = function () { 280 return undefined; 281 }; 282 prototype.login = function () { 283 return undefined; 284 }; 285 prototype.changePassword = function (oldPass, newPass) { 286 var params, this$ = this; 287 params = { 288 uri: null, 289 hostname: window.location.hostname, 290 oldpass: oldPass, 291 newpass: newPass, 292 provider: 'ssauth', 293 withCredentials: true 294 }; 295 return this.isLoggedIn().then(function () { 296 return $.ajax({ 297 type: 'POST', 298 dataType: 'json', 299 url: '/authapi/changepass', 300 data: params, 301 async: false, 302 success: function (response) { 303 return response; 304 } 305 }); 306 }).then(function (response) { 307 var task, ref$; 308 task = Promise.defer(); 309 if ((response != null ? response.changepass : void 8) == null) { 310 task.reject('Invalid response from password change API'); 311 } else if (response.changepass.error != null) { 312 task.reject(response.changepass.error); 313 } else if (((ref$ = response.changepass) != null ? ref$.uid : void 8) == null) { 314 task.reject('No UID returned by change pass API'); 315 } else { 316 task.resolve(response.changepass); 317 } 318 return task.promise; 319 }); 320 }; 321 prototype.changeEmail = function (newEmail, currentPass) { 322 var params, this$ = this; 323 params = { 324 newEmail: newEmail, 325 pass: currentPass, 326 provider: FS.Auth.session.auth_name 327 }; 328 return this.isLoggedIn().then(function () { 329 return this$.apiCall('changemail', null, params); 330 }).get('changemail').then(function (it) { 331 var error, msg, that, ref$, router; 332 error = it.error; 333 if (error) { 334 msg = error.match(/already taken/) 335 ? 'The email address you have chosen is already in use by another account' 336 : "Could not change your email: " + error; 337 throw new Error(msg); 338 } 339 if ((that = (ref$ = this$.session) != null ? ref$.user : void 8) != null) { 340 that.email = newEmail; 341 that.name = newEmail; 342 } 343 router = new Router(); 344 router.dropParam('changeEmail'); 345 router.pushParamToUrl([{ 346 param: "changeEmail", 347 value: newEmail 348 }]); 349 return newEmail; 350 }); 351 }; 352 return Auth; 353 }()); 354 return new Auth(); 355 }); 356}).call(this);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.