Skip to content

Commit

Permalink
fix: reset client secret
Browse files Browse the repository at this point in the history
  • Loading branch information
josxha committed Dec 29, 2023
1 parent aa5b034 commit e35c99a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 22 deletions.
51 changes: 33 additions & 18 deletions OryAdmin/Components/Pages/OAuth2/Clients/View.razor
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@ else
</tr>
<tr>
<td>Client secret</td>
<td>**************************</td>
<td>
@if (string.IsNullOrWhiteSpace(_client.ClientSecret))
{
<p>******</p>
}
else
{
<p>@(_client.ClientSecret)</p>
}
</td>
</tr>
<tr>
<td>Client secret expires at</td>
Expand Down Expand Up @@ -100,23 +109,29 @@ else
<div id="delete-client-modal" class="modal @(_confirmNewSecretModal ? "is-active" : "")">
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Reset Client Secret</p>
<button class="delete" aria-label="close" @onclick="() => _confirmNewSecretModal = true"></button>
</header>
<section class="modal-card-body">
<p>Are you sure to generate a new client secret?</p>
<p>This will delete the old client secret and replace it with a newly generated one.</p>
</section>
<footer class="modal-card-foot">
<button class="button" data-target="delete-client-modal"
type="button" @onclick="() => _confirmNewSecretModal = false">
Cancel
</button>
<div class="button is-danger" @onclick="CreateNewClientSecret">
Accept
</div>
</footer>
<form @onsubmit="CreateNewClientSecret">
<header class="modal-card-head">
<p class="modal-card-title">Reset client secret</p>
<button class="delete" aria-label="close" @onclick="() => _confirmNewSecretModal = true"></button>
</header>
<section class="modal-card-body">
<label class="label">
New client secret
<input @onchange="args => _newClientSecret = args.Value?.ToString()" minlength="6"
class="input" type="text"/>
</label>
<p>This will delete the old client secret and replace it with new new one.</p>
</section>
<footer class="modal-card-foot">
<button class="button" data-target="delete-client-modal"
type="button" @onclick="() => _confirmNewSecretModal = false">
Cancel
</button>
<button class="button is-danger" type="submit">
Accept
</button>
</footer>
</form>
</div>
</div>
<div id="delete-client-modal" class="modal @(_showNewSecretModal ? "is-active" : "")">
Expand Down
7 changes: 3 additions & 4 deletions OryAdmin/Components/Pages/OAuth2/Clients/View.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public partial class View
private bool _confirmDeleteClientModal;
private bool _confirmNewSecretModal;
private bool _isLoading = true;
private string? _newClientSecret;
private bool _showNewSecretModal;
[Parameter] public string? ClientId { get; set; }
[Inject] private ApiService ApiService { get; set; } = default!;
Expand Down Expand Up @@ -38,13 +39,11 @@ private void HideDeleteModal()

private async Task CreateNewClientSecret()
{
if (string.IsNullOrWhiteSpace(_newClientSecret)) return;
_confirmNewSecretModal = false;
var patches = new List<HydraJsonPatch>
{
// TODO this does not work!
new(op: "add", path: "/client_secret"),
new(op: "remove", path: "/client_secret"),
new(op: "replace", path: "/client_secret")
new(op: "replace", path: "/client_secret", value: _newClientSecret)
};
_client = await ApiService.HydraOAuth2.PatchOAuth2ClientAsync(ClientId, patches);
_showNewSecretModal = true;
Expand Down

0 comments on commit e35c99a

Please sign in to comment.