Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions UltimateAuth.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<Folder Name="/Tests/">
<Project Path="tests/CodeBeam.UltimateAuth.Tests.Unit/CodeBeam.UltimateAuth.Tests.Unit.csproj" Id="6f4b22da-849a-4a79-b5c5-aee7cb1429a6" />
</Folder>
<Project Path="src/authentication/CodeBeam.UltimateAuth.Authentication.InMemory/CodeBeam.UltimateAuth.Authentication.InMemory.csproj" Id="bd87e254-0565-4fc5-950d-ee5bbb416079" />
<Project Path="src/authorization/CodeBeam.UltimateAuth.Authorization.Contracts/CodeBeam.UltimateAuth.Authorization.Contracts.csproj" Id="40a23002-f885-42a8-bdd9-fd962ab28742" />
<Project Path="src/authorization/CodeBeam.UltimateAuth.Authorization.InMemory/CodeBeam.UltimateAuth.Authorization.InMemory.csproj" Id="a1e6d007-bdc0-4574-b549-ec863757edd3" />
<Project Path="src/authorization/CodeBeam.UltimateAuth.Authorization.Reference/CodeBeam.UltimateAuth.Authorization.Reference.csproj" Id="84b784d0-bb48-406a-a0d1-c600da667597" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\authentication\CodeBeam.UltimateAuth.Authentication.InMemory\CodeBeam.UltimateAuth.Authentication.InMemory.csproj" />
<ProjectReference Include="..\..\..\src\authorization\CodeBeam.UltimateAuth.Authorization.InMemory\CodeBeam.UltimateAuth.Authorization.InMemory.csproj" />
<ProjectReference Include="..\..\..\src\authorization\CodeBeam.UltimateAuth.Authorization.Reference\CodeBeam.UltimateAuth.Authorization.Reference.csproj" />
<ProjectReference Include="..\..\..\src\authorization\CodeBeam.UltimateAuth.Authorization\CodeBeam.UltimateAuth.Authorization.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using CodeBeam.UltimateAuth.Authentication.InMemory;
using CodeBeam.UltimateAuth.Authorization.InMemory;
using CodeBeam.UltimateAuth.Authorization.InMemory.Extensions;
using CodeBeam.UltimateAuth.Authorization.Reference.Extensions;
Expand All @@ -8,8 +9,6 @@
using CodeBeam.UltimateAuth.Credentials.Reference;
using CodeBeam.UltimateAuth.Sample.UAuthHub.Components;
using CodeBeam.UltimateAuth.Security.Argon2;
using CodeBeam.UltimateAuth.Server.Authentication;
using CodeBeam.UltimateAuth.Server.Defaults;
using CodeBeam.UltimateAuth.Server.Extensions;
using CodeBeam.UltimateAuth.Sessions.InMemory;
using CodeBeam.UltimateAuth.Tokens.InMemory;
Expand Down Expand Up @@ -57,6 +56,7 @@
.AddUltimateAuthAuthorizationReference()
.AddUltimateAuthInMemorySessions()
.AddUltimateAuthInMemoryTokens()
.AddUltimateAuthInMemoryAuthenticationSecurity()
.AddUltimateAuthArgon2();

builder.Services.AddUltimateAuthClient(o =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\authentication\CodeBeam.UltimateAuth.Authentication.InMemory\CodeBeam.UltimateAuth.Authentication.InMemory.csproj" />
<ProjectReference Include="..\..\..\src\authorization\CodeBeam.UltimateAuth.Authorization.InMemory\CodeBeam.UltimateAuth.Authorization.InMemory.csproj" />
<ProjectReference Include="..\..\..\src\authorization\CodeBeam.UltimateAuth.Authorization.Reference\CodeBeam.UltimateAuth.Authorization.Reference.csproj" />
<ProjectReference Include="..\..\..\src\authorization\CodeBeam.UltimateAuth.Authorization\CodeBeam.UltimateAuth.Authorization.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
@using CodeBeam.UltimateAuth.Core.Contracts
@using CodeBeam.UltimateAuth.Credentials.Contracts
@using CodeBeam.UltimateAuth.Users.Contracts
@inject IUAuthClient UAuthClient
@inject ISnackbar Snackbar
@inject IDialogService DialogService
@inject IUAuthStateManager StateManager
@inject NavigationManager Nav

<MudDialog Class="mud-width-full" ContentClass="uauth-dialog">
<TitleContent>
<MudText>Credential Management</MudText>
<MudText Typo="Typo.subtitle2" Color="Color.Primary">User: @AuthState?.Identity?.DisplayName</MudText>
</TitleContent>
<DialogContent>
<MudForm @ref="@_form" OnEnterPressed="@ChangePasswordAsync">
<MudGrid Spacing="2">
<MudItem xs="12" sm="6">
<MudPasswordField @bind-Value="_oldPassword" @bind-PasswordMode="@_passwordMode1" Label="Old Password" Variant="Variant.Outlined" Immediate="true" Required="true" />
</MudItem>

<MudItem xs="12" sm="6">
<MudPasswordField @bind-Value="_newPassword" @bind-PasswordMode="@_passwordMode2" Label="New Password" Variant="Variant.Outlined" Immediate="true" Required="true" />
</MudItem>

<MudItem xs="12" sm="6">
<MudPasswordField @bind-Value="_newPasswordCheck" @bind-PasswordMode="@_passwordMode3" Label="New Password (Again)" Variant="Variant.Outlined" Immediate="true" Required="true" Validation="@(new Func<string, string>(PasswordMatch))" />
</MudItem>

<MudItem xs="12">
<MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="ChangePasswordAsync">Change Password</MudButton>
</MudItem>
</MudGrid>
</MudForm>
</DialogContent>
<DialogActions>
<MudButton OnClick="Cancel">Cancel</MudButton>
<MudButton Color="Color.Primary" OnClick="Submit">OK</MudButton>
</DialogActions>
</MudDialog>

@code {
private MudForm _form = null!;
private string? _oldPassword;
private string? _newPassword;
private string? _newPasswordCheck;
private bool _passwordMode1 = false;
private bool _passwordMode2 = false;
private bool _passwordMode3 = true;

[CascadingParameter]
private IMudDialogInstance MudDialog { get; set; } = default!;

[Parameter]
public UAuthState AuthState { get; set; } = default!;

protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);

if (firstRender)
{

}
}

private async Task ChangePasswordAsync()
{
if (_form is null)
return;

await _form.Validate();
if (!_form.IsValid)
{
Snackbar.Add("Form is not valid.", Severity.Error);
return;
}

if (_newPassword != _newPasswordCheck)
{
Snackbar.Add("New password and check do not match", Severity.Error);
return;
}

ChangeCredentialRequest request = new ChangeCredentialRequest
{
CurrentSecret = _oldPassword!,
NewSecret = _newPassword!,
};

var result = await UAuthClient.Credentials.ChangeMyAsync(request);
if (result.IsSuccess)
{
Snackbar.Add("Password changed successfully", Severity.Success);
await UAuthClient.Flows.LogoutAsync();
}
else
{
Snackbar.Add(result?.Problem?.Detail ?? result?.Problem?.Title ?? "An error occurred while changing password", Severity.Error);
}
}

private string PasswordMatch(string arg) => _newPassword != arg ? "Passwords don't match" : string.Empty;

private void Submit() => MudDialog.Close(DialogResult.Ok(true));

private void Cancel() => MudDialog.Cancel();
}
Loading