Skip to content

Commit 1f89e9d

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

4 files changed

Lines changed: 45 additions & 39 deletions

File tree

src/profiles/forms.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
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 ((claim, claim) for claim in sorted(set(validator.oidc_claim_scope.values())))
7+
return (
8+
(claim, claim) for claim in sorted(set(validator.oidc_claim_scope.values()))
9+
)
10+
711

812
class OIDCForm(forms.Form):
913
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 user claims are returned by asking for one or more of the following claim scopes:</p>
14+
<p class="lead">When using BornHack as an IDP (logging into other sites using your BornHack account) you can control which user claims are returned by asking for one or more of the following claim scopes:</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
@@ -130,7 +130,7 @@ def get(self, request, *args, **kwargs):
130130
else:
131131
return HttpResponseForbidden()
132132

133-
133+
134134
class ProfileOIDCView(LoginRequiredMixin, FormView):
135135
template_name = "oidc.html"
136136
form_class = OIDCForm
@@ -144,7 +144,7 @@ def setup(self, *args, **kwargs):
144144
def get_form(self, form_class=None):
145145
if form_class is None:
146146
form_class = self.get_form_class()
147-
self.initial['scopes'] = self.request.GET.getlist(key="scopes")
147+
self.initial["scopes"] = self.request.GET.getlist(key="scopes")
148148
return form_class(**self.get_form_kwargs())
149149

150150
def get_context_data(self, **kwargs):
@@ -155,6 +155,8 @@ def get_context_data(self, **kwargs):
155155
if scope in self.request.GET.getlist(key="scopes"):
156156
context["claims"][claim] = value
157157
context["scopes"] = self.scopes
158-
context["active_scopes"] = ["openid"] + sorted(list(set(self.request.GET.getlist(key="scopes"))))
158+
context["active_scopes"] = ["openid"] + sorted(
159+
list(set(self.request.GET.getlist(key="scopes")))
160+
)
159161
context["all_scopes"] = sorted(list(set(self.scopes.values())))
160162
return context

0 commit comments

Comments
 (0)