-
Notifications
You must be signed in to change notification settings - Fork 493
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #245 from auth0/v8-popup
V8 Popup mode
- Loading branch information
Showing
12 changed files
with
1,042 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,6 +110,13 @@ <h2>Login with database connection:</h2> | |
<input type="button" class="login-db" value="login" /> | ||
</div> | ||
|
||
<div> | ||
<h2>Login with database connection (popup):</h2> | ||
<input class="popup-login-username" value="[email protected]" /> | ||
<input type="password" class="popup-login-password" value="1234" /> | ||
<input type="button" class="popup-login-db" value="login" /> | ||
</div> | ||
|
||
<div> | ||
<h2>Login with database connection (client login):</h2> | ||
<input class="client-login-username" value="[email protected]" /> | ||
|
@@ -118,12 +125,21 @@ <h2>Login with database connection (client login):</h2> | |
</div> | ||
|
||
<div> | ||
<h2>Login with social connections:</h2> | ||
<h2>Login with /authorize:</h2> | ||
<input type="button" class="login-hosted" value="Hosted login page" /> | ||
<input type="button" class="login-facebook" value="Facebook" /> | ||
<input type="button" class="login-twitter" value="Twitter" /> | ||
<input type="button" class="login-github" value="Github" /> | ||
</div> | ||
|
||
<div> | ||
<h2>Login with /authorize (popup):</h2> | ||
<input type="button" class="popup-login-hosted" value="Hosted login page" /> | ||
<input type="button" class="popup-login-facebook" value="Facebook" /> | ||
<input type="button" class="popup-login-twitter" value="Twitter" /> | ||
<input type="button" class="popup-login-github" value="Github" /> | ||
</div> | ||
|
||
<div> | ||
<h2>Renew authentication:</h2> | ||
<input type="button" class="renew-auth" value="Renew" /> | ||
|
@@ -151,13 +167,14 @@ <h2>Console:</h2> | |
domain: 'auth0-tests-auth0js.auth0.com', | ||
redirectUri: 'http://localhost:3000/example', | ||
clientID: '3GGMIEuBPZ28lb6NBDNARaEZisqFakAs', | ||
responseType: 'id_token' | ||
responseType: 'token' | ||
}); | ||
|
||
var hash = webAuth.parseHash(); | ||
if (hash) { | ||
htmlConsole.dumpCallback(hash.error ? hash : null, hash.error ? null : hash); | ||
window.location.hash = ''; | ||
webAuth.client.userInfo(hash.accessToken, htmlConsole.dumpCallback.bind(htmlConsole)); | ||
} | ||
|
||
$('#clear-console').click(function () { | ||
|
@@ -182,6 +199,16 @@ <h2>Console:</h2> | |
}, htmlConsole.dumpCallback.bind(htmlConsole)); | ||
}); | ||
|
||
$('.popup-login-db').click(function (e) { | ||
e.preventDefault(); | ||
webAuth.popup.login({ | ||
connection: 'tests', | ||
username: $('.popup-login-username').val(), | ||
password: $('.popup-login-password').val(), | ||
scope: 'openid' | ||
}, htmlConsole.dumpCallback.bind(htmlConsole)); | ||
}); | ||
|
||
$('.client-login-db').click(function (e) { | ||
e.preventDefault(); | ||
webAuth.client.login({ | ||
|
@@ -197,6 +224,11 @@ <h2>Console:</h2> | |
webAuth.login({ connection: 'facebook' }); | ||
}); | ||
|
||
$('.login-hosted').click(function (e) { | ||
e.preventDefault(); | ||
webAuth.login({ }); | ||
}); | ||
|
||
$('.login-twitter').click(function (e) { | ||
e.preventDefault(); | ||
webAuth.login({ connection: 'twitter' }); | ||
|
@@ -207,6 +239,26 @@ <h2>Console:</h2> | |
webAuth.login({ connection: 'github' }); | ||
}); | ||
|
||
$('.popup-login-facebook').click(function (e) { | ||
e.preventDefault(); | ||
webAuth.popup.authorize({ connection: 'facebook' }, htmlConsole.dumpCallback.bind(htmlConsole)); | ||
}); | ||
|
||
$('.popup-login-hosted').click(function (e) { | ||
e.preventDefault(); | ||
webAuth.popup.authorize({ }, htmlConsole.dumpCallback.bind(htmlConsole)); | ||
}); | ||
|
||
$('.popup-login-twitter').click(function (e) { | ||
e.preventDefault(); | ||
webAuth.popup.authorize({ connection: 'twitter' }, htmlConsole.dumpCallback.bind(htmlConsole)); | ||
}); | ||
|
||
$('.popup-login-github').click(function (e) { | ||
e.preventDefault(); | ||
webAuth.popup.authorize({ connection: 'github' }, htmlConsole.dumpCallback.bind(htmlConsole)); | ||
}); | ||
|
||
$('.logout').click(function (e) { | ||
e.preventDefault(); | ||
webAuth.logout({ returnTo: 'http://localhost:3000/example' }); | ||
|
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
var WinChan = require('winchan'); | ||
|
||
var windowHandler = require('../helper/window'); | ||
var objectHelper = require('../helper/object'); | ||
|
||
function PopupHandler() { | ||
this._current_popup = null; | ||
} | ||
|
||
PopupHandler.prototype.stringifyPopupSettings = function (options) { | ||
var settings = ''; | ||
|
||
for (var key in options) { | ||
settings += key + '=' + options[key] + ','; | ||
} | ||
|
||
return settings.slice(0, -1); | ||
}; | ||
|
||
PopupHandler.prototype.calculatePosition = function (options) { | ||
var width = options.width || 500; | ||
var height = options.height || 600; | ||
var _window = windowHandler.getWindow(); | ||
|
||
var screenX = typeof _window.screenX !== 'undefined' ? _window.screenX : _window.screenLeft; | ||
var screenY = typeof _window.screenY !== 'undefined' ? _window.screenY : _window.screenTop; | ||
|
||
var outerWidth = typeof _window.outerWidth !== 'undefined' | ||
? _window.outerWidth | ||
: _window.document.body.clientWidth; | ||
|
||
var outerHeight = typeof _window.outerHeight !== 'undefined' | ||
? _window.outerHeight | ||
: _window.document.body.clientHeight; | ||
|
||
var left = screenX + ((outerWidth - width) / 2); | ||
var top = screenY + ((outerHeight - height) / 2); | ||
|
||
return { width: width, height: height, left: left, top: top }; | ||
}; | ||
|
||
PopupHandler.prototype.load = function (url, relayUrl, options, cb) { | ||
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; | ||
}; | ||
|
||
module.exports = PopupHandler; |
This file contains 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
This file contains 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
Oops, something went wrong.