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

Feature/update to duende #78

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
3 changes: 2 additions & 1 deletion Api.Client/Api.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Moq" Version="4.18.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Linq;
using System.Threading.Tasks;
using IdentityServer4.Extensions;
using IdentityServer4.Models;
using IdentityServer4.Services;
using Duende.IdentityServer.Extensions;
using Duende.IdentityServer.Models;
using Duende.IdentityServer.Services;
using IdentityServer.LdapExtension.UserModel;
using IdentityServer.LdapExtension.UserStore;
using Microsoft.Extensions.Logging;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Threading.Tasks;
using Duende.IdentityServer.Validation;
using IdentityModel;
using IdentityServer4.Validation;
using IdentityServer.LdapExtension.UserModel;
using IdentityServer.LdapExtension.UserStore;
using Microsoft.AspNetCore.Authentication;
Expand Down
14 changes: 8 additions & 6 deletions IdentityServer.LdapExtension/IdentityServer.LdapExtension.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0;netcoreapp3.1</TargetFrameworks>
<TargetFramework>net6.0</TargetFramework>
<Authors>Nordès Ménard-Lamarre</Authors>
<Version>2.1.14</Version>
<Company>HoNoSoFt</Company>
<Description>Extension for IdentityServer 4 in order to use LDAP as a plugin. It is also extensible enough in order to use custom LDAP schema such as OpenLdap or Active Directory.</Description>
<Description>Extension for Duende IdentityServer in order to use LDAP as a plugin. It is also extensible enough in order to use custom LDAP schema such as OpenLdap or Active Directory.</Description>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
Expand All @@ -16,17 +16,19 @@
<PackageIconUrl>https://www.honosoft.com/img/logo.png</PackageIconUrl>
<Copyright>Nordès Ménard-Lamarre</Copyright>
<RepositoryUrl>https://github.com/Nordes/IdentityServer4.LdapExtension/</RepositoryUrl>
<PackageTags>IdentityServer4, Ldap, OpenLdap, ActiveDirectory</PackageTags>
<PackageTags>IdentityServer4, Ldap, OpenLdap, ActiveDirectory, Duende, IdentityServer</PackageTags>
<IncludeSymbols>true</IncludeSymbols>
<IncludeSource>true</IncludeSource>
<NeutralLanguage />
<LangVersion>latest</LangVersion>
<PackageVersion>4.1.0</PackageVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="IdentityModel" Version="5.1.0" />
<PackageReference Include="IdentityServer4" Version="4.1.2" />
<PackageReference Include="IdentityModel" Version="6.0.0" />
<PackageReference Include="Duende.IdentityServer" Version="6.1.7" />
<PackageReference Include="Novell.Directory.Ldap.NETStandard" Version="3.6.0" />
<PackageReference Include="StackExchange.Redis" Version="2.2.4" />
<PackageReference Include="StackExchange.Redis" Version="2.6.70" />
</ItemGroup>

</Project>
12 changes: 6 additions & 6 deletions IdentityServer.LdapExtension/LdapUserProfileService.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using IdentityServer.LdapExtension.UserStore;
using IdentityServer4.Extensions;
using IdentityServer4.Models;
using IdentityServer4.Services;
using Microsoft.Extensions.Logging;
using System.Linq;
using System.Linq;
using System.Threading.Tasks;
using IdentityServer.LdapExtension.UserStore;
using Microsoft.Extensions.Logging;
using Duende.IdentityServer.Extensions;
using Duende.IdentityServer.Models;
using Duende.IdentityServer.Services;

namespace IdentityServer.LdapExtension
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System.Threading.Tasks;
using IdentityServer4.Events;
using IdentityServer4.Services;
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using Duende.IdentityServer.Events;
using Duende.IdentityServer.Services;

