auth/web/authorize.qtpl

192 lines
5.0 KiB
Plaintext
Raw Permalink Normal View History

{% import (
"source.toby3d.me/toby3d/auth/internal/domain"
) %}
2022-01-20 19:50:15 +00:00
{% code type AuthorizePage struct {
BaseOf
2022-01-31 16:15:38 +00:00
Scope domain.Scopes
CodeChallengeMethod domain.CodeChallengeMethod
ResponseType domain.ResponseType
Client *domain.Client
2022-01-20 19:50:15 +00:00
Me *domain.Me
2022-01-31 16:15:38 +00:00
RedirectURI *domain.URL
Providers []*domain.Provider
CSRF []byte
CodeChallenge string
State string
} %}
2023-08-06 00:42:38 +00:00
{% func (p *AuthorizePage) title() %}
2023-08-07 03:10:00 +00:00
{% if p.Client.Name != "" %}
{%= p.t("Authorize %s", p.Client.Name) %}
{% else %}
2023-08-06 00:42:38 +00:00
{%= p.t("Authorize application") %}
{% endif %}
2022-01-20 19:50:15 +00:00
{% endfunc %}
2023-08-06 00:42:38 +00:00
{% func (p *AuthorizePage) body() %}
<header>
2023-08-07 03:10:00 +00:00
{% if p.Client.Logo != nil %}
<img class=""
crossorigin="anonymous"
decoding="async"
height="140"
importance="high"
loading="lazy"
referrerpolicy="no-referrer-when-downgrade"
2023-08-07 03:10:00 +00:00
src="{%s p.Client.Logo.String() %}"
alt="{%s p.Client.Name %}"
width="140">
{% endif %}
<h2>
2023-08-07 03:10:00 +00:00
{% if p.Client.URL != nil %}
<a href="{%s p.Client.URL.String() %}">
2022-01-20 19:50:15 +00:00
{% endif %}
2023-08-07 03:10:00 +00:00
{% if p.Client.Name != "" %}
{%s p.Client.Name %}
2022-01-20 19:50:15 +00:00
{% else %}
{%s p.Client.ID.String() %}
2022-01-20 19:50:15 +00:00
{% endif %}
2023-08-07 03:10:00 +00:00
{% if p.Client.URL != nil %}
</a>
{% endif %}
</h2>
</header>
<main>
<aside>
{% if p.CodeChallengeMethod != domain.CodeChallengeMethodUnd && p.CodeChallenge != "" %}
<p class="with-icon">
<span class="icon"
role="img"
aria-label="closed lock with key">🔐</span>
2023-08-06 00:42:38 +00:00
{%= p.t(`This client uses %sPKCE%s with the %s%s%s method.`, `<abbr title="Proof of Key Code Exchange">`,
`</abbr>`, `<code>`, p.CodeChallengeMethod, `</code>`) %}
</p>
{% else %}
<details>
<summary class="with-icon">
<span class="icon"
role="img"
aria-label="unlock">🔓</span>
2023-08-06 00:42:38 +00:00
{%= p.t(`This client does not use %sPKCE%s!`, `<abbr title="Proof of Key Code Exchange">`, `</abbr>`) %}
</summary>
<p>
2023-08-06 00:42:38 +00:00
{%= p.t(`%sProof of Key Code Exchange%s is a mechanism that protects against attackers in the middle hijacking `+
`your application's authentication process. You can still authorize this application without this protection, `+
`but you must independently verify the security of this connection. If you have any doubts - stop the process `+
` and contact the developers.`, `<dfn id="PKCE">`, `</dfn>`) %}
</p>
</details>
{% endif %}
</aside>
<form class=""
accept-charset="utf-8"
action="/authorize/verify"
autocomplete="off"
enctype="application/x-www-form-urlencoded"
method="post"
novalidate="true"
target="_self">
{% if p.CSRF != nil %}
<input type="hidden"
name="_csrf"
value="{%z p.CSRF %}">
{% endif %}
2022-01-20 19:50:15 +00:00
{% for key, val := range map[string]string{
2023-01-16 10:19:22 +00:00
"client_id": p.Client.ID.String(),
"redirect_uri": p.RedirectURI.String(),
"response_type": p.ResponseType.String(),
"state": p.State,
} %}
<input type="hidden"
name="{%s key %}"
value="{%s val %}">
{% endfor %}
{% if len(p.Scope) > 0 %}
<fieldset>
2023-08-06 00:42:38 +00:00
<legend>{%= p.t("Scopes") %}</legend>
{% for _, scope := range p.Scope %}
<div>
<label>
<input type="checkbox"
name="scope[]"
value="{%s scope.String() %}"
checked>
{%s scope.String() %}
</label>
</div>
2022-01-20 19:50:15 +00:00
{% endfor %}
</fieldset>
{% else %}
<aside>
2023-08-06 00:42:38 +00:00
<p>{%= p.t(`No scopes is requested: the application will only get your profile URL.`) %}</p>
</aside>
{% endif %}
2022-01-20 19:50:15 +00:00
{% if p.CodeChallenge != "" %}
2023-01-16 10:19:22 +00:00
{% for key, val := range map[string]string{
"code_challenge": p.CodeChallenge,
"code_challenge_method": p.CodeChallengeMethod.String(),
} %}
<input type="hidden"
2023-01-16 10:19:22 +00:00
name="{%s key %}"
value="{%s val %}">
{% endfor %}
{% endif %}
2022-01-20 19:50:15 +00:00
{% if p.Me != nil %}
<input type="hidden"
name="me"
value="{%s p.Me.String() %}">
{% endif %}
2022-01-20 19:50:15 +00:00
{% if len(p.Providers) > 0 %}
<select name="provider"
autocomplete
required>
2022-01-31 16:15:38 +00:00
{% for _, provider := range p.Providers %}
<option value="{%s provider.UID %}"
2022-01-31 16:15:38 +00:00
{% if provider.UID == "mastodon" %}selected{% endif %}>
{%s provider.Name %}
</option>
{% endfor %}
</select>
{% else %}
<input type="hidden"
name="provider"
value="direct">
{% endif %}
2022-01-31 16:15:38 +00:00
<button type="submit"
name="authorize"
value="deny">
2022-01-20 19:50:15 +00:00
2023-08-06 00:42:38 +00:00
{%= p.t("Deny") %}
</button>
2022-01-20 19:50:15 +00:00
<button type="submit"
name="authorize"
value="allow">
2022-01-20 19:50:15 +00:00
2023-08-06 00:42:38 +00:00
{%= p.t("Allow") %}
</button>
<aside>
2023-08-06 00:42:38 +00:00
<p>{%= p.t(`You will be redirected to %s%s%s`, `<code>`, p.RedirectURI, `</code>`) %}</p>
</aside>
</form>
</main>
{% endfunc %}