diff --git a/Source/MongoDb.AdminModule.Tests/AddClient.cs b/Source/MongoDb.AdminModule.Tests/AddClient.cs index c8fce03..3dd8cb7 100644 --- a/Source/MongoDb.AdminModule.Tests/AddClient.cs +++ b/Source/MongoDb.AdminModule.Tests/AddClient.cs @@ -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; @@ -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{"restriction1", "restriction2"}, client.IdentityProviderRestrictions); diff --git a/Source/MongoDb.AdminModule.Tests/TestData.cs b/Source/MongoDb.AdminModule.Tests/TestData.cs index 59bba7a..c15f594 100644 --- a/Source/MongoDb.AdminModule.Tests/TestData.cs +++ b/Source/MongoDb.AdminModule.Tests/TestData.cs @@ -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; @@ -40,7 +41,7 @@ public static Client ClientAllProperties() ClientName = "TEST", ClientSecrets = new List() { - new Secret("secret","secret", WellKnownTime){Type = "secret type"}, + new Secret("secret","secret", WellKnownTime){Type = Constants.SecretTypes.SharedSecret}, new Secret("newsecret"), }, ClientUri = "clientUri", diff --git a/Source/MongoDb.AdminModule/CreateClientSecret.cs b/Source/MongoDb.AdminModule/CreateClientSecret.cs index 25cf9fa..222f09c 100644 --- a/Source/MongoDb.AdminModule/CreateClientSecret.cs +++ b/Source/MongoDb.AdminModule/CreateClientSecret.cs @@ -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 }); } } } \ No newline at end of file