Iceshrimp.NET/Iceshrimp.Backend/Pages/OAuth/Authorize.cshtml

80 lines
No EOL
2.9 KiB
Text

@page "/oauth/authorize"
@using Microsoft.AspNetCore.Mvc.TagHelpers
@using Microsoft.AspNetCore.WebUtilities
@model AuthorizeModel
<h3>Iceshrimp.NET OAuth</h3>
@if (Model.Token == null)
{
<div>
The app <span class="app_name">@Model.App.Name</span> requests the following permissions:
<ul>
@foreach (var scope in Model.Scopes)
{
<li>@scope</li>
}
</ul>
<form method="post">
<div class="margin-bottom-5px">
Feature flags:
</div>
<div>
<input type="checkbox" name="supportsHtmlFormatting" id="supportsHtmlFormatting" value="1"/>
<label for="supportsHtmlFormatting">This app supports HTML formatting</label>
</div>
<div>
<input type="checkbox" name="autoDetectQuotes" id="autoDetectQuotes" value="1"/>
<label for="autoDetectQuotes">Automatically detect quotes</label>
</div>
<div>
<input type="checkbox" name="isPleroma" id="isPleroma" value="1"/>
<label for="isPleroma">This app is intended for Pleroma or Akkoma</label>
</div>
@if (Model.AuthenticatedUsers.Count > 0)
{
<div class="margin-top-5px">
@foreach (var user in Model.AuthenticatedUsers)
{
<button type="submit" name="userId" value="@user.Id">Log in as @@@user.Username</button>
}
</div>
<div class="margin-bottom-5px margin-top-5px">
Alternatively, sign in with to a different account below:
</div>
<input type="text" placeholder="Username" name="username"/>
<input type="password" placeholder="Password" name="password"/>
}
else
{
<div class="margin-bottom-5px margin-top-10px">
Log in below to confirm this:
</div>
<input type="text" placeholder="Username" name="username" required/>
<input type="password" placeholder="Password" name="password" required/>
}
<button type="submit">Submit</button>
</form>
</div>
}
else if (Model.Token.RedirectUri == "urn:ietf:wg:oauth:2.0:oob")
{
<div>
Your code is: <pre>@Model.Token.Code</pre>
</div>
}
else
{
var uri = new Uri(Model.Token.RedirectUri);
var query = QueryHelpers.ParseQuery(uri.Query);
query.Add("code", Model.Token.Code);
if (Request.Query.ContainsKey("state"))
query.Add("state", Request.Query["state"]);
uri = new Uri(QueryHelpers.AddQueryString(Model.Token.RedirectUri, query));
Response.Redirect(uri.ToString());
<div>
Click <a href="@uri.ToString()">here</a> to be redirected back to your application
</div>
}