Skip to content

Commit

Permalink
add edit oauth2 client page
Browse files Browse the repository at this point in the history
  • Loading branch information
josxha committed Oct 18, 2023
1 parent 017cb29 commit 0dacdc5
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 6 deletions.
52 changes: 52 additions & 0 deletions OryAdmin/Components/Pages/OAuth2/Clients/Edit.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@page "/oauth2/clients/{ClientId}/edit"
@using Ory.Hydra.Client.Model
@attribute [StreamRendering]
@attribute [RenderModeInteractiveServer]
@inject ICustomTranslator Translator
@inject ILogger<Home> Logger
@inject NavigationManager Navigation

<PageTitle>Edit Client</PageTitle>

<h1 class="title">Edit Client</h1>
@if (_isLoading)
{
// is loading
<p>Loading data...</p>
}
else
{
<form @onsubmit="SubmitForm">
<div class="field">
<label class="label">
Client Name
<div class="control">
<input type="text" class="input" value="@_client?.ClientName"
@onchange="args => AddPatch(new HydraJsonPatch())"/>
</div>
</label>
</div>
<div class="field">
<label class="label">
Client Secret
<div class="control">
<input type="text" class="input" value="@_client?.ClientSecret"
@onchange="args => AddPatch(new HydraJsonPatch())"/>
</div>
</label>
</div>
<div class="message is-warning p-2 @(string.IsNullOrWhiteSpace(_errorMessage) ? "is-hidden" : "")">
@_errorMessage
</div>
<div class="mt-5">
<div class="buttons">
<a class="button" href="oauth2/clients/@ClientId">
Cancel
</a>
<button type="submit" class="button is-success">
Save
</button>
</div>
</div>
</form>
}
46 changes: 46 additions & 0 deletions OryAdmin/Components/Pages/OAuth2/Clients/Edit.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Microsoft.AspNetCore.Components;
using Ory.Hydra.Client.Model;
using Ory.Kratos.Client.Client;
using OryAdmin.Services;

namespace OryAdmin.Components.Pages.OAuth2.Clients;

public partial class Edit
{
private HydraOAuth2Client? _client;
private string? _errorMessage;
private bool _isLoading = true;

[Parameter]
public required string ClientId { get; set; }

private readonly List<HydraJsonPatch> _patches = new();

[Inject] private ApiService ApiService { get; set; } = default!;

protected override async Task OnInitializedAsync()
{
_client = await ApiService.HydraOAuth2.GetOAuth2ClientAsync(ClientId);
_isLoading = false;
}

private async Task SubmitForm()
{
try
{
_ = await ApiService.HydraOAuth2.PatchOAuth2ClientAsync(ClientId, _patches);
}
catch (ApiException exception)
{
_errorMessage = exception.Message;
return;
}

Navigation.NavigateTo("oauth2/clients");
}

private void AddPatch(HydraJsonPatch patch)
{
_patches.Add(patch);
}
}
12 changes: 6 additions & 6 deletions OryAdmin/Components/Pages/OAuth2/Clients/View.razor
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ else
<td>@(_client!.ClientId)</td>
</tr>
<tr>
<td>Name</td>
<td>Client Name</td>
<td>@(string.IsNullOrWhiteSpace(_client.ClientName) ? "-" : _client.ClientName)</td>
</tr>
<tr>
<td>Secret</td>
<td>Client Secret</td>
<td>@(string.IsNullOrWhiteSpace(_client.ClientSecret) ? "-" : _client.ClientSecret)</td>
</tr>
<tr>
<td>Client Secret Expires At</td>
<td>@(_client.ClientSecretExpiresAt == 0 ? "never" : _client.ClientSecretExpiresAt)</td>
</tr>
<tr>
<td>Scope</td>
<td>@(string.IsNullOrWhiteSpace(_client.Scope) ? "-" : _client.Scope.Replace(" ", ", "))</td>
Expand Down Expand Up @@ -302,10 +306,6 @@ else
<td>Backchannel Logout Session Required</td>
<td>@(_client.BackchannelLogoutSessionRequired ? "Yes" : "No")</td>
</tr>
<tr>
<td>Client Secret Expires At</td>
<td>@(_client.ClientSecretExpiresAt == 0 ? "never" : _client.ClientSecretExpiresAt)</td>
</tr>
<tr>
<td>Frontchannel Logout Session Required</td>
<td>@(_client.FrontchannelLogoutSessionRequired ? "Yes" : "No")</td>
Expand Down

0 comments on commit 0dacdc5

Please sign in to comment.