Skip to content
Merged
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
15 changes: 15 additions & 0 deletions src/O2NextGen-Prototypes.sln
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "teambrain", "teambrain", "{
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "a-discount", "a-discount", "{41ECEE68-B668-45CB-A3F0-DAC0BCF20D89}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "O2NextGen.SmallTalk.SignalrHub", "Services\smalltalk\O2NextGen.SmallTalk.SignalrHub\O2NextGen.SmallTalk.SignalrHub.csproj", "{C4AE66A7-2DC5-410C-B17C-9A23DBD0A429}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -493,6 +495,18 @@ Global
{9D65077A-687A-433A-A280-45A70620ADC0}.Release|x64.Build.0 = Release|Any CPU
{9D65077A-687A-433A-A280-45A70620ADC0}.Release|x86.ActiveCfg = Release|Any CPU
{9D65077A-687A-433A-A280-45A70620ADC0}.Release|x86.Build.0 = Release|Any CPU
{C4AE66A7-2DC5-410C-B17C-9A23DBD0A429}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C4AE66A7-2DC5-410C-B17C-9A23DBD0A429}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C4AE66A7-2DC5-410C-B17C-9A23DBD0A429}.Debug|x64.ActiveCfg = Debug|Any CPU
{C4AE66A7-2DC5-410C-B17C-9A23DBD0A429}.Debug|x64.Build.0 = Debug|Any CPU
{C4AE66A7-2DC5-410C-B17C-9A23DBD0A429}.Debug|x86.ActiveCfg = Debug|Any CPU
{C4AE66A7-2DC5-410C-B17C-9A23DBD0A429}.Debug|x86.Build.0 = Debug|Any CPU
{C4AE66A7-2DC5-410C-B17C-9A23DBD0A429}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C4AE66A7-2DC5-410C-B17C-9A23DBD0A429}.Release|Any CPU.Build.0 = Release|Any CPU
{C4AE66A7-2DC5-410C-B17C-9A23DBD0A429}.Release|x64.ActiveCfg = Release|Any CPU
{C4AE66A7-2DC5-410C-B17C-9A23DBD0A429}.Release|x64.Build.0 = Release|Any CPU
{C4AE66A7-2DC5-410C-B17C-9A23DBD0A429}.Release|x86.ActiveCfg = Release|Any CPU
{C4AE66A7-2DC5-410C-B17C-9A23DBD0A429}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -543,6 +557,7 @@ Global
{A50DA91B-BD5D-4640-80D8-46B1E55E76FD} = {574CE1BF-397E-4262-82AD-94FB1CE98DA2}
{4BAA467F-6F58-4C99-ACCF-88F2ADD398B8} = {574CE1BF-397E-4262-82AD-94FB1CE98DA2}
{41ECEE68-B668-45CB-A3F0-DAC0BCF20D89} = {574CE1BF-397E-4262-82AD-94FB1CE98DA2}
{C4AE66A7-2DC5-410C-B17C-9A23DBD0A429} = {0DB9F20A-FD40-4110-807E-AAEFEFCCD574}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5C9AF9F4-BF0A-486D-9F2E-17FE2F53F7E9}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.UI.Services;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using O2NextGen.Auth.Web.Data;
using O2NextGen.Auth.Web.Helpers;
using O2NextGen.Auth.Web.Utilities;

