Skip to content

Commit

Permalink
Add initial identity projects setup
Browse files Browse the repository at this point in the history
  • Loading branch information
amd-9 committed Jul 6, 2021
1 parent 4ce0121 commit cd60bf0
Show file tree
Hide file tree
Showing 258 changed files with 101,338 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

# Jetbrains Rider .idea folter
.idea/

# Sqlite database files
*.db

# User-specific files
*.rsuser
*.suo
Expand Down
37 changes: 37 additions & 0 deletions IdentitySPA.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31321.278
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityServer", "IdentityServer\IdentityServer.csproj", "{AD6BBF25-D09F-4414-AFCA-2C86CEB683B7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WeatherApi", "WeatherApi\WeatherApi.csproj", "{CE8550B6-63A5-4108-8CD8-739FE64FEAD0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WeatherMVC", "WeatherMVC\WeatherMVC.csproj", "{1E133DD9-FF3E-4719-B83E-97529DFE342F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AD6BBF25-D09F-4414-AFCA-2C86CEB683B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AD6BBF25-D09F-4414-AFCA-2C86CEB683B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD6BBF25-D09F-4414-AFCA-2C86CEB683B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AD6BBF25-D09F-4414-AFCA-2C86CEB683B7}.Release|Any CPU.Build.0 = Release|Any CPU
{CE8550B6-63A5-4108-8CD8-739FE64FEAD0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CE8550B6-63A5-4108-8CD8-739FE64FEAD0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CE8550B6-63A5-4108-8CD8-739FE64FEAD0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CE8550B6-63A5-4108-8CD8-739FE64FEAD0}.Release|Any CPU.Build.0 = Release|Any CPU
{1E133DD9-FF3E-4719-B83E-97529DFE342F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1E133DD9-FF3E-4719-B83E-97529DFE342F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1E133DD9-FF3E-4719-B83E-97529DFE342F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1E133DD9-FF3E-4719-B83E-97529DFE342F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {34F4CE00-0972-4E7A-9359-93FBD04EF649}
EndGlobalSection
EndGlobal
131 changes: 131 additions & 0 deletions IdentityServer/Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
using System.Collections.Generic;
using System.Security.Claims;
using System.Text.Json;
using IdentityModel;
using IdentityServer4;
using IdentityServer4.Models;
using IdentityServer4.Test;

namespace IdentityServer
{
public static class Config
{
public static List<TestUser> Users
{
get
{
var address = new
{
street_address = "One Hacker Way",
locality = "Heidelberg",
postal_code = 123456,
country = "Russia"
};


return new List<TestUser>
{
new TestUser
{
SubjectId = "818727",
Username = "developer",
Password = "developer",
Claims =
{
new Claim(JwtClaimTypes.Name, value: "Identity Developer"),
new Claim(JwtClaimTypes.GivenName, value: "Developer"),
new Claim(JwtClaimTypes.FamilyName, value: "Developer"),
new Claim(JwtClaimTypes.Email, value: "developer@identity.com"),
new Claim(JwtClaimTypes.EmailVerified, value: ClaimValueTypes.Boolean),
new Claim(JwtClaimTypes.Role, value: "admin"),
new Claim(JwtClaimTypes.WebSite, value: "http://developer.com"),
new Claim(JwtClaimTypes.Address, value: JsonSerializer.Serialize(address),
valueType: IdentityServerConstants.ClaimValueTypes.Json)
}
},
new TestUser
{
SubjectId = "88421113",
Username = "user",
Password = "user",
Claims =
{
new Claim(JwtClaimTypes.Name, value: "Identity User"),
new Claim(JwtClaimTypes.GivenName, value: "User"),
new Claim(JwtClaimTypes.FamilyName, value: "User"),
new Claim(JwtClaimTypes.Email, value: "User@identity.com"),
new Claim(JwtClaimTypes.EmailVerified, value: ClaimValueTypes.Boolean),
new Claim(JwtClaimTypes.Role, value: "User"),
new Claim(JwtClaimTypes.WebSite, value: "http://User.com"),
new Claim(JwtClaimTypes.Address, value: JsonSerializer.Serialize(address),
valueType: IdentityServerConstants.ClaimValueTypes.Json)
}
},
};
}
}

public static IEnumerable<IdentityResource> IdentityResources =>
new[]
{
new IdentityResources.OpenId(),
new IdentityResources.Profile(),
new IdentityResource
{
Name = "role",
UserClaims = new List<string> {"role"}
}
};

public static IEnumerable<ApiScope> ApiScopes => new[]
{
new ApiScope("weatherapi.read"),
new ApiScope("weatherapi.write"),
};

public static IEnumerable<ApiResource> ApiResources => new[]
{
new ApiResource("weatherapi")
{
Scopes = new List<string> { "weatherapi.read", "weatherapi.write"},
ApiSecrets = new List<Secret> {new Secret("ScopeSecret".Sha256())},
UserClaims = new List<string> {"role"}
}
};

public static IEnumerable<Client> Clients
{
get
{
return new List<Client>
{
// machine to machine (m2m) client
new Client
{
ClientId = "m2m.client",
ClientName = "Client Credentials Client",

AllowedGrantTypes = GrantTypes.ClientCredentials,
ClientSecrets = { new Secret("SuperPassword".Sha256())},

AllowedScopes = {"weatherapi.read", "weatherapi.write"}
},
new Client
{
ClientId = "interactive",
ClientSecrets = { new Secret("SuperPassword".Sha256())},

AllowedGrantTypes = GrantTypes.Code,

RedirectUris = {"https://localhost:5444/signin-oidc"},
FrontChannelLogoutUri = "https://localhost:5444/signout-oidc",
PostLogoutRedirectUris = {"http://localhost:5444/signout-callback-oidc"},

AllowOfflineAccess = true,
AllowedScopes = {"openid","profile","weatherapi.read"}
}
};
}
}
}
}
17 changes: 17 additions & 0 deletions IdentityServer/Data/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace IdentityServer.Data
{
public class ApplicationDbContext : IdentityDbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
}
}
21 changes: 21 additions & 0 deletions IdentityServer/IdentityServer.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="IdentityServer4" Version="4.1.2" />
<PackageReference Include="IdentityServer4.AspNetIdentity" Version="4.1.2" />
<PackageReference Include="IdentityServer4.EntityFramework" Version="4.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="5.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
</ItemGroup>

</Project>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cd60bf0

Please sign in to comment.