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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
bin/
obj/
.idea/
backup/


*.user

src/IdentityServer4\.Mock/\.vs/
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,33 @@
# IdentityServer4.Mock
Mock Identity Server for Integration testing

## Usage

#### Creating a mock identity server

```cs
var identityServer = MockIdentityServer.Configure(c => {
c.AddApiResources(new ApiResource() {
Name = "testscope",
Scopes = new[] {new Scope("testscope")},
ApiSecrets = new[] {new Secret("apisecret".Sha256())}
})
.AddClients(new Client() {
ClientId = "testclient",
ClientSecrets = new[] {new Secret("clientsecret".Sha256())},
AllowedGrantTypes = GrantTypes.ClientCredentials,
AllowedScopes = new[] {"testscope"}
});
}).Start();
```

#### Authenticating a client

```cs
var proxyHandler = identityServer.CreateHandler();
var discoClient = new DiscoveryClient(identityServer.BaseAddress.ToString(), proxyHandler);
var disco = await discoClient.GetAsync();

var tokenClient = new TokenClient(disco.TokenEndpoint, "testclient","clientsecret", proxyHandler);
var tokenResponse = await tokenClient.RequestClientCredentialsAsync("testscope");
```
6 changes: 0 additions & 6 deletions global.json

This file was deleted.

4 changes: 2 additions & 2 deletions src/IdentityServer4.Mock/IMockIdentityServerConfig.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using IdentityServer4.Models;
using IdentityServer4.Services.InMemory;
using IdentityServer4.Test;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
Expand All @@ -15,7 +15,7 @@ public interface IMockIdentityServerConfig

IMockIdentityServerConfig AddApiResources(params ApiResource[] apiResources);

IMockIdentityServerConfig AddUsers(params InMemoryUser[] users);
IMockIdentityServerConfig AddUsers(params TestUser[] users);

IMockIdentityServerConfig Configure(Action<IApplicationBuilder> appCfg);

Expand Down
14 changes: 14 additions & 0 deletions src/IdentityServer4.Mock/IdentityServer4.Mock.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<DebugType>portable</DebugType>
<AssemblyName>IdentityServer4.Mock</AssemblyName>
<PackageId>IdentityServer4.Mock</PackageId>
<Version>2.0.0</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="IdentityServer4" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.0.1" />
</ItemGroup>
</Project>
22 changes: 22 additions & 0 deletions src/IdentityServer4.Mock/IdentityServer4.Mock.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdentityServer4.Mock", "IdentityServer4.Mock.csproj", "{56296462-9857-490E-B431-597ACFD07755}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdentityServer4.Mock.Tests", "..\..\test\IdentityServer4.Mock.Tests\IdentityServer4.Mock.Tests.csproj", "{F2E900F8-CE93-4AFA-8924-A534CD413A2E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{56296462-9857-490E-B431-597ACFD07755}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{56296462-9857-490E-B431-597ACFD07755}.Debug|Any CPU.Build.0 = Debug|Any CPU
{56296462-9857-490E-B431-597ACFD07755}.Release|Any CPU.ActiveCfg = Release|Any CPU
{56296462-9857-490E-B431-597ACFD07755}.Release|Any CPU.Build.0 = Release|Any CPU
{F2E900F8-CE93-4AFA-8924-A534CD413A2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F2E900F8-CE93-4AFA-8924-A534CD413A2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F2E900F8-CE93-4AFA-8924-A534CD413A2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F2E900F8-CE93-4AFA-8924-A534CD413A2E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
6 changes: 3 additions & 3 deletions src/IdentityServer4.Mock/MockIdentityServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static IStartIdentityServer Configure(Action<IMockIdentityServerConfig> c
cfg.AppConfig(app);
if(cfg.UseRequestLogging)
{
app.ApplicationServices.GetRequiredService<ILoggerFactory>().AddConsole();
app.ApplicationServices.GetRequiredService<ILoggingBuilder>().AddConsole();
}
}).ConfigureServices(s => {
var idServerCfg = s.AddIdentityServer();
Expand All @@ -45,7 +45,7 @@ public static IStartIdentityServer Configure(Action<IMockIdentityServerConfig> c
.AddInMemoryClients(cfg.Clients)
.AddInMemoryIdentityResources(cfg.IdentityResources)
.AddInMemoryApiResources(cfg.ApiResources)
.AddInMemoryUsers(cfg.Users.ToList())
.AddTestUsers(cfg.Users.ToList())
//.AddTemporarySigningCredential()
.AddDefaultSecretParsers()
.AddDefaultSecretValidators()
Expand All @@ -56,7 +56,7 @@ public static IStartIdentityServer Configure(Action<IMockIdentityServerConfig> c
}
else
{
idServerCfg.AddTemporarySigningCredential();
idServerCfg.AddDeveloperSigningCredential();
}
cfg.ServiceConfig(s);
}));
Expand Down
6 changes: 3 additions & 3 deletions src/IdentityServer4.Mock/MockIdentityServerConfig.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using IdentityServer4.Models;
using IdentityServer4.Services.InMemory;
using IdentityServer4.Test;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
Expand Down Expand Up @@ -28,7 +28,7 @@ public IMockIdentityServerConfig AddApiResources(params ApiResource[] apiResourc
}


public IMockIdentityServerConfig AddUsers(params InMemoryUser[] users)
public IMockIdentityServerConfig AddUsers(params TestUser[] users)
{
Users = users;
return this;
Expand Down Expand Up @@ -66,7 +66,7 @@ public IMockIdentityServerConfig AddSigningCredential(SigningCredentials credent
internal ApiResource[] ApiResources { get; private set; }= new ApiResource[]{};

internal IdentityResource[] IdentityResources { get; private set; }= new IdentityResource[]{};
internal InMemoryUser[] Users { get; private set; }= new InMemoryUser[]{};
internal TestUser[] Users { get; private set; }= new TestUser[]{};

internal Action<IApplicationBuilder> AppConfig { get; private set; } = _ => {};

Expand Down
14 changes: 0 additions & 14 deletions src/IdentityServer4.Mock/project.json

This file was deleted.

Loading