namespace O2NextGen.Auth.Web.Extensions
{
Expand All @@ -19,6 +15,7 @@ public static IServiceCollection AddConfiguredIdentity(this IServiceCollection s
options.UseSqlServer(configuration["ConnectionString"]));

services

.AddIdentity<O2User, IdentityRole>(options =>
{
options.Password.RequireDigit = false;
Expand All @@ -27,14 +24,14 @@ public static IServiceCollection AddConfiguredIdentity(this IServiceCollection s
options.Password.RequireLowercase = false;
options.Password.RequireUppercase = false;
options.Password.RequireNonAlphanumeric = false;
options.User.RequireUniqueEmail = true;
// options.SignIn.RequireConfirmedEmail = true;
})
.AddEntityFrameworkStores<AuthDbContext>()
.AddDefaultTokenProviders();

services.AddSingleton<IEmailSender, DummyEmailSender>();
services.AddSingleton<IBase64QrCodeGenerator, Base64QrCodeGenerator>();


services.AddConfiguredIdentityServer(configuration);

return services;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,30 @@
using System.Linq;
using IdentityServer4;
using IdentityServer4.Models;
using Microsoft.AspNetCore.Hosting;
using IdentityServer4.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Hosting;
using O2NextGen.Auth.Web.Data;
using O2NextGen.Auth.Web.Services;

namespace O2NextGen.Auth.Web.Extensions
{
public static class IdentityServerExtensions
{
public static IServiceCollection AddConfiguredIdentityServer(this IServiceCollection services,
IHostingEnvironment environment, IConfiguration configuration)
IConfiguration configuration)
{
var builder = services.AddIdentityServer(options =>
{
options.Events.RaiseErrorEvents = true;
options.Events.RaiseInformationEvents = true;
options.Events.RaiseFailureEvents = true;
options.Events.RaiseSuccessEvents = true;
// options.Events.RaiseErrorEvents = true;
// options.Events.RaiseInformationEvents = true;
// options.Events.RaiseFailureEvents = true;
// options.Events.RaiseSuccessEvents = true;
})
// using in memory, but we could also get it, for example, from the database

.AddDeveloperSigningCredential()
.AddInMemoryPersistedGrants()
// access to data regarding the user's identity
.AddInMemoryIdentityResources(GetIdentityResources())
// APIs that may be accessed
Expand All @@ -32,16 +34,17 @@ public static IServiceCollection AddConfiguredIdentityServer(this IServiceCollec
.AddInMemoryClients(GetClients())
// configures IdentityServer integration with ASP.NET Core Identity
.AddAspNetIdentity<O2User>()

// to avoid bombarding the db with checks, make use of cache
.AddInMemoryCaching();
//.AddInMemoryCaching();
// more about EF integration:
// - http://docs.identityserver.io/en/latest/quickstarts/7_entity_framework.html
// - http://docs.identityserver.io/en/latest/reference/ef.html?highlight=dbcontext


.Services.AddTransient<IProfileService, ProfileService>();
return services;
}

private static IEnumerable<IdentityResource> GetIdentityResources()
{
var profile = new IdentityResources.Profile();
Expand All @@ -52,40 +55,105 @@ private static IEnumerable<IdentityResource> GetIdentityResources()
profile
};
}

private static IEnumerable<ApiResource> GetApis()
{
var apiResource = new ApiResource("GroupManagement", "Group Management");
apiResource.Scopes.First().Required = true;
return new[]

// private static IEnumerable<ApiResource> GetApis()
// {
// var apiResource = new ApiResource("smalltalkapi", "smalltalkapi");
// apiResource.Scopes.First().Required = true;
// return new[]
// {
// apiResource
// };
// }
public static IEnumerable<ApiResource> GetApis() =>
new List<ApiResource>
{
apiResource
new ApiResource("smalltalkapi", "SmallTalk API"),
new ApiResource("smalltalksignalr","SmallTalk SignalR")
};
}

private static IEnumerable<Client> GetClients()
{
return new[]
{
// React client
new Client
{
ClientId = "WebFrontend",
AllowedGrantTypes = GrantTypes.Code,
ClientSecrets = {new Secret("secret".Sha256())},
RedirectUris = new[] {"https://localhost:1001/signin-oidc"},
RefreshTokenUsage = TokenUsage.OneTimeOnly,
AllowedScopes =
ClientId = "smalltalk_client_reactjs",
ClientName = "SmallTalk React App",

AllowedGrantTypes = GrantTypes.Implicit,

RequireClientSecret = false,

RedirectUris =
{"http://localhost:3003/signin-oidc",
},


AllowedScopes = new List<string>
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
"GroupManagement",
IdentityServerConstants.StandardScopes.OfflineAccess
"smalltalkapi",
"smalltalksignalr",
},

AllowAccessTokensViaBrowser = true,
AlwaysIncludeUserClaimsInIdToken = true,
RequireConsent = false
},
new Client
{
ClientId = "smalltalkapi",
ClientName = "Smalltalkapi Swagger UI",
AllowedGrantTypes = GrantTypes.Implicit,
AllowAccessTokensViaBrowser = true,

RedirectUris = { $"http://localhost:5003/swagger/o2c.html" },
Copy link
Copy Markdown
Collaborator

@AlbusaOxyuranus AlbusaOxyuranus May 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to move it to appsettings.json

PostLogoutRedirectUris = { $"http://localhost:5003/swagger/" },

AllowedScopes = new List<string>
{
"smalltalkapi"
}
},
new Client {
ClientId = "o2business-wpf",

AllowedGrantTypes = GrantTypes.Code,
RequirePkce = true,
RequireClientSecret = false,

RedirectUris = { "http://localhost/sample-wpf-app" },
AllowedCorsOrigins = { "http://localhost" },

AllowedScopes = {
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
},

AllowAccessTokensViaBrowser = true,
RequireConsent = false,
},
new Client {
ClientId = "xamarin",

AllowedGrantTypes = GrantTypes.Code,
RequirePkce = true,
RequireClientSecret = false,

RedirectUris = { "xamarinformsclients://callback" },

AllowedScopes = {
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
},
AllowOfflineAccess = true,
AccessTokenLifetime = 60,
RefreshTokenExpiration = TokenExpiration.Sliding,
//RequireConsent = false
}

AllowAccessTokensViaBrowser = true,
RequireConsent = false,
},

};
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/Services/auth/O2NextGen.Auth.Web/Pages/Register.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
Expand Down Expand Up @@ -83,9 +84,10 @@ public async Task<IActionResult> OnPostAsync(string returnUrl = null)
pageHandler: null,
values: new { userId = user.Id, code = code },
protocol: Request.Scheme);

await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

Console.WriteLine(HtmlEncoder.Default.Encode(callbackUrl));
//await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to uncomment it

// $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

await _signInManager.SignInAsync(user, isPersistent: false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:10001;http://localhost:5001"
"applicationUrl": "http://localhost:5001"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to revert line

},
"Docker": {
"commandName": "Docker",
Expand Down
Loading