Created
March 6, 2019 20:19
-
-
Save nicosabena/7359f9932841c86618f314dbdd4f5974 to your computer and use it in GitHub Desktop.
An Auth0 hosted login page with logic to take the user directly to a single upstream connection. Good options for tenants that have only one connection enabled.
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
<!DOCTYPE html> | |
<!-- | |
This hosted login page will go directly to a single upstream identity provider | |
instead of showing Lock. It's a good choice for tenants that have only one | |
connection enabled, or for individual applications with just one connection | |
(in which case, the logic to decide to go directly to the idp needs to | |
be changed, see below). | |
It still keeps Lock if you do `prompt=login`, just in case. | |
--> | |
<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/11.11/lock.min.js"></script> | |
<script src="https://cdn.auth0.com/js/auth0/9.2/auth0.min.js"></script> | |
<script src="https://cdn.auth0.com/js/polyfills/1.0/object-assign.min.js"></script> | |
<script> | |
// Decode utf8 characters properly | |
var config = JSON.parse(decodeURIComponent(escape(window.atob('@@config@@')))); | |
config.extraParams = config.extraParams || {}; | |
var connection = config.connection; | |
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; | |
// We will only show Lock if the authorize request | |
// included 'prompt=login' | |
// This assumes that all applications in the tenant | |
// use a single connection. If only some applications | |
// have one connection enabled, then this logic could | |
// be augmented/changed. E.g. | |
// force Lock for specific client IDs (check config.clientID) | |
const showLock = prompt; | |
if (!showLock) { | |
// shortcut the hosted login page | |
const fixedConnectionName = 'google-oauth2'; | |
var params = Object.assign({ | |
/* additional configuration needed for use of custom domains | |
overrides: { | |
__tenant: config.auth0Tenant, | |
__token_issuer: 'YOUR_CUSTOM_DOMAIN' | |
}, */ | |
domain: config.auth0Domain, | |
clientID: config.clientID, | |
redirectUri: config.callbackURL, | |
responseType: 'code' | |
}, config.internalOptions); | |
var webAuth = new auth0.WebAuth(params); | |
webAuth.authorize({connection: fixedConnectionName}); | |
} else { | |
var lock = new Auth0Lock(config.clientID, config.auth0Domain, { | |
auth: { | |
redirectUrl: config.callbackURL, | |
responseType: (config.internalOptions || {}).response_type || | |
(config.callbackOnLocationHash ? 'token' : 'code'), | |
params: config.internalOptions | |
}, | |
configurationBaseUrl: config.clientConfigurationBaseUrl, | |
overrides: { | |
__tenant: config.auth0Tenant, | |
__token_issuer: 'YOUR_CUSTOM_DOMAIN' | |
}, | |
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' | |
__useTenantInfo: config.isThirdPartyClient | |
}); | |
lock.show(); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment