Skip to content

Commit

Permalink
Update for Blazor wasm RC
Browse files Browse the repository at this point in the history
  • Loading branch information
rockfordlhotka committed May 18, 2020
1 parent cefa444 commit 4626578
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ else

private async void VerifyCredentials()
{
var identity = await DataPortal.FetchAsync<CustomIdentity>(vm.Model);
var baseidentity = new ClaimsIdentity(identity.AuthenticationType);
baseidentity.AddClaim(new Claim(ClaimTypes.Name, identity.Name));
if (identity.Roles != null)
foreach (var item in identity.Roles)
baseidentity.AddClaim(new Claim(ClaimTypes.Role, item));
var principal = new System.Security.Claims.ClaimsPrincipal(baseidentity);
var userInfo = await DataPortal.FetchAsync<CredentialValidator>(vm.Model);
var identity = new ClaimsIdentity(userInfo.AuthenticationType);
identity.AddClaim(new Claim(ClaimTypes.Name, userInfo.Name));
if (userInfo.Roles != null)
foreach (var item in userInfo.Roles)
identity.AddClaim(new Claim(ClaimTypes.Role, item));
var principal = new System.Security.Claims.ClaimsPrincipal(identity);
userService.CurrentUser = principal;
StateHasChanged();
nav.NavigateTo("/");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using Csla;

namespace BlazorCslaAuthentication.Shared
{
/// <summary>
/// Verifies the supplied user credentials and
/// returns information about the verified user.
/// </summary>
[Serializable]
public class CredentialValidator : ReadOnlyBase<CredentialValidator>
{
public static readonly PropertyInfo<string> NameProperty = RegisterProperty<string>(nameof(Name));
public string Name
{
get => GetProperty(NameProperty);
private set => LoadProperty(NameProperty, value);
}

public static readonly PropertyInfo<string> AuthenticationTypeProperty = RegisterProperty<string>(nameof(AuthenticationType));
public string AuthenticationType
{
get => GetProperty(AuthenticationTypeProperty);
private set => LoadProperty(AuthenticationTypeProperty, value);
}

public static readonly PropertyInfo<Csla.Core.MobileList<string>> RolesProperty = RegisterProperty<Csla.Core.MobileList<string>>(nameof(Roles));
public Csla.Core.MobileList<string> Roles
{
get => GetProperty(RolesProperty);
private set => LoadProperty(RolesProperty, value);
}

[Fetch]
private void Fetch(UserCredentials credentials)
{
// validate credentials here
if (!string.IsNullOrWhiteSpace(credentials.Username))
{
Name = credentials.Username;
AuthenticationType = "Custom";
Roles = new Csla.Core.MobileList<string>
{
"StandardUser",
"PersonCreator"
};
}
else
{
Name = string.Empty;
AuthenticationType = string.Empty;
Roles = new Csla.Core.MobileList<string>();
}
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

namespace BlazorCslaAuthentication.Shared
{
/// <summary>
/// Responsible for getting user credentials
/// from the user and acting as criteria for
/// the CredentialValidator type.
/// </summary>
[Serializable]
public class UserCredentials : BusinessBase<UserCredentials>
{
Expand Down
8 changes: 4 additions & 4 deletions BlazorCslaExample/BlazorCslaExample/BlazorCslaExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Csla.AspNetCore" Version="5.2.0-R20050802" />
<PackageReference Include="Csla.Blazor" Version="5.2.0-R20050802" />
<PackageReference Include="Csla.AspNetCore" Version="5.2.0-R20051501" />
<PackageReference Include="Csla.Blazor" Version="5.2.0-R20051501" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.0-rc1.20223.4" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.4" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ else
</tr>
</thead>
<tbody>
<DisplayRow Property="vm.GetPropertyInfo(nameof(vm.Model.Id))" />
<TextInputRow Property="vm.GetPropertyInfo(nameof(vm.Model.Name))" />
<DateInputRow Property="vm.GetPropertyInfo(nameof(vm.Model.Birthdate))" />
<DisplayRow Property="vm.GetPropertyInfo(nameof(vm.Model.Age))" />
<DisplayRow Property="vm.GetPropertyInfo(() => vm.Model.Id)" />
<TextInputRow Property="vm.GetPropertyInfo(() => vm.Model.Name)" />
<DateInputRow Property="vm.GetPropertyInfo(() => vm.Model.Birthdate)" />
<DisplayRow Property="vm.GetPropertyInfo(() => vm.Model.Age)" />
</tbody>
</table>
<button @onclick="vm.SaveAsync" disabled="@(!vm.Model.IsSavable)">Save</button>
Expand Down

0 comments on commit 4626578

Please sign in to comment.