Skip to content

Commit

Permalink
Current claims available in RefreshTokenRefreshDetails IdentityServer…
Browse files Browse the repository at this point in the history
  • Loading branch information
Szymon Gaertig committed Sep 4, 2016
1 parent 550cc2e commit 2d7e028
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
10 changes: 10 additions & 0 deletions source/Core/Events/TokenService/RefreshTokenRefreshDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

using System.Collections.Generic;

namespace IdentityServer3.Core.Events
{
/// <summary>
Expand Down Expand Up @@ -52,5 +54,13 @@ public class RefreshTokenRefreshDetails
/// The lifetime.
/// </value>
public int Lifetime { get; set; }

/// <summary>
/// Gets or sets the claims.
/// </summary>
/// <value>
/// The claims.
/// </value>
public Dictionary<string, object> Claims { get; set; }
}
}
3 changes: 2 additions & 1 deletion source/Core/Extensions/IEventServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@ public static async Task RaiseSuccessfulRefreshTokenRefreshEventAsync(this IEven
OldHandle = oldHandle,
NewHandle = newHandle,
ClientId = token.ClientId,
Lifetime = token.LifeTime
Lifetime = token.LifeTime,
Claims = token.Subject.Claims.ToClaimsDictionary()
};

await events.RaiseEventAsync(evt);
Expand Down
1 change: 1 addition & 0 deletions source/Tests/UnitTests/Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
<Compile Include="Endpoints\Connect\PoP\PoPAsymmetricTestsCode.cs" />
<Compile Include="Endpoints\Connect\PoP\RsaPublicKeyJwk.cs" />
<Compile Include="Endpoints\Setup\MockUserService.cs" />
<Compile Include="Events\RefreshTokenRefreshDetailsTests.cs" />
<Compile Include="Services\Default\DefaultCorsPolicyServiceTests.cs" />
<Compile Include="Services\Default\DefaultLocalizationServiceTests.cs" />
<Compile Include="TestCert.cs" />
Expand Down
58 changes: 58 additions & 0 deletions source/Tests/UnitTests/Events/RefreshTokenRefreshDetailsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System.Collections.Generic;
using System.Security.Claims;
using System.Threading.Tasks;
using IdentityServer3.Core.Events;
using IdentityServer3.Core.Extensions;
using IdentityServer3.Core.Models;
using IdentityServer3.Core.Services;
using Moq;
using Xunit;

namespace IdentityServer3.Tests.Events
{
public class RefreshTokenRefreshDetailsTests
{
[Fact]
public async Task When_claims_are_provided_then_create_event_with_given_claims()
{
// Given
var oldHandle = "old_handle";
var newHandle = "new_handle";

var claimsPrincipalMock = new Mock<ClaimsPrincipal>();
claimsPrincipalMock.Setup(x => x.Claims)
.Returns(new List<Claim>()
{
new Claim("claim_type_1", "claims_1_value"),
new Claim("claim_type_2", "claims_2_value")
});

var refreshToken = new RefreshToken()
{
AccessToken = new Token()
{
Client = new Client()
{
ClientId = "client_id",
AccessTokenLifetime = 10
},
},
Subject = claimsPrincipalMock.Object
};
var eventServiceMock = new Mock<IEventService>();

// When
await eventServiceMock.Object.RaiseSuccessfulRefreshTokenRefreshEventAsync(oldHandle,
newHandle,
refreshToken);

// Then
eventServiceMock.Verify(
x => x.RaiseAsync(
It.Is<Event<RefreshTokenRefreshDetails>>(rt
=> rt.Details.Claims.ContainsKey("claim_type_1")
&& rt.Details.Claims.ContainsKey("claim_type_2")
&& rt.Details.Claims.Count == 2)));
}
}
}

0 comments on commit 2d7e028

Please sign in to comment.