Skip to content

Commit f1d6338

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent a848892 commit f1d6338

5 files changed

Lines changed: 47 additions & 43 deletions

File tree

src/bornhack/settings.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,22 +221,18 @@
221221
"SCOPES": {
222222
# required
223223
"openid": "OpenID Connect scope",
224-
225224
# deprecated api scope, remove after 2025 camp
226225
"profile:read": "Allow the remote site to read your bornhack.dk username (uuid), user id, profile public credit name, profile description, and a list of team memberships using the profile API endpoint (scope profile:read). NOTE: This scope is being deprecated soon! Ask the BornHack website team for more info.",
227-
228226
# standard OIDC claim scopes
229227
"profile": "Allow the remote site to read your profile public_credit_name, description, and update time (scope: profile)",
230228
"email": "Allow the remote site to read your email address (scope: email)",
231229
"address": "Allow the remote site to read your profile location (scope: address)",
232230
"phone": "Allow the remote site to read your profile phonenumber (scope: phone)",
233-
234231
# custom bornhack user claim scopes
235232
"groups:read": "Allow the remote site to read a list of your group memberships (scope: groups:read).",
236233
"location:read": "Allow the remote site to read your profile location (scope: loocation:read)",
237234
"permissions:read": "Allow the remote site to read a list of your assigned permissions (scope: permissions:read).",
238235
"teams:read": "Allow the remote site to read a list of your team memberships and team lead status (scope: teams:read)",
239-
240236
# api scopes
241237
"phonebook:admin": "Allow the remote site to read the camp phonebook, including service numbers and unlisted numbers. Also allow the remote site to use to the POC API. This scope is only relevant for POC team leads (scope: phonebook:admin).",
242238
"phonebook:read": "Allow the remote site to read the camp phonebook (scope: phonebook:read).",

src/profiles/forms.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
from django import forms
22
from bornhack.oauth_validators import BornhackOAuth2Validator
33

4+
45
def get_scopes() -> list[str]:
56
validator = BornhackOAuth2Validator()
6-
return ((scope, scope) for scope in sorted(set(validator.oidc_claim_scope.values())) if scope!="openid")
7+
return (
8+
(scope, scope)
9+
for scope in sorted(set(validator.oidc_claim_scope.values()))
10+
if scope != "openid"
11+
)
12+
713

814
class OIDCForm(forms.Form):
915
scopes = forms.MultipleChoiceField(

src/profiles/templates/oidc.html

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,53 +11,53 @@
1111
<h4>OIDC Claims</h4>
1212
</div>
1313
<div class="card-body">
14-
<p class="lead">When using BornHack as an IDP (logging into other sites using your BornHack account) you can control which <i>user claims</i> are shared with the remote site by asking for one or more of the following <i>claim scopes</i>:</p>
14+
<p class="lead">When using BornHack as an IDP (logging into other sites using your BornHack account) you can control which <i>user claims</i> are shared with the remote site by asking for one or more of the following <i>claim scopes</i>:</p>
1515
<p><ul>
1616
{% for scope in all_scopes %}
17-
<li><code>{{ scope }}</code></li>
17+
<li><code>{{ scope }}</code></li>
1818
{% endfor %}
1919
</ul></p>
2020
<p>Note: In addition to this list the default <code>openid</code> scope is available (it is part of the standard) and must always be included when asking for a jwt.</p>
2121
<p class="lead">This form allows you to see which OIDC user claims are returned for your user with any combination of scopes.</p>
2222
<form method="GET">
23-
{% bootstrap_form form %}
24-
<button class="btn btn-primary" type="submit">Submit</button>
23+
{% bootstrap_form form %}
24+
<button class="btn btn-primary" type="submit">Submit</button>
2525
</form>
2626
<hr>
2727
{% if not active_scopes %}
28-
<p class="lead">Select scopes in the form to see user claims</p>
28+
<p class="lead">Select scopes in the form to see user claims</p>
2929
{% else %}
30-
<p class="lead">The following user claims will be returned in a jwt with these scopes:</p>
31-
<p>
32-
<ul>
33-
{% for scope in active_scopes %}
34-
<li><code>{{ scope }}</code></li>
35-
{% endfor %}
36-
</ul>
37-
</p>
38-
<table class="table table-striped">
39-
<tr>
40-
<th>Claim Name</th>
41-
<th>Required Scope</th>
42-
<th>Claim Value (JSON)</th>
43-
</tr>
44-
<tr>
45-
<td><code>sub</code></td>
46-
<td><code>openid</code></td>
47-
<td>{{ request.user.username }}</td>
48-
</tr>
49-
{% for claim, value in claims.items %}
50-
{% for claimname, scope in scopes.items %}
51-
{% if claimname == claim %}
30+
<p class="lead">The following user claims will be returned in a jwt with these scopes:</p>
31+
<p>
32+
<ul>
33+
{% for scope in active_scopes %}
34+
<li><code>{{ scope }}</code></li>
35+
{% endfor %}
36+
</ul>
37+
</p>
38+
<table class="table table-striped">
5239
<tr>
53-
<td><code>{{ claim }}</code></td>
54-
<td><code>{{ scope }}</code></td>
55-
<td>{{ value }}</td>
40+
<th>Claim Name</th>
41+
<th>Required Scope</th>
42+
<th>Claim Value (JSON)</th>
5643
</tr>
57-
{% endif %}
58-
{% endfor %}
59-
{% endfor %}
60-
</table>
44+
<tr>
45+
<td><code>sub</code></td>
46+
<td><code>openid</code></td>
47+
<td>{{ request.user.username }}</td>
48+
</tr>
49+
{% for claim, value in claims.items %}
50+
{% for claimname, scope in scopes.items %}
51+
{% if claimname == claim %}
52+
<tr>
53+
<td><code>{{ claim }}</code></td>
54+
<td><code>{{ scope }}</code></td>
55+
<td>{{ value }}</td>
56+
</tr>
57+
{% endif %}
58+
{% endfor %}
59+
{% endfor %}
60+
</table>
6161
{% endif %}
6262
</div>
6363
</div>

src/profiles/templates/profile_base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ <h2>Your BornHack Account</h2>
9494
{% url 'profiles:oidc' as profile_oidc_url %}
9595
<li class="nav-item">
9696
<a class="nav-link{% if request.path == profile_oidc_url %} active{% endif %}" href="{{ profile_oidc_url }}">
97-
OIDC Scope<i class="fas fa-arrow-right"></i>Claim
97+
OIDC Scope<i class="fas fa-arrow-right"></i>Claim
9898
</a>
9999
</li>
100100

src/profiles/views.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def get_form(self, form_class=None):
122122
if form_class is None:
123123
form_class = self.get_form_class()
124124
scopes = self.request.GET.getlist(key="scopes")
125-
self.initial['scopes'] = scopes
125+
self.initial["scopes"] = scopes
126126
return form_class(**self.get_form_kwargs())
127127

128128
def get_context_data(self, **kwargs):
@@ -133,7 +133,9 @@ def get_context_data(self, **kwargs):
133133
if scope in self.request.GET.getlist(key="scopes"):
134134
context["claims"][claim] = value
135135
context["scopes"] = self.scopes
136-
context["active_scopes"] = ["openid"] + sorted(set(self.request.GET.getlist(key="scopes")))
136+
context["active_scopes"] = ["openid"] + sorted(
137+
set(self.request.GET.getlist(key="scopes"))
138+
)
137139
context["all_scopes"] = sorted(set(self.scopes.values()))
138-
del(context["all_scopes"][context["all_scopes"].index("openid")])
140+
del context["all_scopes"][context["all_scopes"].index("openid")]
139141
return context

0 commit comments

Comments
 (0)