Skip to content

Instantly share code, notes, and snippets.

@aolney
Created February 18, 2021 18:08
Show Gist options
  • Save aolney/51bcd35bc1455d8e2481f10c30e8e81b to your computer and use it in GitHub Desktop.
Save aolney/51bcd35bc1455d8e2481f10c30e8e81b to your computer and use it in GitHub Desktop.
Autologin for JupyterHub by query string
{% extends "page.html" %}
{% if announcement_login %}
{% set announcement = announcement_login %}
{% endif %}
{% block login_widget %}
{% endblock %}
{% block main %}
{% block login %}
<div id="login-main" class="container">
{% if custom_html %}
{{ custom_html | safe }}
{% elif login_service %}
<div class="service-login">
<a role="button" class='btn btn-jupyter btn-lg' href='{{authenticator_login_url}}'>
Sign in with {{login_service}}
</a>
</div>
{% else %}
<form action="{{login_url}}?next={{next}}" method="post" role="form">
<div class="auth-form-header">
Sign in
</div>
<div class='auth-form-body'>
<p id='insecure-login-warning' class='hidden'>
Warning: JupyterHub seems to be served over an unsecured HTTP connection.
We strongly recommend enabling HTTPS for JupyterHub.
</p>
{% if login_error %}
<p class="login_error">
{{login_error}}
</p>
{% endif %}
<label for="username_input">Username:</label>
<input
id="username_input"
type="text"
autocapitalize="off"
autocorrect="off"
class="form-control"
name="username"
val="{{username}}"
tabindex="1"
autofocus="autofocus"
/>
<label for='password_input'>Password:</label>
<input
type="password"
class="form-control"
name="password"
id="password_input"
tabindex="2"
/>
<input
type="submit"
id="login_submit"
class='btn btn-jupyter'
value='Sign In'
tabindex="3"
/>
</div>
</form>
{% endif %}
</div>
{% endblock login %}
{% endblock %}
{% block script %}
{{ super() }}
<script>
if (window.location.protocol === "http:") {
// unhide http warning
var warning = document.getElementById('insecure-login-warning');
warning.className = warning.className.replace(/\bhidden\b/, '');
}
function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
var get = getUrlVars();
if( get['password'] !== undefined ) {
document.getElementById('password_input').value = get['password'];
}
if( get['username'] !== undefined ) {
document.getElementById('username_input').value = get['username'];
}
</script>
{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment