Skip to content

Commit

Permalink
feat: delete identity sessions, invoke identity session button
Browse files Browse the repository at this point in the history
  • Loading branch information
josxha committed Jan 5, 2024
1 parent e43cc1b commit d05ff7f
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 15 deletions.
95 changes: 83 additions & 12 deletions OryAdmin/Components/Pages/Identities/Users/View.razor
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,26 @@ else
Update Password
</button>
<button class="js-modal-trigger button is-danger" data-target="delete-identity-modal"
type="button" @onclick="() => _showDeleteModal = true">
type="button" @onclick="() => _showDeleteIdentityModal = true">
Delete Identity
</button>
</div>
@if (_showDeleteModal)
@if (_showDeleteIdentityModal)
{
<div id="delete-identity-modal" class="modal is-active">
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Confirm Deletion</p>
<button class="delete" aria-label="close" @onclick="() => _showDeleteModal = false"></button>
<button class="delete" aria-label="close" @onclick="() => _showDeleteIdentityModal = false"></button>
</header>
<section class="modal-card-body">
<p>Are you sure to delete this identity?</p>
<p>Be aware that this cannot be undone.</p>
</section>
<footer class="modal-card-foot">
<button class="button" data-target="delete-identity-modal"
type="button" @onclick="() => _showDeleteModal = false">
type="button" @onclick="() => _showDeleteIdentityModal = false">
Cancel
</button>
<div class="button is-danger" @onclick="DeleteIdentity">
Expand Down Expand Up @@ -112,6 +112,7 @@ else
<td>Authenticator Assurance Level</td>
<td>Devices</td>
<td>Timestamps</td>
<td></td>
</tr>
</thead>
<tbody>
Expand All @@ -132,20 +133,90 @@ else
<p>Issued: @session.IssuedAt</p>
<p>Expires: @session.ExpiresAt</p>
</td>
<td>
<button class="button is-warning is-small"
@onclick="() => _identitySessionToInvoke = session">
Disable
</button>
</td>
</tr>
}
</tbody>
</table>
<div class="buttons">
<button class="js-modal-trigger button is-danger" data-target="delete-identity-modal"
type="button" @onclick="() => _showDeleteSessionsModal = true">
Delete Sessions
</button>
</div>

@if (_identitySessionToInvoke != null)
{
<div id="delete-identity-modal" class="modal is-active">
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Confirm Invoke Session</p>
<button class="delete" aria-label="close"
@onclick="() => _identitySessionToInvoke = null">
</button>
</header>
<section class="modal-card-body">
<p>Are you sure to invoke the identity session?</p>
<p></p>
<p>Be aware that this cannot be undone.</p>
</section>
<footer class="modal-card-foot">
<button class="button" data-target="delete-identity-modal"
type="button" @onclick="() => _identitySessionToInvoke = null">
Cancel
</button>
<div class="button is-danger"
@onclick="() => DisableIdentitySession(_identitySessionToInvoke.Id)">
Yes
</div>
</footer>
</div>
</div>
}

@if (_showDeleteSessionsModal)
{
<div id="delete-identity-modal" class="modal is-active">
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Confirm Delete User Sessions</p>
<button class="delete" aria-label="close"
@onclick="() => _showDeleteSessionsModal = false">
</button>
</header>
<section class="modal-card-body">
<p>Are you sure to delete every session for this identity?</p>
<p>Be aware that this cannot be undone.</p>
</section>
<footer class="modal-card-foot">
<button class="button" data-target="delete-identity-modal"
type="button" @onclick="() => _showDeleteSessionsModal = false">
Cancel
</button>
<div class="button is-danger" @onclick="DeleteIdentitySessions">
Yes
</div>
</footer>
</div>
</div>
}
}
</div>

@if (_oauth2Sessions != null)
{
<div class="box">
<h1 class="title">Active Oauth2 Sessions</h1>
<h1 class="title">Active OAuth2 Sessions</h1>
@if (_oauth2Sessions!.Count == 0)
{
<p>This user has no active oauth2 sessions.</p>
<p>This user has no active OAuth2 sessions.</p>
}
else
{
Expand Down Expand Up @@ -191,7 +262,7 @@ else
<td>@(session.ExpiresAt != null ? session.ExpiresAt?.RefreshToken : "-")</td>
<td>
<button class="button is-info is-small"
@onclick="() => _oauth2SessionDetails = session">
@onclick="() => _oauth2SessionToShowDetailsFor = session">
Details
</button>
</td>
Expand Down Expand Up @@ -231,32 +302,32 @@ else
</div>
}

@if (_oauth2SessionDetails != null)
@if (_oauth2SessionToShowDetailsFor != null)
{
<div id="oauth2-session-details" class="modal is-active">
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">OAuth2 session details</p>
<button class="delete" aria-label="close" @onclick="() => _oauth2SessionDetails = null"></button>
<button class="delete" aria-label="close" @onclick="() => _oauth2SessionToShowDetailsFor = null"></button>
</header>
<section class="modal-card-body">
<table class="table is-fullwidth">
<tbody>
<tr>
<td>Session access token</td>
<td>@_oauth2SessionDetails.Session.AccessToken</td>
<td>@_oauth2SessionToShowDetailsFor.Session.AccessToken</td>
</tr>
<tr>
<td>Session ID token</td>
<td>@_oauth2SessionDetails.Session.IdToken</td>
<td>@_oauth2SessionToShowDetailsFor.Session.IdToken</td>
</tr>
</tbody>
</table>
</section>
<footer class="modal-card-foot">
<button class="button" data-target="delete-client-modal"
type="button" @onclick="() => _oauth2SessionDetails = null">
type="button" @onclick="() => _oauth2SessionToShowDetailsFor = null">
OK
</button>
</footer>
Expand Down
21 changes: 18 additions & 3 deletions OryAdmin/Components/Pages/Identities/Users/View.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ public partial class View
{
private List<KratosSession>? _activeSessions;
private KratosIdentity? _identity;
private KratosSession? _identitySessionToInvoke;
private bool _isLoading = true;
private HydraOAuth2ConsentSession? _oauth2SessionDetails;
private List<HydraOAuth2ConsentSession>? _oauth2Sessions;
private bool _showDeleteModal;
private HydraOAuth2ConsentSession? _oauth2SessionToShowDetailsFor;
private bool _showDeleteIdentityModal;
private bool _showDeleteSessionsModal;
private bool _showRevokeOAuth2SessionsModal;
[Parameter] public string? UserId { get; set; }
[Inject] private ApiService ApiService { get; set; } = default!;
Expand Down Expand Up @@ -55,7 +57,20 @@ private async Task UpdatePassword()
private async Task RevokeOAuth2ConsentSessions()
{
await ApiService.HydraOAuth2.RevokeOAuth2ConsentSessionsAsync(UserId, all: true);
// reload oauth2 sessions
_showRevokeOAuth2SessionsModal = false;
_oauth2Sessions = await ApiService.HydraOAuth2.ListOAuth2ConsentSessionsAsync(UserId);
}

private async Task DeleteIdentitySessions()
{
await ApiService.KratosIdentity.DeleteIdentitySessionsAsync(UserId);
_showDeleteSessionsModal = false;
_activeSessions = await ApiService.KratosIdentity.ListIdentitySessionsAsync(UserId, active: true);
}

private async Task DisableIdentitySession(string sessionId)
{
await ApiService.KratosIdentity.DisableSessionAsync(sessionId);
_activeSessions = await ApiService.KratosIdentity.ListIdentitySessionsAsync(UserId, active: true);
}
}

0 comments on commit d05ff7f

Please sign in to comment.