From 348120d5f584e0f3794aef01edf63bf93c8eac00 Mon Sep 17 00:00:00 2001 From: John10 Korsnes Date: Sun, 22 Jan 2017 12:03:31 +0100 Subject: [PATCH] Added simple claims for claimsprincipal serialization/deserialization for Subject property of RefreshToken --- Source/Core.MongoDb/RefreshTokenSerializer.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Source/Core.MongoDb/RefreshTokenSerializer.cs b/Source/Core.MongoDb/RefreshTokenSerializer.cs index f047db9..1b58db8 100644 --- a/Source/Core.MongoDb/RefreshTokenSerializer.cs +++ b/Source/Core.MongoDb/RefreshTokenSerializer.cs @@ -14,6 +14,7 @@ * limitations under the License. */ +using System.Security.Claims; using System.Threading.Tasks; using IdentityServer3.Core.Models; using IdentityServer3.Core.Services; @@ -24,10 +25,12 @@ namespace IdentityServer3.MongoDb class RefreshTokenSerializer { private readonly TokenSerializer _tokenSerializer; + private readonly ClaimSetSerializer _subjectSerializer; public RefreshTokenSerializer(IClientStore clientStore) { _tokenSerializer = new TokenSerializer(clientStore); + _subjectSerializer = new ClaimSetSerializer(); } public BsonDocument Serialize(string key, RefreshToken value) { @@ -43,6 +46,9 @@ public BsonDocument Serialize(string key, RefreshToken value) doc["creationTime"] = value.CreationTime.ToBsonDateTime(); doc["lifetime"] = value.LifeTime; doc["version"] = value.Version; + + var subjectClaims = _subjectSerializer.Serialize(value.Subject.Claims); + doc["_subjectClaims"] = subjectClaims; return doc; } @@ -58,6 +64,9 @@ public async Task Deserialize(BsonDocument doc) token.CreationTime = doc.GetValueOrDefault("creationTime", token.CreationTime); token.LifeTime = doc.GetValueOrDefault("lifetime", token.LifeTime); token.Version = doc.GetValueOrDefault("version", token.Version); + var documentClaims = doc.GetValue("_subjectClaims").AsBsonDocument; + var claimsFromSubject = _subjectSerializer.Deserialize(documentClaims); + token.Subject = new ClaimsPrincipal(new ClaimsIdentity(claimsFromSubject)); return token; } }