forked from Github-Mirrors/canaille
feat: button to create a new client token
This commit is contained in:
parent
662f60af86
commit
bab6fc6504
3 changed files with 46 additions and 0 deletions
|
@ -2,6 +2,7 @@ import datetime
|
|||
|
||||
from flask import Blueprint
|
||||
from flask import abort
|
||||
from flask import current_app
|
||||
from flask import flash
|
||||
from flask import redirect
|
||||
from flask import request
|
||||
|
@ -94,6 +95,9 @@ def edit(user, client):
|
|||
if request.form and request.form.get("action") == "delete":
|
||||
return client_delete(client)
|
||||
|
||||
if request.form and request.form.get("action") == "new-token":
|
||||
return client_new_token(client)
|
||||
|
||||
return client_edit(client)
|
||||
|
||||
|
||||
|
@ -154,3 +158,23 @@ def client_delete(client):
|
|||
)
|
||||
Backend.instance.delete(client)
|
||||
return redirect(url_for("oidc.clients.index"))
|
||||
|
||||
|
||||
def client_new_token(client):
|
||||
flash(
|
||||
_(f"A token have been created for the client {client.client_name}"),
|
||||
"success",
|
||||
)
|
||||
now = datetime.datetime.now(datetime.timezone.utc)
|
||||
token = models.Token(
|
||||
token_id=gen_salt(48),
|
||||
type="access_token",
|
||||
access_token=gen_salt(48),
|
||||
issue_date=now,
|
||||
lifetime=current_app.config["CANAILLE_OIDC"]["JWT"]["EXP"],
|
||||
scope=client.scope,
|
||||
client=client,
|
||||
audience=client.audience,
|
||||
)
|
||||
Backend.instance.save(token)
|
||||
return redirect(url_for("oidc.tokens.view", token=token))
|
||||
|
|
|
@ -71,6 +71,9 @@
|
|||
|
||||
<div class="ui right aligned container">
|
||||
<div class="ui stackable buttons">
|
||||
<button type="submit" class="ui right floated button" name="action" value="new-token" id="new-token">
|
||||
{{ _("New token") }}
|
||||
</button>
|
||||
<button type="submit" class="ui right floated negative basic button confirm" name="action" value="confirm-delete" id="confirm-delete" formnovalidate>
|
||||
{{ _("Delete the client") }}
|
||||
</button>
|
||||
|
|
|
@ -289,3 +289,22 @@ def test_client_edit_invalid_uri(testclient, client, logged_admin, trusted_clien
|
|||
"The client has not been edited. Please check your information.",
|
||||
) in res.flashes
|
||||
res.mustcontain("This is not a valid URL")
|
||||
|
||||
|
||||
def test_client_new_token(testclient, logged_admin, backend, client):
|
||||
res = testclient.get("/admin/client/edit/" + client.client_id)
|
||||
res = res.forms["clientaddform"].submit(name="action", value="new-token")
|
||||
assert (
|
||||
"success",
|
||||
"A token have been created for the client Some client",
|
||||
) in res.flashes
|
||||
|
||||
token = backend.get(models.Token)
|
||||
assert token.client == client
|
||||
assert not token.subject
|
||||
assert token.type == "access_token"
|
||||
assert token.scope == client.scope
|
||||
assert token.audience == client.audience
|
||||
|
||||
res = res.follow()
|
||||
assert res.template == "token_view.html"
|
||||
|
|
Loading…
Reference in a new issue