Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make client editable #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions website/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,37 @@ def create_client():
return redirect('/')


@bp.route('/edit_client/<client_id>', methods=('GET', 'POST'))
def edit_client(client_id=None):
user = current_user()
if not user:
return redirect('/')
client = OAuth2Client.query.filter_by(client_id=client_id).first()

if request.method == 'GET':
return render_template('edit_client.html', client_id=client_id, client=client)


form = request.form
client_metadata = {
"client_name": form["client_name"],
"client_uri": form["client_uri"],
"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"],
"token_endpoint_auth_method": form["token_endpoint_auth_method"]
}
client.set_client_metadata(client_metadata)

if form['token_endpoint_auth_method'] == 'none':
client.client_secret = ''
elif client.client_secret == '':
client.client_secret = gen_salt(48)
db.session.commit()
return redirect('/')


@bp.route('/oauth/authorize', methods=['GET', 'POST'])
def authorize():
user = current_user()
Expand Down
52 changes: 52 additions & 0 deletions website/templates/edit_client.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<style>
label, label > span { display: block; }
label { margin: 15px 0; }
</style>

<a href="/">Home</a>
<h2>Edit Client</h2>
<form action="" method="post">
<label>
<span>Client Id</span>
<span>{{client.client_info['client_id']}}</span>
</label>
<label>
<span>Client Secret</span>
<span>{{client.client_info['client_secret']}}</span>
</label>
<label>
<span>Client Name</span>
<input type="text" name="client_name" value="{{client.client_metadata['client_name']}}">
</label>
<label>
<span>Client URI</span>
<input type="url" name="client_uri" value="{{client.client_metadata['client_uri']}}">
</label>
<label>
<span>Allowed Scope</span>
<input type="text" name="scope" value="{{client.client_metadata['scope']}}">
</label>
<label>
<span>Redirect URIs</span>
<textarea name="redirect_uri" cols="80" rows="10">{% for line in client.client_metadata['redirect_uris'] %}{{line}}{{"\n"}}{%endfor%}</textarea>
</label>
<label>
<span>Allowed Grant Types</span>
<textarea name="grant_type" cols="80" rows="10">{% for line in client.client_metadata['grant_types'] %}{{line}}{{"\n"}}{%endfor%}</textarea>
</label>
<label>
<span>Allowed Response Types</span>
<textarea name="response_type" cols="30" rows="10">{% for line in client.client_metadata['response_types'] %}{{line}}{{"\n"}}{%endfor%}</textarea>
</label>
<label>
<span>Token Endpoint Auth Method</span>
{% set method = client.client_metadata['token_endpoint_auth_method'] %}
<select name="token_endpoint_auth_method">
{% for o in ['client_secret_basic', 'client_secret_post', 'none'] %}
<option value="{{o}}" {% if (o == method) %} selected="selected" {% endif %} >{{o}}</option>
{%endfor%}
</select>
</label>
<button>Submit</button>
</form>

5 changes: 3 additions & 2 deletions website/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

{% for client in clients %}
<pre>
{{ client.client_info|tojson }}
{{ client.client_metadata|tojson }}
{{ client.client_info|tojson(indent=4) }}
{{ client.client_metadata|tojson(indent=4) }}
</pre>
<a href="/edit_client/{{client.client_info['client_id']}}">[edit]</a>
<hr>
{% endfor %}

Expand Down