Permalink
Browse files

Migrated from Thinktecture.IdentityServer3 packages to IdentityServer…

…3 packages. Updated usings. Persisted client AllowedScopes.
  • Loading branch information...
edgecastle committed Jan 23, 2016
1 parent 897c241 commit 8864806c78d3be6336677cbe28c3137e3d8d7ea5
Showing with 115 additions and 98 deletions.
  1. +4 −4 Edgecastle.IdentityServer3.Neo4j.Tests/Edgecastle.IdentityServer3.Neo4j.Tests.csproj
  2. +1 −1 Edgecastle.IdentityServer3.Neo4j.Tests/packages.config
  3. +6 −5 Edgecastle.IdentityServer3.Neo4j/Edgecastle.IdentityServer3.Neo4j.csproj
  4. +1 −1 Edgecastle.IdentityServer3.Neo4j/Interfaces/IClientAdminService.cs
  5. +1 −1 Edgecastle.IdentityServer3.Neo4j/Interfaces/IScopeAdminService.cs
  6. +1 −1 Edgecastle.IdentityServer3.Neo4j/Interfaces/IUserAdminService.cs
  7. +1 −1 Edgecastle.IdentityServer3.Neo4j/Models/Claim.cs
  8. +1 −1 Edgecastle.IdentityServer3.Neo4j/Models/ClientAdminResult.cs
  9. +6 −6 Edgecastle.IdentityServer3.Neo4j/Models/Scope.cs
  10. +6 −5 Edgecastle.IdentityServer3.Neo4j/Neo4jClientStore.cs
  11. +3 −3 Edgecastle.IdentityServer3.Neo4j/Neo4jScopeStore.cs
  12. +2 −2 Edgecastle.IdentityServer3.Neo4j/Neo4jServiceFactory.cs
  13. +47 −43 Edgecastle.IdentityServer3.Neo4j/Neo4jUsersService.cs
  14. +1 −1 Edgecastle.IdentityServer3.Neo4j/PrincipalHelper.cs
  15. +2 −2 Edgecastle.IdentityServer3.Neo4j/Properties/AssemblyInfo.cs
  16. +1 −1 Edgecastle.IdentityServer3.Neo4j/packages.config
  17. +3 −3 Samples/IdentityServer3Neo4J.Samples.MVC/Controllers/SetupController.cs
  18. +14 −6 Samples/IdentityServer3Neo4J.Samples.MVC/IdentityServer3Neo4J.Samples.MVC.csproj
  19. +11 −9 Samples/IdentityServer3Neo4J.Samples.MVC/Startup.cs
  20. +1 −1 Samples/IdentityServer3Neo4J.Samples.MVC/Web.config
  21. +2 −1 Samples/IdentityServer3Neo4J.Samples.MVC/packages.config
