Skip to content

Commit

Permalink
Added simple claims for claimsprincipal serialization/deserialization…
Browse files Browse the repository at this point in the history
… for Subject property of RefreshToken
  • Loading branch information
johnkors committed Jan 22, 2017
1 parent 78e2142 commit 348120d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Source/Core.MongoDb/RefreshTokenSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

using System.Security.Claims;
using System.Threading.Tasks;
using IdentityServer3.Core.Models;
using IdentityServer3.Core.Services;
Expand All @@ -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)
{
Expand All @@ -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;
}

Expand All @@ -58,6 +64,9 @@ public async Task<RefreshToken> 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;
}
}
Expand Down

0 comments on commit 348120d

Please sign in to comment.