From be587b815ecbe8e028032bdce08a6541881e52fb Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Mon, 17 Jun 2024 17:46:03 +1000 Subject: [PATCH] feat: Improve ease of adding a new client --- website/routes.py | 41 +++++++-- website/templates/client.html | 131 +++++++++++++++++++++++++++ website/templates/create_client.html | 16 +++- website/templates/home.html | 4 +- 4 files changed, 178 insertions(+), 14 deletions(-) create mode 100644 website/templates/client.html diff --git a/website/routes.py b/website/routes.py index d78bbb9..6c93c2b 100644 --- a/website/routes.py +++ b/website/routes.py @@ -16,6 +16,7 @@ from requests_doh import DNSOverHTTPSSession, add_dns_provider from datetime import timedelta from eth_account.messages import encode_defunct from eth_account import Account +import json @@ -380,7 +381,7 @@ def create_client(): "grant_types": split_by_crlf(form["grant_type"]), "redirect_uris": split_by_crlf(form["redirect_uri"]), "response_types": split_by_crlf(form["response_type"]), - "scope": form["scope"], + "scope": " ".join(form.getlist("scope")), "token_endpoint_auth_method": form["token_endpoint_auth_method"], } client.set_client_metadata(client_metadata) @@ -392,7 +393,27 @@ def create_client(): db.session.add(client) db.session.commit() - return redirect("/") + return redirect("/client/" + client_id) + +@bp.route("/client/") +def client(client_id): + user = current_user() + if not user: + return redirect("/") + + client:OAuth2Client = OAuth2Client.query.filter_by(client_id=client_id).first() + if not client: + return redirect("/") + + if client.user_id != user.id and user.id != 1: + return redirect("/") + + metadata = client.client_metadata + # Convert metadata to json + metadata = json.dumps(metadata, indent=4) + + return render_template("client.html", client=metadata,id=client_id, + secret=client.client_secret) @bp.route("/delete_client") @@ -400,14 +421,18 @@ def delete_client(): user = current_user() if not user: return redirect("/") - if user.id != 1: - return redirect("/") client_id = request.args.get("client_id") - client = OAuth2Client.query.filter_by(client_id=client_id).first() - if client: - db.session.delete(client) - db.session.commit() + client:OAuth2Client = OAuth2Client.query.filter_by(client_id=client_id).first() + + if not client: + return redirect("/") + + if client.user_id != user.id and user.id != 1: + return redirect("/") + + db.session.delete(client) + db.session.commit() return redirect("/") diff --git a/website/templates/client.html b/website/templates/client.html new file mode 100644 index 0000000..cd1bb36 --- /dev/null +++ b/website/templates/client.html @@ -0,0 +1,131 @@ + + + + + + + HNS Login + + + + + + +

HNS Login

+

Client Information

+

Client ID: {{id}}

+

Client Secret: {{secret}}

+ +

URLS

+

Authorization URL: {{url_for('.authorize',_external=True)}}

+

Token URL: {{url_for('.issue_token',_external=True)}}

+

Revoke URL: {{url_for('.revoke_token',_external=True)}}

+

Discovery URL: {{url_for('.autodiscovery',_external=True)}}

+ +
+ Delete Client + +
+ Powered by Varo Auth, HNS.ID and Nathan.Woodburn/ +
+
+ + \ No newline at end of file diff --git a/website/templates/create_client.html b/website/templates/create_client.html index 2a6d4c7..5659c8f 100644 --- a/website/templates/create_client.html +++ b/website/templates/create_client.html @@ -58,7 +58,7 @@

Home

-

Create OAuth Client

+

Create an OAuth Client

diff --git a/website/templates/home.html b/website/templates/home.html index 2646eee..d0a152e 100644 --- a/website/templates/home.html +++ b/website/templates/home.html @@ -117,6 +117,7 @@ Log Out + Create an OAuth client {% for client in clients %}
@@ -188,6 +189,7 @@
       
         
         
+      
     
   
 
@@ -277,7 +279,7 @@
         
         {% endfor %}
       
-      
+