@@ -35,15 +35,15 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="IdentityServer3, Version=2.3.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\IdentityServer3.2.3.0\lib\net45\IdentityServer3.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="Thinktecture.IdentityServer3, Version=1.6.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Thinktecture.IdentityServer3.1.6.2\lib\net45\Thinktecture.IdentityServer3.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="IdentityServer3" version="2.3.0" targetFramework="net46" />
<package id="Owin" version="1.0" targetFramework="net46" />
<package id="Thinktecture.IdentityServer3" version="1.6.2" targetFramework="net46" />
</packages>
@@ -9,8 +9,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Edgecastle.IdentityServer3.Neo4j</RootNamespace>
<AssemblyName>Edgecastle.IdentityServer3.Neo4j</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -42,6 +43,10 @@
<HintPath>..\packages\BrockAllen.MembershipReboot.8.4.0\lib\net45\BrockAllen.MembershipReboot.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="IdentityServer3, Version=2.3.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\IdentityServer3.2.3.0\lib\net45\IdentityServer3.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Neo4jClient, Version=1.0.0.662, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Neo4jClient.1.0.0.662\lib\net40\Neo4jClient.dll</HintPath>
<Private>True</Private>
@@ -75,10 +80,6 @@
<HintPath>..\packages\Thinktecture.IdentityModel.Core.1.4.0\lib\net45\Thinktecture.IdentityModel.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Thinktecture.IdentityServer3, Version=1.6.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Thinktecture.IdentityServer3.1.6.2\lib\net45\Thinktecture.IdentityServer3.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Configuration.cs" />
@@ -4,7 +4,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Thinktecture.IdentityServer.Core.Models;
using IdentityServer3.Core.Models;
namespace Edgecastle.IdentityServer3.Neo4j.Interfaces
{
@@ -4,7 +4,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Thinktecture.IdentityServer.Core.Models;
using IdentityServer3.Core.Models;
namespace Edgecastle.IdentityServer3.Neo4j.Interfaces
{
@@ -4,7 +4,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Thinktecture.IdentityServer.Core.Models;
using IdentityServer3.Core.Models;
namespace Edgecastle.IdentityServer3.Neo4j.Interfaces
{
@@ -4,7 +4,7 @@
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using Thinktecture.IdentityServer.Core;
using IdentityServer3.Core;
namespace Edgecastle.IdentityServer3.Neo4j.Models
{
@@ -3,7 +3,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Thinktecture.IdentityServer.Core.Models;
using IdentityServer3.Core.Models;
namespace Edgecastle.IdentityServer3.Neo4j.Models
{
@@ -3,7 +3,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Thinktecture.IdentityServer.Core.Models;
using IdentityServer = IdentityServer3.Core.Models;
namespace Edgecastle.IdentityServer3.Neo4j.Models
{
@@ -17,11 +17,11 @@ public class Scope
/// </summary>
/// <param name="scopeClaim">The scope claim to add</param>
/// <returns>An IdentityServer3 scope representative of the Neo4j-serializable scope object.</returns>
internal Thinktecture.IdentityServer.Core.Models.Scope ToIdentityServerScope(ScopeClaim scopeClaim)
internal IdentityServer.Scope ToIdentityServerScope(IdentityServer.ScopeClaim scopeClaim)
{
var idSrvScope = new Thinktecture.IdentityServer.Core.Models.Scope
var idSrvScope = new IdentityServer.Scope
{
Claims = new List<ScopeClaim> { scopeClaim },
Claims = new List<IdentityServer.ScopeClaim> { scopeClaim },
ClaimsRule = this.ClaimsRule,
Description = this.Description,
DisplayName = this.DisplayName,
@@ -40,7 +40,7 @@ internal Thinktecture.IdentityServer.Core.Models.Scope ToIdentityServerScope(Sco
/// <summary>
/// List of user claims that should be included in the identity (identity scope) or access token (resource scope).
/// </summary>
public ScopeClaim[] Claims { get; set; }
public IdentityServer.ScopeClaim[] Claims { get; set; }
/// <summary>
/// Rule for determining which claims should be included in the token (this is implementation specific)
@@ -90,6 +90,6 @@ internal Thinktecture.IdentityServer.Core.Models.Scope ToIdentityServerScope(Sco
/// <summary>
/// Specifies whether this scope is about identity information from the userinfo endpoint, or a resource (e.g. a Web API). Defaults to Resource.
/// </summary>
public ScopeType Type { get; set; }
public IdentityServer.ScopeType Type { get; set; }
}
}
@@ -5,8 +5,8 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Thinktecture.IdentityServer.Core.Models;
using Thinktecture.IdentityServer.Core.Services;
using IdentityServer3.Core.Models;
using IdentityServer3.Core.Services;
using Edgecastle.IdentityServer3.Neo4j.Models;
namespace Edgecastle.IdentityServer3.Neo4j
@@ -36,12 +36,13 @@ public async Task<ClientAdminResult> CreateClient(Client client)
ClientName = client.ClientName,
ClientId = client.ClientId,
Flow = Flows.Implicit,
AllowedScopes = client.AllowedScopes,
// TODO - Uniqueness of redirect uris
RedirectUris = new List<string>
{
client.RedirectUris.FirstOrDefault()
}
{
client.RedirectUris.FirstOrDefault()
}
};
await DB.Cypher.Create("(c:Client {newClient})")
@@ -7,9 +7,9 @@
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Thinktecture.IdentityServer.Core.Logging;
using Thinktecture.IdentityServer.Core.Services;
using Thinktecture.IdentityServer.Core.Models;
using IdentityServer3.Core.Logging;
using IdentityServer3.Core.Services;
using IdentityServer3.Core.Models;
namespace Edgecastle.IdentityServer3.Neo4j
{
@@ -4,8 +4,8 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Thinktecture.IdentityServer.Core.Configuration;
using Thinktecture.IdentityServer.Core.Services;
using IdentityServer3.Core.Configuration;
using IdentityServer3.Core.Services;
namespace Edgecastle.IdentityServer3.Neo4j
{
@@ -8,9 +8,9 @@
using System.Text;
using System.Threading.Tasks;
using Thinktecture.IdentityModel;
using Thinktecture.IdentityServer.Core;
using Thinktecture.IdentityServer.Core.Models;
using Thinktecture.IdentityServer.Core.Services;
using IdentityServer3.Core;
using IdentityServer3.Core.Models;
using IdentityServer3.Core.Services;
namespace Edgecastle.IdentityServer3.Neo4j
{
@@ -81,18 +81,17 @@ public async Task<Models.UserAdminResult> AddClaimToUser(Guid userId, Models.Cla
/// <summary>
///
/// </summary>
/// <param name="externalUser"></param>
/// <param name="message"></param>
/// <param name="context"></param>
/// <returns></returns>
public async Task<AuthenticateResult> AuthenticateExternalAsync(ExternalIdentity externalUser, SignInMessage message)
public async Task AuthenticateExternalAsync(ExternalAuthenticationContext context)
{
// TODO: External providers as separate nodes
var query = DB.Cypher
.Match("(u:User { Provider: {provider}, ProviderId: {providerId}})")
.WithParams(new
{
provider = externalUser.Provider,
providerId = externalUser.ProviderId
provider = context.ExternalIdentity.Provider,
providerId = context.ExternalIdentity.ProviderId
})
.Return(u => u.As<Models.User>());
@@ -102,10 +101,10 @@ public async Task<AuthenticateResult> AuthenticateExternalAsync(ExternalIdentity
{
string displayName;
var name = externalUser.Claims.FirstOrDefault(x => x.Type == Constants.ClaimTypes.Name);
var name = context.ExternalIdentity.Claims.FirstOrDefault(x => x.Type == Constants.ClaimTypes.Name);
if (name == null)
{
displayName = externalUser.ProviderId;
displayName = context.ExternalIdentity.ProviderId;
}
else
{
@@ -115,10 +114,10 @@ public async Task<AuthenticateResult> AuthenticateExternalAsync(ExternalIdentity
user = new Models.User
{
Id = Guid.NewGuid(),
Provider = externalUser.Provider,
ProviderId = externalUser.ProviderId,
Provider = context.ExternalIdentity.Provider,
ProviderId = context.ExternalIdentity.ProviderId,
Username = displayName,
Claims = externalUser.Claims.Select(c => (Models.Claim) c) // Cast
Claims = context.ExternalIdentity.Claims.Select(c => (Models.Claim) c) // Cast
};
DB.Cypher
@@ -127,33 +126,30 @@ public async Task<AuthenticateResult> AuthenticateExternalAsync(ExternalIdentity
.ExecuteWithoutResults();
}
var result = new AuthenticateResult(user.Id.ToString(), user.Username);
return result;
context.AuthenticateResult = new AuthenticateResult(user.Id.ToString(), user.Username);
}
/// <summary>
///
/// Authenticates the user with a local account
/// </summary>
/// <param name="username"></param>
/// <param name="password"></param>
/// <param name="message"></param>
/// <param name="context">The context</param>
/// <returns></returns>
public async Task<AuthenticateResult> AuthenticateLocalAsync(string username, string password, SignInMessage message)
public async Task AuthenticateLocalAsync(LocalAuthenticationContext context)
{
var usernameQuery = DB.Cypher
.Match("(u:User {Username:{username}})")
.WithParam("username", username.ToLowerInvariant())
.WithParam("username", context.UserName.ToLowerInvariant())
.Return(u => u.As<Models.AuthenticationInfo>());
var authenticationInfo = (await usernameQuery.ResultsAsync).FirstOrDefault();
if (authenticationInfo == null || !PasswordSecurity.Verify(input: password, hash: authenticationInfo.Password))
if (authenticationInfo == null || !PasswordSecurity.Verify(input: context.Password, hash: authenticationInfo.Password))
{
// Couldn't find user with that username and/or password
return new AuthenticateResult("Authentication failed.");
context.AuthenticateResult = new AuthenticateResult("Authentication failed.");
}
return new AuthenticateResult(authenticationInfo.Id.ToString(), authenticationInfo.Username);
context.AuthenticateResult = new AuthenticateResult(authenticationInfo.Id.ToString(), authenticationInfo.Username);
}
/// <summary>
@@ -193,60 +189,68 @@ await DB.Cypher.Create("(u:User {newUser})")
}
/// <summary>
///
/// Populates the context with issues claims.
/// </summary>
/// <param name="subject"></param>
/// <param name="requestedClaimTypes"></param>
/// <returns></returns>
public async Task<IEnumerable<Claim>> GetProfileDataAsync(ClaimsPrincipal subject, IEnumerable<string> requestedClaimTypes = null)
/// <param name="context">The profile data request</param>
public async Task GetProfileDataAsync(ProfileDataRequestContext context) // ClaimsPrincipal subject, IEnumerable<string> requestedClaimTypes = null)
{
// TODO: This is all temporary
var query = DB.Cypher
.Match("(u:User {Username: {username}})-[:HAS_CLAIM]->(c:Claim)")
.WithParam("username", subject.Identity.Name)
.WithParam("username", context.Subject.Identity.Name)
.Return(c => c.As<Models.Claim>());
var results = await query.ResultsAsync;
var claims = new List<Claim>{
new Claim(Constants.ClaimTypes.Subject, subject.Identity.Name),
new Claim(Constants.ClaimTypes.Subject, context.Subject.Identity.Name),
};
claims.AddRange(results.Select(c => (Claim) c));
if (requestedClaimTypes != null)
if (context.RequestedClaimTypes != null)
{
claims = claims.Where(x => requestedClaimTypes.Contains(x.Type)).ToList();
claims = claims.Where(x => context.RequestedClaimTypes.Contains(x.Type)).ToList();
}
return claims;
context.IssuedClaims = claims;
}
/// <summary>
///
/// </summary>
/// <param name="subject"></param>
/// <param name="context"></param>
/// <returns></returns>
public Task<bool> IsActiveAsync(ClaimsPrincipal subject)
public Task IsActiveAsync(IsActiveContext context)
{
return Task.FromResult<bool>(true);
return Task.FromResult(0);
}
/// <summary>
///
/// </summary>
/// <param name="message"></param>
/// <param name="context">The context</param>
/// <returns></returns>
public Task<AuthenticateResult> PreAuthenticateAsync(SignInMessage message)
public Task PreAuthenticateAsync(PreAuthenticationContext context)
{
return Task.FromResult<AuthenticateResult>(null);
return Task.FromResult(0);
}
/// <summary>
/// Post authentication
/// </summary>
/// <param name="context">The context</param>
/// <returns></returns>
public Task PostAuthenticateAsync(PostAuthenticationContext context)
{
return Task.FromResult(0);
}
/// <summary>
///
/// Signs out
/// </summary>
/// <param name="subject"></param>
/// <param name="context"></param>
/// <returns></returns>
public Task SignOutAsync(ClaimsPrincipal subject)
public Task SignOutAsync(SignOutContext context)
{
return Task.FromResult(0);
}
Oops, something went wrong.

0 comments on commit 8864806

Please sign in to comment.