Auth0.prototype.loginWithPopup = function(options, callback) { var self = this; if (!callback) { throw new Error('popup mode should receive a mandatory callback'); } var query = this._buildAuthorizeQueryString([ this._getMode(options), options, { client_id: this._clientID, owp: true }]); var popupUrl = 'https://' + this._domain + '/authorize?' + query; var popupOptions = xtend( self._computePopupPosition({ width: (options.popupOptions && options.popupOptions.width) || 500, height: (options.popupOptions && options.popupOptions.height) || 600 }), options.popupOptions); var popup = WinChan.open({ url: popupUrl, relay_url: 'https://' + this._domain + '/relay.html', window_features: stringifyPopupSettings(popupOptions) }, function (err, result) { if (err) { // Winchan always returns string errors, we wrap them inside Error objects return callback(new Error(err), null, null, null, null, null); } if (result && result.id_token) { return self.getProfile(result.id_token, function (err, profile) { callback(err, profile, result.id_token, result.access_token, result.state, result.refresh_token); }); } // Case where we've found an error return callback(new Error(result ? result.err : 'Something went wrong'), null, null, null, null, null); }); popup.focus(); };
Auth0.prototype.loginWithUsernamePasswordAndSSO = function(options, callback) { var _this = this; var popupPosition = this._computePopupPosition(options.popupOptions); var popupOptions = xtend(popupPosition, options.popupOptions); var popup = WinChan.open({ url: 'https://' + this._domain + '/sso_dbconnection_popup/' + this._clientID, relay_url: 'https://' + this._domain + '/relay.html', window_features: stringifyPopupSettings(popupOptions), popup: this._current_popup, params: { domain: this._domain, clientID: this._clientID, options: { username: trim(options.username || options.email || ''), password: options.password, connection: options.connection, state: options.state, scope: options.scope } } }, function(err, result) { _this._current_popup = null; if (err) { return callback(new LoginError(err), null, null, null, null, null); } if (!result) { return callback(new LoginError('Something went wrong'), null, null, null, null, null); } if (result.id_token) { return callback(null, _this._prepareResult(result)); } if (result.err) { return callback(new LoginError(result.err.status, result.err.details || result.err), null, null, null, null, null); } if (result.error) { return callback(new LoginError(result.status, result.details || result), null, null, null, null, null); } return callback(new LoginError('Something went wrong'), null, null, null, null, null); }); popup.focus(); };
Auth0.prototype.loginWithPopup = function(options, callback) { var _this = this; if (!callback) { throw new Error('popup mode should receive a mandatory callback'); } var qs = [this._getMode(options), options, { client_id: this._clientID, owp: true }]; if (this._sendClientInfo) { qs.push({auth0Client: this._getClientInfoString()}); } var query = this._buildAuthorizeQueryString(qs); var popupUrl = joinUrl('https:', this._domain, '/authorize?' + query); var popupPosition = this._computePopupPosition(options.popupOptions); var popupOptions = xtend(popupPosition, options.popupOptions); var popup = WinChan.open({ url: popupUrl, relay_url: 'https://' + this._domain + '/relay.html', window_features: stringifyPopupSettings(popupOptions) }, function(err, result) { _this._current_popup = null; if (err) { return callback(new LoginError(err), null, null, null, null, null); } if (!result) { return callback(new LoginError('Something went wrong'), null, null, null, null, null); } if (result.id_token) { return callback(null, _this._prepareResult(result)); } if (result.err) { return callback(new LoginError(result.err.status, result.err.details || result.err), null, null, null, null, null); } if (result.error) { return callback(new LoginError(result.status, result.details || result), null, null, null, null, null); } return callback(new LoginError('Something went wrong'), null, null, null, null, null); }); popup.focus(); };
PopupHandler.prototype.load = function (url, relayUrl, options, cb) { var _this = this; var popupPosition = this.calculatePosition(options.popupOptions || {}); var popupOptions = objectHelper.merge(popupPosition).with(options.popupOptions); var winchanOptions = { url: url, relay_url: relayUrl, window_features: this.stringifyPopupSettings(popupOptions), popup: this._current_popup, params: options }; var popup = WinChan.open(winchanOptions, function (err, data) { _this._current_popup = null; return cb(err, data); }); popup.focus(); return popup; };
PopupHandler.prototype.load = function (url, relayUrl, options, cb) { var _this = this; var popupPosition = this.calculatePosition(options.popupOptions || {}); var popupOptions = objectHelper.merge(popupPosition).with(options.popupOptions); var winchanOptions = objectHelper.merge({ url: url, relay_url: relayUrl, window_features: qs.stringify(popupOptions, { delimiter: ',', encode: false }), popup: this._current_popup }).with(options); var popup = WinChan.open(winchanOptions, function (err, data) { _this._current_popup = null; return cb(err, data); }); popup.focus(); return popup; };