Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

Commit

Permalink
Updated claims serializer to preserve value types - closes #380
Browse files Browse the repository at this point in the history
  • Loading branch information
leastprivilege committed Oct 28, 2016
1 parent f636f55 commit 0e8c77d
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/IdentityServer4/Stores/Serialization/ClaimConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public override bool CanConvert(Type objectType)
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var source = serializer.Deserialize<ClaimLite>(reader);
var target = new Claim(source.Type, source.Value);
var target = new Claim(source.Type, source.Value, source.ValueType);
return target;
}

Expand All @@ -29,9 +29,11 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
var target = new ClaimLite
{
Type = source.Type,
Value = source.Value
Value = source.Value,
ValueType = source.ValueType
};

serializer.Serialize(writer, target);
}
}
}
}
3 changes: 2 additions & 1 deletion src/IdentityServer4/Stores/Serialization/ClaimLite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ public class ClaimLite
{
public string Type { get; set; }
public string Value { get; set; }
public string ValueType { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,45 @@ public async Task Response_data_should_be_valid_using_single_scope()
scopes.Count.Should().Be(1);
}

[Fact]
[Trait("Category", Category)]
public async Task Response_data_with_user_authentication_should_be_valid_using_single_scope()
{
var tokenClient = new TokenClient(
TokenEndpoint,
"ro.client",
"secret",
_handler);

var tokenResponse = await tokenClient.RequestResourceOwnerPasswordAsync("bob", "bob", "api1");
tokenResponse.IsError.Should().BeFalse();

var introspectionClient = new IntrospectionClient(
IntrospectionEndpoint,
"api1",
"secret",
_handler);

var response = await introspectionClient.SendAsync(new IntrospectionRequest
{
Token = tokenResponse.AccessToken
});

var values = response.Json.ToObject<Dictionary<string, object>>();

values["aud"].GetType().Name.Should().Be("String");
values["iss"].GetType().Name.Should().Be("String");
values["nbf"].GetType().Name.Should().Be("Int64");
values["exp"].GetType().Name.Should().Be("Int64");
values["auth_time"].GetType().Name.Should().Be("Int64");
values["client_id"].GetType().Name.Should().Be("String");
values["sub"].GetType().Name.Should().Be("String");
values["active"].GetType().Name.Should().Be("Boolean");

var scopes = values["scope"] as JArray;
scopes.Count.Should().Be(1);
}

[Fact]
[Trait("Category", Category)]
public async Task Response_data_should_be_valid_using_multiple_scopes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ public static IEnumerable<Client> Get()
AllowedGrantTypes = GrantTypes.ClientCredentials,
AllowAccessToAllScopes = true,
AccessTokenType = AccessTokenType.Reference
},
new Client
{
ClientId = "ro.client",
ClientSecrets = new List<Secret>
{
new Secret("secret".Sha256())
},

AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
AllowAccessToAllScopes = true,
AccessTokenType = AccessTokenType.Reference
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void ConfigureServices(IServiceCollection services)

builder.AddInMemoryClients(Clients.Get());
builder.AddInMemoryScopes(Scopes.Get());
builder.AddInMemoryUsers(new List<InMemoryUser>());
builder.AddInMemoryUsers(Users.Get());
builder.AddTemporarySigningCredential();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.


using IdentityServer4.Services.InMemory;
using System.Collections.Generic;

namespace IdentityServer4.IntegrationTests.Endpoints.Introspection
{
public static class Users
{
public static List<InMemoryUser> Get()
{
return new List<InMemoryUser>
{
new InMemoryUser
{
Subject = "1",
Username = "bob",
Password = "bob"
}
};
}
}
}

0 comments on commit 0e8c77d

Please sign in to comment.