namespace IdentityServer.LdapExtension
{
Expand All @@ -24,15 +23,7 @@ public Task PersistAsync(Event evt)
{
if (evt == null) throw new ArgumentNullException(nameof(evt));

var json = JsonConvert.SerializeObject(evt);
_log.LogInformation(json);

return Task.CompletedTask;
// Not working at the moment. In the doc it says to register the DI, but it still not work.
_log.LogDebug(evt.EventType.ToString());
_log.LogDebug(evt.Id.ToString());
_log.LogDebug(evt.Name);
_log.LogDebug(evt.Message);
_log.LogInformation("Event details: {@Event}", evt);

return Task.CompletedTask;
}
Expand Down
5 changes: 2 additions & 3 deletions IdentityServer.LdapExtension/UserStore/InMemoryUserStore.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using IdentityModel;
using System.Collections.Generic;
using IdentityModel;
using IdentityServer.LdapExtension.Exceptions;
using IdentityServer.LdapExtension.UserModel;
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Security.Claims;
Expand Down
22 changes: 8 additions & 14 deletions IdentityServer.LdapExtension/UserStore/RedisUserStore.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using IdentityModel;
using System;
using System.Collections.Generic;
using IdentityModel;
using IdentityServer.LdapExtension.UserModel;
using IdentityServer4.Stores.Serialization;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Security.Claims;
using System.Text.Json;

namespace IdentityServer.LdapExtension.UserStore
{
Expand All @@ -27,11 +26,6 @@ public class RedisUserStore<TUser> : ILdapUserStore
private readonly ILdapService<TUser> _authenticationService;
private readonly ILogger<RedisUserStore<TUser>> _logger;
private IConnectionMultiplexer _redis;
private readonly JsonSerializerSettings _jsonSerializerSettings = new JsonSerializerSettings
{
Converters = new List<JsonConverter> { new ClaimConverter() },
Formatting = Formatting.Indented
};

private TimeSpan _dataExpireIn;

Expand Down Expand Up @@ -143,7 +137,7 @@ public IAppUser FindBySubjectId(string subjectId)
if (result.HasValue)
{
// IMPORTANT! This line might throw an exception if we change the format/version
IAppUser foundSubjectId = JsonConvert.DeserializeObject<TUser>(result.ToString(), _jsonSerializerSettings);
IAppUser foundSubjectId = JsonSerializer.Deserialize<TUser>(result.ToString());

return foundSubjectId;
}
Expand Down Expand Up @@ -178,7 +172,7 @@ public IAppUser FindByUsername(string username)
if (subject.HasValue)
{
// IMPORTANT! This line might throw an exception if we change the format/version
IAppUser foundSubjectId = JsonConvert.DeserializeObject<TUser>(subject.ToString(), _jsonSerializerSettings);
IAppUser foundSubjectId = JsonSerializer.Deserialize<TUser>(subject.ToString());

return foundSubjectId;
}
Expand Down Expand Up @@ -217,7 +211,7 @@ public IAppUser FindByExternalProvider(string provider, string userId)
if (subject.HasValue)
{
// IMPORTANT! This line might throw an exception if we change the format/version
IAppUser foundSubjectId = JsonConvert.DeserializeObject<TUser>(subject.ToString(), _jsonSerializerSettings);
IAppUser foundSubjectId = JsonSerializer.Deserialize<TUser>(subject.ToString());

return foundSubjectId;
}
Expand Down Expand Up @@ -306,7 +300,7 @@ private void SetRedisData(IAppUser user)
const string keyByUsername = "IdentityServer/OpenId/username/{0}"; // <== contains a link to the SubjectId
const string keyByProviderAndUserid = "IdentityServer/OpenId/provider/{0}/userId/{1}"; // <== contains a link to the SubjectId

var userStr = JsonConvert.SerializeObject(user, _jsonSerializerSettings);
var userStr = JsonSerializer.Serialize(user);
var subjectIdStorageKey = string.Format(keyBySubjectId, user.SubjectId);

// add user to Redis store
Expand Down
3 changes: 2 additions & 1 deletion MvcVueClient/MvcVueClient.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.5" />
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
[![Build status](https://ci.appveyor.com/api/projects/status/k26pepb32vka29w2/branch/master?svg=true)](https://ci.appveyor.com/project/Nordes/identityserver4-ldapextension/branch/master)
[![NuGet](https://img.shields.io/nuget/v/IdentityServer.LdapExtension.svg)](https://www.nuget.org/packages/IdentityServer.LdapExtension/)

- [IdentityServer4.LdapExtension](#identityserver4ldapextension)
- [IdentityServer.LdapExtension](#identityserverldapextension)
- [Installation](#installation)
- [Configuration for IdentityServer4 Server](#configuration-for-identityserver4-server)
- [Configuration for IdentityServer Server](#configuration-for-identityserver-server)
- [AppSettings Configuration](#appsettings-configuration)
- [Multiple concurent Ldap (For different DN, or totally different Ldap)](#multiple-concurent-ldap-for-different-dn-or-totally-different-ldap)
- [Quick and Simple Example of a Configuration](#quick-and-simple-example-of-a-configuration)
Expand All @@ -14,11 +14,11 @@
- [Special thanks to](#special-thanks-to)
- [License](#license)

# IdentityServer4.LdapExtension
IdentityServer4 Ldap Extension ([OpenLdap](https://www.openldap.org/) or [ActiveDirectory](https://en.wikipedia.org/wiki/Active_Directory)).
# IdentityServer.LdapExtension
IdentityServer Ldap Extension ([OpenLdap](https://www.openldap.org/) or [ActiveDirectory](https://en.wikipedia.org/wiki/Active_Directory)).

## Installation
The plugin is easy to install to your solution. Built using **.Net Core 3.1** and **.Net 5.0**. The Nuget package can be installed by either searching the package `IdentityServer.LdapExtension` or by typing the following command in your package console:
The plugin is easy to install to your solution. Built using **.Net 6.0**. The Nuget package can be installed by either searching the package `IdentityServer.LdapExtension` or by typing the following command in your package console:

```csharp
Install-Package IdentityServer.LdapExtension
Expand All @@ -29,8 +29,9 @@ Install-Package IdentityServer.LdapExtension
> - Ldap Extension 2.1.7 goes with IdentityServer 2.3.x
> - Ldap Extension 2.1.8 goes with IdentityServer 2.4.x
> - Ldap Extension 3.1.0 goes with IdentityServer 4.1.2
> - Ldap Extension 4.1.0 goes with Duende IdentityServer 6.1.7

## Configuration for IdentityServer4 Server
## Configuration for IdentityServer Server
An easy extension method have been created in order to add the LDAP as a provider to your IdentityServer. For this you simply have to use the `AddLdapUsers<TApplicationUser>(LdapConfigSection, StoreTypeOrCustomStore)`. The configuration has to be provided or it won't work. The configuration is described [here](#appsettings-configuration).

In the `Startup.cs` under `ConfigureServices` method, you will have something similar to the following by default (Starter pack for IdentityServer). The last line is what you will need to add in order to get started.
Expand Down
5 changes: 3 additions & 2 deletions Sample/Api/Api.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.10" />
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion Sample/Client/MvcClient.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions Sample/IdentityServer/Config.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using IdentityServer4;
using IdentityServer4.Models;
using System.Collections.Generic;
using System.Collections.Generic;
using Duende.IdentityServer;
using Duende.IdentityServer.Models;

namespace QuickstartIdentityServer412
{
Expand Down
2 changes: 1 addition & 1 deletion Sample/IdentityServer/Configuration/Clients.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.


using IdentityServer4.Models;
using System.Collections.Generic;
using Duende.IdentityServer.Models;

namespace IdentityServerHost.Configuration
{
Expand Down
4 changes: 2 additions & 2 deletions Sample/IdentityServer/Configuration/ClientsConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@


using System.Collections.Generic;
using IdentityServer4;
using IdentityServer4.Models;
using Duende.IdentityServer;
using Duende.IdentityServer.Models;

namespace IdentityServerHost.Configuration
{
Expand Down
4 changes: 2 additions & 2 deletions Sample/IdentityServer/Configuration/ClientsWeb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.using System.Collections.Generic;

using System.Collections.Generic;
using IdentityServer4;
using IdentityServer4.Models;
using Duende.IdentityServer;
using Duende.IdentityServer.Models;

namespace IdentityServerHost.Configuration
{
Expand Down
8 changes: 4 additions & 4 deletions Sample/IdentityServer/Configuration/Resources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.


using IdentityModel;
using IdentityServer4.Models;
using System.Collections.Generic;
using static IdentityServer4.IdentityServerConstants;
using IdentityModel;
using Duende.IdentityServer;
using Duende.IdentityServer.Models;

namespace IdentityServerHost.Configuration
{
Expand All @@ -29,7 +29,7 @@ public class Resources
new[]
{
// local API scope
new ApiScope(LocalApi.ScopeName),
new ApiScope(IdentityServerConstants.LocalApi.ScopeName),

// resource specific scopes
new ApiScope("resource1.scope1"),
Expand Down
4 changes: 2 additions & 2 deletions Sample/IdentityServer/Extensions/ExtensionGrantValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.


using IdentityServer4.Models;
using IdentityServer4.Validation;
using System.Threading.Tasks;
using Duende.IdentityServer.Models;
using Duende.IdentityServer.Validation;

namespace IdentityServerHost.Extensions
{
Expand Down
6 changes: 3 additions & 3 deletions Sample/IdentityServer/Extensions/HostProfileService.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using IdentityServer.LdapExtension;
using IdentityServer.LdapExtension.UserStore;
using IdentityServer4.Models;
using Duende.IdentityServer.Models;
using IdentityServer.LdapExtension;
using IdentityServer.LdapExtension.UserStore;
using Microsoft.Extensions.Logging;

namespace IdentityServerHost.Extensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.


using IdentityServer4.Models;
using IdentityServer4.Validation;
using System.Threading.Tasks;
using Duende.IdentityServer.Models;
using Duende.IdentityServer.Validation;

namespace IdentityServerHost.Extensions
{
Expand Down
Loading