Skip to content
Open
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
20 changes: 16 additions & 4 deletions IdentityServer4-AspNetCore-Claim/ApiResource/ApiResource.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand All @@ -12,8 +12,20 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="2.6.0" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.5" />
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.1.8" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.8" PrivateAssets="all" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.8" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="2.0.0-preview1-final" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.8" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.8" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.2.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand Down
15 changes: 9 additions & 6 deletions IdentityServer4-AspNetCore-Claim/ApiResource/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,27 @@ public Startup(IConfiguration configuration)
public void ConfigureServices(IServiceCollection services)
{
services.AddMvcCore()
.AddAuthorization(options => options.AddPolicy("Founder", policy => policy.RequireClaim("Employee", "Mosalla")))
.AddJsonFormatters();
.AddAuthorization(options => options.AddPolicy("Founder", policy => policy.RequireClaim("Employee", "Mosalla")));

services.AddAuthentication("Bearer")
.AddIdentityServerAuthentication(options =>
{
options.Authority = "http://localhost:5000";
options.RequireHttpsMetadata = false;
options.Authority = "https://localhost:44384/";
options.RequireHttpsMetadata = true;
options.ApiName = "Api1";
});
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();

app.UseAuthentication();

app.UseMvc();
app.UseAuthorization();

app.UseEndpoints(routes => routes.MapDefaultControllerRoute());
}
}
}
80 changes: 37 additions & 43 deletions IdentityServer4-AspNetCore-Claim/AspNetCoreIdentityServer.sln
Original file line number Diff line number Diff line change
@@ -1,43 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2020
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCoreIdentityServer", "AspNetCoreIdentityServer\AspNetCoreIdentityServer.csproj", "{BA3B956B-D51C-485E-A80B-0D6623975DFA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiResource", "ApiResource\ApiResource.csproj", "{DBA87F35-EC86-459A-8A8D-74427F61A9DB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MvcClient", "MvcClient\MvcClient.csproj", "{4AF34743-BA5A-4396-9AE8-8E3717522560}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MvcClient2", "MvcClient2\MvcClient2.csproj", "{C60B8205-772D-43A1-9A12-9B9121F36BAA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BA3B956B-D51C-485E-A80B-0D6623975DFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BA3B956B-D51C-485E-A80B-0D6623975DFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BA3B956B-D51C-485E-A80B-0D6623975DFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BA3B956B-D51C-485E-A80B-0D6623975DFA}.Release|Any CPU.Build.0 = Release|Any CPU
{DBA87F35-EC86-459A-8A8D-74427F61A9DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DBA87F35-EC86-459A-8A8D-74427F61A9DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DBA87F35-EC86-459A-8A8D-74427F61A9DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DBA87F35-EC86-459A-8A8D-74427F61A9DB}.Release|Any CPU.Build.0 = Release|Any CPU
{4AF34743-BA5A-4396-9AE8-8E3717522560}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4AF34743-BA5A-4396-9AE8-8E3717522560}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4AF34743-BA5A-4396-9AE8-8E3717522560}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4AF34743-BA5A-4396-9AE8-8E3717522560}.Release|Any CPU.Build.0 = Release|Any CPU
{C60B8205-772D-43A1-9A12-9B9121F36BAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C60B8205-772D-43A1-9A12-9B9121F36BAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C60B8205-772D-43A1-9A12-9B9121F36BAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C60B8205-772D-43A1-9A12-9B9121F36BAA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4DB5543D-6407-47F3-855F-7C74374E4B12}
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30503.244
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCoreIdentityServer", "AspNetCoreIdentityServer\AspNetCoreIdentityServer.csproj", "{BA3B956B-D51C-485E-A80B-0D6623975DFA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiResource", "ApiResource\ApiResource.csproj", "{DBA87F35-EC86-459A-8A8D-74427F61A9DB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MvcClient", "MvcClient\MvcClient.csproj", "{4AF34743-BA5A-4396-9AE8-8E3717522560}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BA3B956B-D51C-485E-A80B-0D6623975DFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BA3B956B-D51C-485E-A80B-0D6623975DFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BA3B956B-D51C-485E-A80B-0D6623975DFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BA3B956B-D51C-485E-A80B-0D6623975DFA}.Release|Any CPU.Build.0 = Release|Any CPU
{DBA87F35-EC86-459A-8A8D-74427F61A9DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DBA87F35-EC86-459A-8A8D-74427F61A9DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DBA87F35-EC86-459A-8A8D-74427F61A9DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DBA87F35-EC86-459A-8A8D-74427F61A9DB}.Release|Any CPU.Build.0 = Release|Any CPU
{4AF34743-BA5A-4396-9AE8-8E3717522560}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4AF34743-BA5A-4396-9AE8-8E3717522560}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4AF34743-BA5A-4396-9AE8-8E3717522560}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4AF34743-BA5A-4396-9AE8-8E3717522560}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4DB5543D-6407-47F3-855F-7C74374E4B12}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UserSecretsId>aspnet-AspNetCoreIdentityServer-AFD4C82E-A3A7-4B45-BDA5-4EF3A9BE1DF0</UserSecretsId>
</PropertyGroup>


<ItemGroup>
<PackageReference Include="IdentityServer4.AspNetIdentity" Version="2.1.0" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.4" PrivateAssets="all">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.5" PrivateAssets="All" />
<PackageReference Include="IdentityServer4.AspNetIdentity" Version="4.0.4" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.1.8" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.8" PrivateAssets="all" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.8" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="2.0.0-preview1-final" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.8" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.7" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.8" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.2.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,38 @@ public static IEnumerable<ApiResource> GetApiResources()
{
return new List<ApiResource>
{
new ApiResource("Api1", "Protected Api")
new ApiResource
{
Name = "Api1",
DisplayName = "API #1",
Description = "Allow the application to access API #1 on your behalf",
Scopes = new List<string> {"Api1", "api1.write"},
ApiSecrets = new List<Secret> {new Secret("ScopeSecret".Sha256())},
UserClaims = new List<string> {"role"}
}
};
}

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

public static IEnumerable<ApiScope> GetApiScopes()
{
return new List<ApiScope>
{
new IdentityResources.OpenId(),
new IdentityResources.Profile(),
new ApiScope("Api1", "Read Access to API #1")
};
}

Expand All @@ -39,40 +61,14 @@ public static IEnumerable<Client> GetClients()
{
new Secret("secret".Sha256())
},

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

AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
"Api1"
},
AllowOfflineAccess = true,
AlwaysSendClientClaims = true,
AlwaysIncludeUserClaimsInIdToken = true
},
new Client
{
ClientId = "mvc2",
ClientName = "MVC Client",
AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,

RequireConsent = false,

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

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

// MvcClient
RedirectUris = {"https://localhost:44395/signin-oidc"},
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.Email,
"role",
"Api1"
},
AllowOfflineAccess = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public static void Main(string[] args)

public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureLogging(log =>
{
log.AddConsole();
})
.UseStartup<Startup>()
.Build();
}
Expand Down
Loading