Skip to content

Commit

Permalink
Merge hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm360 committed Nov 19, 2021
2 parents ce0f1a4 + 4e29c4b commit e2b1525
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 33 deletions.
6 changes: 3 additions & 3 deletions src/EthernaSSO.Domain/EthernaSSO.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EthernaRCL" Version="0.1.0-alpha.9" />
<PackageReference Include="Etherna.DomainEvents" Version="1.3.0" />
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="5.0.11" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Etherna" Version="0.3.0-alpha.7" />
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="5.0.12" />
<PackageReference Include="MongODM.Core" Version="0.23.0-alpha.37" />
<PackageReference Include="Nethereum.Accounts" Version="4.1.0" />
<PackageReference Include="Nethereum.Accounts" Version="4.1.1" />
</ItemGroup>

</Project>
23 changes: 16 additions & 7 deletions src/EthernaSSO.Domain/Models/UserBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,30 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using Etherna.Authentication;
using Etherna.MongODM.Core.Attributes;
using Etherna.RCL;
using Etherna.SSOServer.Domain.Helpers;
using Etherna.SSOServer.Domain.Models.UserAgg;
using Microsoft.AspNetCore.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text.Json;

namespace Etherna.SSOServer.Domain.Models
{
public abstract class UserBase : EntityModelBase<string>
{
// Consts.
public static readonly IEnumerable<string> DomainManagedClaimNames = new[]
{
ClaimTypes.EtherAddress,
ClaimTypes.EtherPreviousAddresses,
ClaimTypes.IsWeb3Account,
ClaimTypes.Role,
ClaimTypes.Username
};

// Fields.
private readonly List<UserClaim> _customClaims = new();
private List<string> _etherPreviousAddresses = new();
Expand Down Expand Up @@ -58,10 +67,10 @@ public virtual IEnumerable<UserClaim> DefaultClaims
{
var claims = new List<UserClaim>
{
new UserClaim(UserClaimTypes.EtherAddress, EtherAddress),
new UserClaim(UserClaimTypes.EtherPreviousAddresses, JsonSerializer.Serialize(_etherPreviousAddresses)),
new UserClaim(UserClaimTypes.IsWeb3Account, (this is UserWeb3).ToString()),
new UserClaim(UserClaimTypes.Username, Username)
new UserClaim(ClaimTypes.EtherAddress, EtherAddress),
new UserClaim(ClaimTypes.EtherPreviousAddresses, JsonSerializer.Serialize(_etherPreviousAddresses)),
new UserClaim(ClaimTypes.IsWeb3Account, (this is UserWeb3).ToString()),
new UserClaim(ClaimTypes.Username, Username)
};

foreach (var role in _roles)
Expand Down Expand Up @@ -110,7 +119,7 @@ public virtual bool AddClaim(UserClaim claim)
throw new ArgumentNullException(nameof(claim));

//keep default claims managed by model
if (UserClaimTypes.Names.Contains(claim.Type))
if (DomainManagedClaimNames.Contains(claim.Type))
return false;

//don't add duplicate claims
Expand Down
16 changes: 15 additions & 1 deletion src/EthernaSSO.Persistence/Settings/DbSeedSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
namespace Etherna.SSOServer.Persistence.Settings
// Copyright 2021-present Etherna Sagl
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Etherna.SSOServer.Persistence.Settings
{
public class DbSeedSettings
{
Expand Down
3 changes: 3 additions & 0 deletions src/EthernaSSO.Persistence/SsoDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public SsoDbContext(
(Builders<UserBase>.IndexKeys.Ascending(u => u.EtherAddress),
new CreateIndexOptions<UserBase> { Unique = true }),

(Builders<UserBase>.IndexKeys.Ascending(u => u.EtherPreviousAddresses),
new CreateIndexOptions<UserBase> { Unique = true }),

(Builders<UserBase>.IndexKeys.Descending(u => u.LastLoginDateTime),
new CreateIndexOptions<UserBase> { Sparse = true }),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<td>@claim.Type</td>
<td>@claim.Value</td>
<td>
@if (!UserClaimTypes.Names.Contains(claim.Type))
@if (!UserBase.DomainManagedClaimNames.Contains(claim.Type))
{
<a asp-page="UserClaimsDelete"
asp-route-claimType="@claim.Type"
Expand Down
2 changes: 1 addition & 1 deletion src/EthernaSSO/Areas/Api/Controllers/IdentityController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
namespace Etherna.SSOServer.Areas.Api.Controllers
{
[ApiController]
[ApiVersion("0.2")]
[ApiVersion("0.3")]
[Route("api/v{api-version:apiVersion}/[controller]")]
public class IdentityController : Controller
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
namespace Etherna.SSOServer.Areas.Api.Controllers
{
[ApiController]
[ApiVersion("0.2")]
[ApiVersion("0.3")]
[Route("api/v{api-version:apiVersion}/[controller]")]
[Authorize(CommonConsts.ServiceInteractApiScopePolicy)]
public class ServiceInteractController : ControllerBase
Expand Down
4 changes: 3 additions & 1 deletion src/EthernaSSO/Areas/Identity/Pages/Account/Login.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ await userManager.FindByEmailAsync(Input.UsernameOrEmail) :
}

//validate login
var result = await signInManager.PasswordSignInAsync(user, Input.Password, true, lockoutOnFailure: true);
var result = user is UserWeb2 ? //if user is not UserWeb2, fail password login
await signInManager.PasswordSignInAsync(user, Input.Password, true, lockoutOnFailure: true) :
Microsoft.AspNetCore.Identity.SignInResult.Failed;

if (result.Succeeded)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<div asp-validation-summary="All" class="text-danger"></div>
<div class="mb-3">
<label asp-for="Input.TwoFactorCode"></label>
<input asp-for="Input.TwoFactorCode" class="form-control" autocomplete="off" />
<input asp-for="Input.TwoFactorCode" class="form-control" autocomplete="one-time-code" />
<span asp-validation-for="Input.TwoFactorCode" class="text-danger"></span>
</div>
<div class="mb-3">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<form id="send-code" method="post">
<div class="mb-3">
<label asp-for="Input.Code" class="control-label">Verification Code</label>
<input asp-for="Input.Code" class="form-control" autocomplete="off" />
<input asp-for="Input.Code" class="form-control" autocomplete="one-time-code" />
<span asp-validation-for="Input.Code" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Verify</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ else
<div class="mb-3">
<label asp-for="EmailInput.Email"></label>
<input asp-for="EmailInput.Email" class="form-control" />
<button type="submit" class="btn btn-secondary mt-2">Send email</button>
<button type="submit" class="btn btn-secondary mt-2">Send code</button>
</div>
</form>

Expand Down
10 changes: 5 additions & 5 deletions src/EthernaSSO/Configs/IdentityServer/IdServerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using Etherna.RCL;
using Etherna.Authentication;
using Etherna.RCL.Exceptions;
using IdentityServer4;
using IdentityServer4.Models;
Expand Down Expand Up @@ -229,9 +229,9 @@ public IdServerConfig(IConfiguration configuration)
Name = "ether_accounts",
UserClaims = new List<string>()
{
UserClaimTypes.EtherAddress,
UserClaimTypes.EtherPreviousAddresses,
UserClaimTypes.IsWeb3Account
ClaimTypes.EtherAddress,
ClaimTypes.EtherPreviousAddresses,
ClaimTypes.IsWeb3Account
}
},
new IdentityResource()
Expand All @@ -240,7 +240,7 @@ public IdServerConfig(IConfiguration configuration)
Name = "role",
UserClaims = new List<string>()
{
UserClaimTypes.Role
ClaimTypes.Role
}
}
};
Expand Down
16 changes: 8 additions & 8 deletions src/EthernaSSO/EthernaSSO.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,27 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GitVersion.MsBuild" Version="5.7.0">
<PackageReference Include="EthernaRCL" Version="0.1.0-alpha.12" />
<PackageReference Include="GitVersion.MsBuild" Version="5.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="5.0.11" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="5.0.11" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.11" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Twitter" Version="5.0.11" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="5.0.11" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="5.0.12" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="5.0.12" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.12" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Twitter" Version="5.0.12" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="5.0.12" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="5.0.0" />
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="4.4.4"> <!--Installed only for hide warning-->
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.11.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
<PackageReference Include="MongODM" Version="0.23.0-alpha.37" />
<PackageReference Include="MongODM.AspNetCore.UI" Version="0.23.0-alpha.37" />
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.2.0" />
<PackageReference Include="Serilog.Exceptions" Version="7.1.0" />
<PackageReference Include="Serilog.Exceptions" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Elasticsearch" Version="8.4.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
Expand Down
16 changes: 15 additions & 1 deletion src/EthernaSSO/Extensions/LoggerExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
using Microsoft.Extensions.Logging;
// Copyright 2021-present Etherna Sagl
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;

Expand Down
4 changes: 3 additions & 1 deletion src/EthernaSSO/Pages/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container">
<a class="navbar-brand" asp-area="" asp-page="/Index">Etherna SSO Server</a>
<a class="navbar-brand" asp-area="" asp-page="/Index">
<img src="/images/etherna-header-symbol-colors.png" style="padding-right:4px" /> Etherna SSO Server
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar-menu"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e2b1525

Please sign in to comment.