forked from Github-Mirrors/canaille
chore: demo client registration
This commit is contained in:
parent
772a364128
commit
14a93ad104
9 changed files with 39 additions and 11 deletions
|
@ -25,6 +25,24 @@ def setup_routes(app):
|
|||
"index.html", user=session.get("user"), name=app.config["NAME"]
|
||||
)
|
||||
|
||||
@app.route("/register")
|
||||
def register():
|
||||
return oauth.canaille.authorize_redirect(
|
||||
url_for("register_callback", _external=True), prompt="create"
|
||||
)
|
||||
|
||||
@app.route("/register_callback")
|
||||
def register_callback():
|
||||
try:
|
||||
token = oauth.canaille.authorize_access_token()
|
||||
session["user"] = token.get("userinfo")
|
||||
session["id_token"] = token["id_token"]
|
||||
flash("You account has been successfully created.", "success")
|
||||
except AuthlibBaseError as exc:
|
||||
flash(f"An error happened during registration: {exc.description}", "error")
|
||||
|
||||
return redirect(url_for("index"))
|
||||
|
||||
@app.route("/login")
|
||||
def login():
|
||||
return oauth.canaille.authorize_redirect(
|
||||
|
@ -39,7 +57,7 @@ def setup_routes(app):
|
|||
session["id_token"] = token["id_token"]
|
||||
flash("You have been successfully logged in.", "success")
|
||||
except AuthlibBaseError as exc:
|
||||
flash(f"You have not been logged in: {exc.description}", "error")
|
||||
flash(f"An error happened during login: {exc.description}", "error")
|
||||
|
||||
return redirect(url_for("index"))
|
||||
|
||||
|
|
|
@ -118,7 +118,7 @@
|
|||
</a>
|
||||
<a class="ui huge negative button" href="{{ url_for('logout') }}">
|
||||
Log out
|
||||
<i class="right arrow icon"></i>
|
||||
<i class="sign out icon"></i>
|
||||
</a>
|
||||
</div>
|
||||
{% else %}
|
||||
|
@ -126,9 +126,13 @@
|
|||
<a href="{{ config.OAUTH_AUTH_SERVER }}" target="_blank" class="ui huge button">
|
||||
Identity server
|
||||
</a>
|
||||
<a class="ui huge primary button" href="{{ url_for('register') }}">
|
||||
Sign up
|
||||
<i class="handshake icon"></i>
|
||||
</a>
|
||||
<a class="ui huge primary button" href="{{ url_for('login') }}">
|
||||
Sign in
|
||||
<i class="right arrow icon"></i>
|
||||
<i class="sign in icon"></i>
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
|
|
@ -43,7 +43,7 @@ FAVICON = "/static/img/canaille-c.webp"
|
|||
# By default, this is true if SMTP is configured, else this is false.
|
||||
# If explicitely set to true and SMTP is disabled, the email field
|
||||
# will be read-only.
|
||||
# EMAIL_CONFIRMATION =
|
||||
EMAIL_CONFIRMATION = false
|
||||
|
||||
# If ENABLE_REGISTRATION is true, then users can freely create an account
|
||||
# at this instance. If email verification is available, users must confirm
|
||||
|
|
|
@ -43,7 +43,7 @@ FAVICON = "/static/img/canaille-c.webp"
|
|||
# By default, this is true if SMTP is configured, else this is false.
|
||||
# If explicitely set to true and SMTP is disabled, the email field
|
||||
# will be read-only.
|
||||
# EMAIL_CONFIRMATION =
|
||||
EMAIL_CONFIRMATION = false
|
||||
|
||||
# If ENABLE_REGISTRATION is true, then users can freely create an account
|
||||
# at this instance. If email verification is available, users must confirm
|
||||
|
|
|
@ -43,7 +43,7 @@ FAVICON = "/static/img/canaille-c.webp"
|
|||
# By default, this is true if SMTP is configured, else this is false.
|
||||
# If explicitely set to true and SMTP is disabled, the email field
|
||||
# will be read-only.
|
||||
# EMAIL_CONFIRMATION =
|
||||
EMAIL_CONFIRMATION = false
|
||||
|
||||
# If ENABLE_REGISTRATION is true, then users can freely create an account
|
||||
# at this instance. If email verification is available, users must confirm
|
||||
|
|
|
@ -43,7 +43,7 @@ FAVICON = "/static/img/canaille-c.webp"
|
|||
# By default, this is true if SMTP is configured, else this is false.
|
||||
# If explicitely set to true and SMTP is disabled, the email field
|
||||
# will be read-only.
|
||||
# EMAIL_CONFIRMATION =
|
||||
EMAIL_CONFIRMATION = false
|
||||
|
||||
# If ENABLE_REGISTRATION is true, then users can freely create an account
|
||||
# at this instance. If email verification is available, users must confirm
|
||||
|
|
|
@ -43,7 +43,7 @@ FAVICON = "/static/img/canaille-c.webp"
|
|||
# By default, this is true if SMTP is configured, else this is false.
|
||||
# If explicitely set to true and SMTP is disabled, the email field
|
||||
# will be read-only.
|
||||
# EMAIL_CONFIRMATION =
|
||||
EMAIL_CONFIRMATION = false
|
||||
|
||||
# If ENABLE_REGISTRATION is true, then users can freely create an account
|
||||
# at this instance. If email verification is available, users must confirm
|
||||
|
|
|
@ -43,7 +43,7 @@ FAVICON = "/static/img/canaille-c.webp"
|
|||
# By default, this is true if SMTP is configured, else this is false.
|
||||
# If explicitely set to true and SMTP is disabled, the email field
|
||||
# will be read-only.
|
||||
# EMAIL_CONFIRMATION =
|
||||
EMAIL_CONFIRMATION = false
|
||||
|
||||
# If ENABLE_REGISTRATION is true, then users can freely create an account
|
||||
# at this instance. If email verification is available, users must confirm
|
||||
|
|
|
@ -107,7 +107,10 @@ def populate(app):
|
|||
client_name="Client1",
|
||||
contacts=["admin@mydomain.tld"],
|
||||
client_uri="http://localhost:5001",
|
||||
redirect_uris=["http://localhost:5001/login_callback"],
|
||||
redirect_uris=[
|
||||
"http://localhost:5001/login_callback",
|
||||
"http://localhost:5001/register_callback",
|
||||
],
|
||||
post_logout_redirect_uris=["http://localhost:5001/logout_callback"],
|
||||
tos_uri="http://localhost:5001/tos",
|
||||
policy_uri="http://localhost:5001/policy",
|
||||
|
@ -127,7 +130,10 @@ def populate(app):
|
|||
contacts=["admin@mydomain.tld"],
|
||||
client_uri="http://localhost:5002",
|
||||
redirect_uris=["http://localhost:5002/login_callback"],
|
||||
post_logout_redirect_uris=["http://localhost:5002/logout_callback"],
|
||||
post_logout_redirect_uris=[
|
||||
"http://localhost:5002/logout_callback",
|
||||
"http://localhost:5002/register_callback",
|
||||
],
|
||||
tos_uri="http://localhost:5002/tos",
|
||||
policy_uri="http://localhost:5002/policy",
|
||||
grant_types=["authorization_code", "refresh_token"],
|
||||
|
|
Loading…
Reference in a new issue