Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ongoing/anton #13

Open
wants to merge 42 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
2154a15
add check installed MetaMask, and service promise
LICH010 Dec 29, 2017
c1c5633
edit test
LICH010 Dec 29, 2017
e9b917c
PromiseDTO settings
LICH010 Dec 29, 2017
08ee809
migrate
LICH010 Dec 29, 2017
fb8de36
Refactored DbMigrations ( update-migration error) and removed unneces…
jokerosky Jan 8, 2018
4547232
few n2npromise service tests
jokerosky Jan 8, 2018
1786f24
merge with Anton ongoing changes
LICH010 Jan 9, 2018
7997a85
N2N Authorization filter and tests. Misspelling, and migrations.
jokerosky Jan 14, 2018
fbd8fe7
interfaces refactoring
jokerosky Jan 14, 2018
7fe8064
App starting refactoring, users and roles initializator
jokerosky Jan 18, 2018
eef58cf
#12 experiments with promise format
LICH010 Jan 19, 2018
0c62056
intermediate commit
LICH010 Jan 22, 2018
d6a8dc5
SimpleInjector removed, Add startup roles and users initialization, r…
jokerosky Jan 22, 2018
6d900f6
intermediate commit
LICH010 Jan 22, 2018
7051e9c
Merge origin/ongoing/anton
LICH010 Jan 22, 2018
f9a54fa
Test structure refactoring, and App
jokerosky Jan 24, 2018
0e417e6
in memory and sql databases for tests.
jokerosky Jan 26, 2018
47010a7
Fixed test db population, changed database model binder.
jokerosky Jan 29, 2018
8dedc57
Again recreate migrations (with removing all previous.
jokerosky Jan 30, 2018
1ff552d
Refactor AuthenticationService
LICH010 Jan 31, 2018
fcfeb14
user statistics service
jokerosky Jan 31, 2018
d6cb441
merge with ongoing/anton
LICH010 Jan 31, 2018
0d6c3ab
Merge remote-tracking branch 'origin/ongoing/anton' into n2n/12
LICH010 Jan 31, 2018
a2c7791
start implementing postcard service
jokerosky Feb 1, 2018
0130b21
Merge remote-tracking branch 'origin/n2n/12' into ongoing/anton
jokerosky Feb 1, 2018
4597259
authentication refactoring started
jokerosky Feb 2, 2018
985f84f
Authentication service refactoring started
jokerosky Feb 13, 2018
113354a
removed identity server4 package + tests for refactored authenticatio…
jokerosky Feb 22, 2018
e1f807b
continue authentication refactoring
jokerosky Mar 10, 2018
bdae2bb
Change architecture to x86 for Api and tests. add async add and get o…
jokerosky Mar 11, 2018
e31a37b
continue authentication infrastructure refactroing
jokerosky Mar 15, 2018
1a89e9e
Authentication refactoring, tests for AuthFilter attribute and Auth …
jokerosky Mar 16, 2018
186e08c
Authentication service refactoring finished, but have Current princip…
jokerosky Mar 21, 2018
64c2313
auth and tests refactoring, actual problem Principal for SecurityServ…
jokerosky Mar 22, 2018
8b21f3d
Mvc references for api.test
jokerosky Mar 25, 2018
8ee027c
backend program start bug fixed
jokerosky Mar 25, 2018
84a0bae
update angular to 7 and start web app form scratch
jokerosky Nov 5, 2018
5a397b7
Frontend adjustments for registration
jokerosky Nov 5, 2018
46ec2e3
Identity Server instead of manual token creation
jokerosky Nov 5, 2018
43bd0e3
redirect after registration
jokerosky Nov 6, 2018
5458330
little bit authorization
jokerosky Nov 19, 2018
dd50d6b
project update and papertrail loggin
jokerosky Dec 2, 2018
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
39 changes: 30 additions & 9 deletions N2N.sln
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2009
VisualStudioVersion = 15.0.27130.2024
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E17A8916-7BC2-4F80-9198-1CA6744EBB3C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{7F19DC56-9B6E-4B4F-909C-20B87759A4BA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "N2N.Api", "src\N2N.Api\N2N.Api.csproj", "{52F13DD7-82C4-4C44-8023-7F6D7B0AD8EB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N2N.Infrastructure.Tests", "tests\N2N.Infrastructure.Tests\N2N.Infrastructure.Tests.csproj", "{AE7BBF0E-58EF-4076-A191-2F4229D0D53D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N2N.Core", "src\N2N.Core\N2N.Core.csproj", "{94757EF4-4F40-4FCA-B64F-95AB5942B0D6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N2N.Infrasturcture", "src\N2N.Infrastructure\N2N.Infrasturcture.csproj", "{E45EAE66-10ED-4179-805A-F6A5B65F6532}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N2N.Infrastructure", "src\N2N.Infrastructure\N2N.Infrastructure.csproj", "{E45EAE66-10ED-4179-805A-F6A5B65F6532}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "N2N.Web", "src\N2N.Web\N2N.Web.csproj", "{8B788DD5-8887-4463-AD79-18FEA9E27272}"
EndProject
Expand All @@ -32,6 +30,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N2N.Utilities", "src\N2N.Ut
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N2N.Services", "src\N2N.Services\N2N.Services.csproj", "{2D14710E-BF4B-4A05-B189-DBC94D0DEC1C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N2N.Services.Tests", "tests\N2N.Services.Tests\N2N.Services.Tests.csproj", "{2BCC13D6-3A1F-4B40-9230-0A9851844E24}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N2N.TestData", "tests\N2N.TestData\N2N.TestData.csproj", "{053BA1AC-81FE-49A7-B07F-5DA0B87843C9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N2N.Api.Tests", "tests\N2N.Api.Tests\N2N.Api.Tests.csproj", "{1AF2CDCC-F8BC-44D0-A688-E2486A617186}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N2N.Infrastructure.Tests", "tests\N2N.Infrastructure.Tests\N2N.Infrastructure.Tests.csproj", "{B133C9A4-6BEC-45DC-B99C-F3447672606F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -42,10 +48,6 @@ Global
{52F13DD7-82C4-4C44-8023-7F6D7B0AD8EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{52F13DD7-82C4-4C44-8023-7F6D7B0AD8EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{52F13DD7-82C4-4C44-8023-7F6D7B0AD8EB}.Release|Any CPU.Build.0 = Release|Any CPU
{AE7BBF0E-58EF-4076-A191-2F4229D0D53D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AE7BBF0E-58EF-4076-A191-2F4229D0D53D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AE7BBF0E-58EF-4076-A191-2F4229D0D53D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE7BBF0E-58EF-4076-A191-2F4229D0D53D}.Release|Any CPU.Build.0 = Release|Any CPU
{94757EF4-4F40-4FCA-B64F-95AB5942B0D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{94757EF4-4F40-4FCA-B64F-95AB5942B0D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{94757EF4-4F40-4FCA-B64F-95AB5942B0D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -66,18 +68,37 @@ Global
{2D14710E-BF4B-4A05-B189-DBC94D0DEC1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2D14710E-BF4B-4A05-B189-DBC94D0DEC1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2D14710E-BF4B-4A05-B189-DBC94D0DEC1C}.Release|Any CPU.Build.0 = Release|Any CPU
{2BCC13D6-3A1F-4B40-9230-0A9851844E24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2BCC13D6-3A1F-4B40-9230-0A9851844E24}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2BCC13D6-3A1F-4B40-9230-0A9851844E24}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2BCC13D6-3A1F-4B40-9230-0A9851844E24}.Release|Any CPU.Build.0 = Release|Any CPU
{053BA1AC-81FE-49A7-B07F-5DA0B87843C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{053BA1AC-81FE-49A7-B07F-5DA0B87843C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{053BA1AC-81FE-49A7-B07F-5DA0B87843C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{053BA1AC-81FE-49A7-B07F-5DA0B87843C9}.Release|Any CPU.Build.0 = Release|Any CPU
{1AF2CDCC-F8BC-44D0-A688-E2486A617186}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1AF2CDCC-F8BC-44D0-A688-E2486A617186}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1AF2CDCC-F8BC-44D0-A688-E2486A617186}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1AF2CDCC-F8BC-44D0-A688-E2486A617186}.Release|Any CPU.Build.0 = Release|Any CPU
{B133C9A4-6BEC-45DC-B99C-F3447672606F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B133C9A4-6BEC-45DC-B99C-F3447672606F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B133C9A4-6BEC-45DC-B99C-F3447672606F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B133C9A4-6BEC-45DC-B99C-F3447672606F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{52F13DD7-82C4-4C44-8023-7F6D7B0AD8EB} = {E17A8916-7BC2-4F80-9198-1CA6744EBB3C}
{AE7BBF0E-58EF-4076-A191-2F4229D0D53D} = {7F19DC56-9B6E-4B4F-909C-20B87759A4BA}
{94757EF4-4F40-4FCA-B64F-95AB5942B0D6} = {E17A8916-7BC2-4F80-9198-1CA6744EBB3C}
{E45EAE66-10ED-4179-805A-F6A5B65F6532} = {E17A8916-7BC2-4F80-9198-1CA6744EBB3C}
{8B788DD5-8887-4463-AD79-18FEA9E27272} = {E17A8916-7BC2-4F80-9198-1CA6744EBB3C}
{611CDBEB-2465-4BC4-B249-3A4ABC93E62A} = {E17A8916-7BC2-4F80-9198-1CA6744EBB3C}
{2D14710E-BF4B-4A05-B189-DBC94D0DEC1C} = {E17A8916-7BC2-4F80-9198-1CA6744EBB3C}
{2BCC13D6-3A1F-4B40-9230-0A9851844E24} = {7F19DC56-9B6E-4B4F-909C-20B87759A4BA}
{053BA1AC-81FE-49A7-B07F-5DA0B87843C9} = {7F19DC56-9B6E-4B4F-909C-20B87759A4BA}
{1AF2CDCC-F8BC-44D0-A688-E2486A617186} = {7F19DC56-9B6E-4B4F-909C-20B87759A4BA}
{B133C9A4-6BEC-45DC-B99C-F3447672606F} = {7F19DC56-9B6E-4B4F-909C-20B87759A4BA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EEA9FF11-6FF0-4EF2-A7AF-699EDC60DA0E}
Expand Down
110 changes: 110 additions & 0 deletions src/N2N.Api/Configuration/AppConfigurator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Security.Principal;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.ViewComponents;
using Microsoft.Extensions.DependencyInjection;
using N2N.Api.Services;
using N2N.Core.Constants;
using N2N.Core.Entities;
using N2N.Core.Services;
using N2N.Infrastructure.Repositories;
using N2N.Infrastructure.DataContext;
using N2N.Infrastructure.Models;
using N2N.Services;

namespace N2N.Api.Configuration
{
public class AppConfigurator //have to make it public because want to test it
{
internal void UseMvcAndConfigureRoutes(IApplicationBuilder app)
{
app.UseCors("AllowSpecificOrigin");

app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=N2N}/{action=Index}/{id?}");
});
}

public void InitRolesAndUsers(IServiceProvider services)
{
var roles = new List<IdentityRole>()
{
new IdentityRole(N2NRoles.Admin),
new IdentityRole(N2NRoles.User)
};

var users = new Dictionary<N2NUser, string>()
{
//{new N2NUser(){NickName = "jokero"}, "Password@123"},
{new N2NUser(){NickName = "admin"}, "Password@123"},
//{new N2NUser(){NickName = "Administrator"}, "Password@123"}
};

var httpContextAccessor = services.GetService<IHttpContextAccessor>();
// Make a user N2N System user to initialize the database
var stubHttpContext = httpContextAccessor.HttpContext ?? new DefaultHttpContext();
httpContextAccessor.HttpContext = stubHttpContext;
var principal = new ClaimsPrincipal(stubHttpContext.User);
httpContextAccessor.HttpContext.User = N2NSystem.GetN2NSystemPrincipal();

var roleManager = services.GetRequiredService<RoleManager<IdentityRole>>();
var userService = services.GetRequiredService<N2NApiUserService>();

foreach (var role in roles)
{
if (!roleManager.RoleExistsAsync(role.Name).Result)
{
roleManager.CreateAsync(role).Wait(N2NTimingsAndValues.AsyncTaskWaitTime);
}
}

foreach (var user in users)
{
if (!userService.UserExistsAndConsistentAsync(user.Key.NickName).Result)
{
userService.CreateUserAsync(user.Key, user.Value, new []{ N2NRoles.User, N2NRoles.Admin }).Wait(N2NTimingsAndValues.AsyncTaskWaitTime);
}
}

httpContextAccessor.HttpContext.User = principal;
}

/// <summary>
/// Wire up dependecy injection
/// </summary>
/// <param name="services"></param>
public void ConfigureServices(IServiceCollection services)
{
services.AddTransient<IRepository<N2NRefreshToken>, DbRepository<N2NRefreshToken>>();
services.AddTransient<IRepository<N2NToken>, DbRepository<N2NToken>>();
services.AddTransient<IRepository<N2NUser>, DbRepository<N2NUser>>();
services.AddTransient<IAuthenticationService, AuthenticationService>();

services.AddTransient<IRepository<N2NUser>, DbRepository<N2NUser>>();
services.AddTransient<IRepository<N2NToken>, DbRepository<N2NToken>>();
services.AddTransient<IRepository<N2NRefreshToken>, DbRepository<N2NRefreshToken>>();
services.AddTransient<ISecurityService, SecurityService>();
services.AddTransient<IN2NUserService, N2NUserService>();

services.AddTransient<N2NApiUserService>();

services.AddTransient<IPostCardService, N2NPostCardService>();
services.AddTransient<IUsersStatisticsService, UsersStatisticsService>();
services.AddTransient<IN2NTokenService, TokenService>();

services.AddTransient<IPrincipal>(provider =>
provider.GetService<IHttpContextAccessor>()?.HttpContext?.User
);
}
}
}
94 changes: 0 additions & 94 deletions src/N2N.Api/Configuration/AppStart.cs

This file was deleted.

14 changes: 0 additions & 14 deletions src/N2N.Api/Configuration/IConfig.cs

This file was deleted.

67 changes: 67 additions & 0 deletions src/N2N.Api/Configuration/IdentityServer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using IdentityModel;
using IdentityServer4;
using IdentityServer4.Models;

namespace N2N.Api.Configuration
{
public class IdentityServer
{
public static IEnumerable<IdentityResource> GetIdentityResources()
{
return new List<IdentityResource>
{
new IdentityResources.OpenId(),
new IdentityResources.Email(),
new IdentityResources.Profile(),
new IdentityResources.Phone(),
new IdentityResources.Address()
};
}

public static IEnumerable<ApiResource> GetApis()
{
return new List<ApiResource>()
{
// simple API with a single scope (in this case the scope name is the same as the api name)
new ApiResource(SiteConstants.ApiName),

};
}


public static IEnumerable<Client> GetClients()
{
return new List<Client>
{
new Client
{
ClientId = "frontend",
ClientName = "N2N site",

AllowedGrantTypes = GrantTypes.ResourceOwnerPasswordAndClientCredentials,
AccessTokenType = AccessTokenType.Jwt,
AccessTokenLifetime = SiteConstants.AccessTokenLifeTime,
AllowOfflineAccess = true, // allow refresh_token to be generated
AllowAccessTokensViaBrowser = true,

RefreshTokenExpiration = TokenExpiration.Sliding,

ClientSecrets =
{
new Secret("secret".Sha256())
},

RequireConsent = false,
AllowedScopes =
{
SiteConstants.ApiName
}
}
};
}
}
}
18 changes: 18 additions & 0 deletions src/N2N.Api/Configuration/N2NTokenConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;

namespace N2N.Api.Configuration
{
public class N2NTokenConfig
{
public string Issuer { get; set; }
public string Audience { get; set; }
public DateTime ValidFrom { get; set; }
public DateTime ValidTill { get; set; }

public IEnumerable<Claim> Claims { get; set; }
}
}
Loading