Skip to content
Snippets Groups Projects
Commit 9268b8e8 authored by Varac's avatar Varac
Browse files

Merge branch '29-only-login-once-for-all-applications' into 'master'

Resolve "Only login once for all applications"

Closes #29

See merge request openappstack/single-sign-on!12
parents 57d765a4 4dfd16ef
No related branches found
No related tags found
2 merge requests!13Apply new changes to 0.2 release branch,!12Resolve "Only login once for all applications"
Pipeline #2442 failed with stages
in 34 seconds
...@@ -63,7 +63,11 @@ def login(): ...@@ -63,7 +63,11 @@ def login():
"Login denied", "Login denied",
error_description="Login request was denied due to an internal server error")) error_description="Login request was denied due to an internal server error"))
if user.authenticate(login_form.password.data): if user.authenticate(login_form.password.data):
redirect_to = login_request.accept(user.username) redirect_to = login_request.accept(
user.username,
remember=login_form.remember.data,
# Remember session for 12h
remember_for=60*60*12)
app.logger.info("{0} logged in successfully".format(user.username)) app.logger.info("{0} logged in successfully".format(user.username))
else: else:
redirect_to = login_request.reject( redirect_to = login_request.reject(
...@@ -76,14 +80,14 @@ def login(): ...@@ -76,14 +80,14 @@ def login():
# the user. we don't need to check anything and we can accept the request right away. # the user. we don't need to check anything and we can accept the request right away.
elif login_request.skip: elif login_request.skip:
app.logger.info("{0} is already logged in. Skip authentication".format(login_request.subject)) app.logger.info("{0} is already logged in. Skip authentication".format(login_request.subject))
return redirect(login_request(challenge).accept(login_request.subject)) return redirect(login_request.accept(login_request.subject))
# If Skip is not true and the user has not submitted any data via a form, we need # If Skip is not true and the user has not submitted any data via a form, we need
# to display a login form for the user to type in their username and password. # to display a login form for the user to type in their username and password.
# as a reference we save the challenge id in a hidden field of the form. # as a reference we save the challenge id in a hidden field of the form.
else: else:
login_form.challenge.data = challenge login_form.challenge.data = challenge
return render_template('login.html', login_form=login_form) return render_template('login.html', login_form=login_form, logo=login_request.client.logo_uri, application_name=login_request.client.client_name)
if __name__ == '__main__': if __name__ == '__main__':
app.run() app.run()
from wtforms import SubmitField, StringField, PasswordField, HiddenField, validators from wtforms import SubmitField, StringField, PasswordField, BooleanField, HiddenField, validators
from flask_wtf import FlaskForm from flask_wtf import FlaskForm
class LoginForm(FlaskForm): class LoginForm(FlaskForm):
username = StringField("username", validators=[validators.input_required()]) username = StringField("Username", validators=[validators.input_required()],)
password = PasswordField("password", validators=[validators.input_required()]) password = PasswordField("Password", validators=[validators.input_required()])
challenge = HiddenField("challenge") challenge = HiddenField("challenge")
remember = BooleanField("Remember me")
submit = SubmitField("Sign in") submit = SubmitField("Sign in")
<!doctype html> <!doctype html>
<title>OAS authentication service</title> <title>OAS authentication service</title>
<h1>Login</h1> <div style='margin: 0 auto ; width: 350px; padding:20px; border-style:solid; border-color:#6c757d; border-width: 1px; background-color: #f8f9fa; font-family: "Segoe UI", Roboto; font-family: "Helvetica Neue", Arial; font-family: "Noto Sans", sans-serif;'>
<form method="POST" action="/login"> {% if logo %}
<div style="position:relative; width: 350px; height:100px">
<img style="overflow: auto; top: 0; left: 0; bottom: 0; right: 0; position: absolute; margin: auto;max-width: 300px; max-height: 100px" src="{{logo}}" alt="Logo of application"></img>
</div>
{% endif %}
<h1>Log in to {{ application_name }}</h1>
<form method="POST" action="/login">
{{ login_form.csrf_token }} {{ login_form.csrf_token }}
{{ login_form.challenge }} {{ login_form.challenge }}
{{ login_form.username }} {{ login_form.username(placeholder="Username") }}<br>
{{ login_form.password }} <div style="margin-top:5px">{{ login_form.password(placeholder="Password") }}</div> <br>
{{ login_form.submit }} {{ login_form.remember }}{{ login_form.remember.label }} <br>
</form> <div style="margin-top:5px">{{ login_form.submit }}</div>
</form>
</div>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment