Skip to content

Instantly share code, notes, and snippets.

@twistedstream
Created November 16, 2017 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twistedstream/f10521e44db9f5d455d586f7671f09dd to your computer and use it in GitHub Desktop.
Save twistedstream/f10521e44db9f5d455d586f7671f09dd to your computer and use it in GitHub Desktop.
Auth0 Hosted Login Page that
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Sign In with Auth0</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<!--[if IE 8]>
<script src="//cdnjs.cloudflare.com/ajax/libs/ie8/0.2.5/ie8.js"></script>
<![endif]-->
<!--[if lte IE 9]>
<script src="https://cdn.auth0.com/js/base64.js"></script>
<script src="https://cdn.auth0.com/js/es5-shim.min.js"></script>
<![endif]-->
<script src="https://cdn.auth0.com/js/lock/10.18/lock.min.js"></script>
<script src="https://cdn.auth0.com/js/auth0/8.10/auth0.min.js"></script>
<script src="https://cdn.auth0.com/js/polyfills/1.0/object-assign.min.js"></script>
<script>
var REQUIRED_CONNECTION = 'contoso';
// Decode utf8 characters properly
var config = JSON.parse(decodeURIComponent(escape(window.atob('@@config@@'))));
// helper to get a querystring value
function getParameterByName (name) {
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
return results ? decodeURIComponent(results[1].replace(/\+/g, " ")) : "";
}
var connection = config.connection;
// show login page if a connection was specified in the flow
if (connection) {
config.extraParams = config.extraParams || {};
var prompt = config.prompt;
var languageDictionary;
var language;
if (config.dict && config.dict.signin && config.dict.signin.title) {
languageDictionary = { title: config.dict.signin.title };
} else if (typeof config.dict === 'string') {
language = config.dict;
}
var loginHint = config.extraParams.login_hint;
var lock = new Auth0Lock(config.clientID, config.auth0Domain, {
auth: {
redirectUrl: config.callbackURL,
responseType: (config.internalOptions || {}).response_type ||
config.callbackOnLocationHash ? 'token' : 'code',
params: config.internalOptions
},
assetsUrl: config.assetsUrl,
allowedConnections: connection ? [connection] : null,
rememberLastLogin: !prompt,
language: language,
languageDictionary: languageDictionary,
theme: {
//logo: 'YOUR LOGO HERE',
//primaryColor: 'green'
},
prefill: loginHint ? { email: loginHint, username: loginHint } : null,
closable: false,
// uncomment if you want small buttons for social providers
// socialButtonStyle: 'small'
});
lock.show();
} else {
// no connection, so perform new flow with explicit connection
var params = Object.assign({
domain: config.auth0Domain,
clientID: config.clientID,
redirectUri: config.callbackURL,
responseType: 'code',
protocol: getParameterByName('protocol') || 'oauth2',
state: getParameterByName('state'),
scope: getParameterByName('scope') || 'openid'
}, config.internalOptions);
var webAuth = new auth0.WebAuth(params);
webAuth.authorize({ connection: REQUIRED_CONNECTION }, function(err) {
if (err) {
console.err(err);
window.alert('An error occurred performing autoamtic login.');
}
});
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment