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
3 changes: 3 additions & 0 deletions Source/MongoDb.AdminModule.Tests/AddClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Security.Claims;
using System.Threading.Tasks;
using IdentityServer3.Admin.MongoDb;
using IdentityServer3.Core;
using IdentityServer3.Core.Models;
using IdentityServer3.Core.Services;
using Xunit;
Expand Down Expand Up @@ -62,9 +63,11 @@ public async Task CheckClient()
Assert.Equal("WxFhjC5EAnh30M0JIe0Wa58Xb1BYf8kedTTdKUbbd9Y=", client.ClientSecrets[0].Value);
Assert.Equal("testsecret", client.ClientSecrets[0].Description);
Assert.Equal(new DateTimeOffset(2000, 1,1,1,1,1,0,TimeSpan.Zero), client.ClientSecrets[0].Expiration);
Assert.Equal(Constants.SecretTypes.SharedSecret, client.ClientSecrets[0].Type);
Assert.Equal("cckjYsokygyEIiAV5Y/sIStXfM1W7qwGTo3K9VxmT4xXfeRFWekmMbr2wKZy2T1HSNXW6vjNyRxajG46oEBrAw==", client.ClientSecrets[1].Value);
Assert.Null(client.ClientSecrets[1].Description);
Assert.Null(client.ClientSecrets[1].Expiration);
Assert.Equal(Constants.SecretTypes.SharedSecret, client.ClientSecrets[1].Type);
Assert.Equal(true, client.Enabled);
Assert.Equal(Flows.AuthorizationCode, client.Flow);
Assert.Equal(new List<string>{"restriction1", "restriction2"}, client.IdentityProviderRestrictions);
Expand Down
3 changes: 2 additions & 1 deletion Source/MongoDb.AdminModule.Tests/TestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using IdentityServer3.Core;
using IdentityServer3.Core.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
Expand All @@ -40,7 +41,7 @@ public static Client ClientAllProperties()
ClientName = "TEST",
ClientSecrets = new List<Secret>()
{
new Secret("secret","secret", WellKnownTime){Type = "secret type"},
new Secret("secret","secret", WellKnownTime){Type = Constants.SecretTypes.SharedSecret},
new Secret("newsecret"),
},
ClientUri = "clientUri",
Expand Down
9 changes: 7 additions & 2 deletions Source/MongoDb.AdminModule/CreateClientSecret.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,20 @@ public class CreateClientSecret : PSCmdlet
public DateTimeOffset? Expiration { get; set; }
[Parameter]
public HashType? Hash { get; set; }

[Parameter]
public string Type { get; set; }

protected override void ProcessRecord()
{
if (Hash != null)
{
var hash = Hash == HashType.SHA256 ? (HashAlgorithm) SHA256.Create() : SHA512.Create();
var hash = Hash == HashType.SHA256 ? (HashAlgorithm)SHA256.Create() : SHA512.Create();
var bytes = hash.ComputeHash(Encoding.UTF8.GetBytes(Value));
Value = Convert.ToBase64String(bytes);
}
WriteObject(new Secret(Value, Description, Expiration));
if (string.IsNullOrWhiteSpace(Type)) Type = Core.Constants.SecretTypes.SharedSecret;
WriteObject(new Secret(Value, Description, Expiration) { Type = Type });
}
}
}