public void Serialize(BsonDocument doc, Token token) { doc["_version"] = 1; doc["audience"] = token.Audience; doc["claims"] = ClaimsSetSerializer.Serialize(token.Claims); doc["client"] = token.Client.ClientId; doc["creationTime"] = token.CreationTime.ToBsonDateTime(); doc["issuer"] = token.Issuer; doc["lifetime"] = token.Lifetime; doc["type"] = token.Type; doc["version"] = token.Version; }
private BsonArray SerializeIdentities(AuthorizationCode code) { var subject = new BsonArray(); foreach (ClaimsIdentity claimsIdentity in code.Subject.Identities) { var identity = new BsonDocument(); identity["authenticationType"] = claimsIdentity.AuthenticationType; var enumerable = claimsIdentity.Claims; var claims = ClaimSetSerializer.Serialize(enumerable); identity["claimSet"] = claims; subject.Add(identity); } return(subject); }
public BsonDocument Serialize(string key, RefreshToken value) { var doc = new BsonDocument(); doc["_id"] = key; doc["_version"] = 2; doc["_expires"] = value.CreationTime.AddSeconds(value.LifeTime).ToBsonDateTime(); doc["_clientId"] = value.ClientId; doc["_subjectId"] = value.SubjectId; var accessToken = new BsonDocument(); _tokenSerializer.Serialize(accessToken, value.AccessToken); doc["accessToken"] = accessToken; doc["creationTime"] = value.CreationTime.ToBsonDateTime(); doc["lifetime"] = value.LifeTime; doc["version"] = value.Version; var subjectClaims = _claimSetSerializer.Serialize(value.Subject.Claims); doc["subjectClaims"] = subjectClaims; return(doc); }
public BsonDocument Serialize(Client client) { var doc = new BsonDocument(); doc["_id"] = client.ClientId; doc["_version"] = 3; doc["absoluteRefreshTokenLifetime"] = client.AbsoluteRefreshTokenLifetime; doc["accessTokenLifetime"] = client.AccessTokenLifetime; doc["accessTokenType"] = client.AccessTokenType.ToString(); doc["enableLocalLogin"] = client.EnableLocalLogin; doc["allowRememberConsent"] = client.AllowRememberConsent; doc["authorizationCodeLifetime"] = client.AuthorizationCodeLifetime; doc["clientName"] = client.ClientName; var secrets = new BsonArray(); foreach (var clientSecret in client.ClientSecrets) { var secret = new BsonDocument(); secret.SetIfNotNull("description", clientSecret.Description); secret.SetIfNotNull("value", clientSecret.Value); secret.SetIfNotNull("expiration", clientSecret.Expiration); secret.SetIfNotNull("type", clientSecret.Type); secrets.Add(secret); } doc["clientSecrets"] = secrets; if (client.ClientUri != null) { doc.SetIfNotNull("clientUri", client.ClientUri); } doc["enabled"] = client.Enabled; doc["flow"] = client.Flow.ToString(); var idpr = new BsonArray(); foreach (string restriction in client.IdentityProviderRestrictions) { idpr.Add(restriction); } doc["identityProviderRestrictions"] = idpr; doc["identityTokenLifetime"] = client.IdentityTokenLifetime; doc.SetIfNotNull("logoUri", client.LogoUri); var postLogoutRedirectUris = new BsonArray(); foreach (var uri in client.PostLogoutRedirectUris) { postLogoutRedirectUris.Add(uri); } var redirectUris = new BsonArray(); foreach (var uri in client.RedirectUris) { redirectUris.Add(uri); } doc["redirectUris"] = redirectUris; doc["postLogoutRedirectUris"] = postLogoutRedirectUris; doc["refreshTokenExpiration"] = client.RefreshTokenExpiration.ToString(); doc["refreshTokenUsage"] = client.RefreshTokenUsage.ToString(); doc["requireConsent"] = client.RequireConsent; var scopeRestrictions = new BsonArray(); foreach (string restriction in client.AllowedScopes) { scopeRestrictions.Add(restriction); } doc["allowedScopes"] = scopeRestrictions; doc["slidingRefreshTokenLifetime"] = client.SlidingRefreshTokenLifetime; doc["includeJwtId"] = client.IncludeJwtId; var clientClaims = new BsonDocument(); doc["clientClaims"] = clientClaims; ClaimSetSerializer.Serialize(client.Claims, clientClaims); doc["alwaysSendClientClaims"] = client.AlwaysSendClientClaims; doc["PrefixClientClaims"] = client.PrefixClientClaims; var grantRestrictions = new BsonArray(); foreach (string restriction in client.AllowedCustomGrantTypes) { grantRestrictions.Add(restriction); } doc["allowedCustomGrantTypes"] = grantRestrictions; doc["allowClientCredentialsOnly"] = client.AllowClientCredentialsOnly; doc["updateAccessTokenClaimsOnRefresh"] = client.UpdateAccessTokenClaimsOnRefresh; doc["updateAccessTokenClaimsOnRefresh"] = client.UpdateAccessTokenClaimsOnRefresh; var allowedCorsOrigins = new BsonArray(); foreach (var origin in client.AllowedCorsOrigins) { if (!string.IsNullOrEmpty(origin)) { allowedCorsOrigins.Add(origin); } } doc["allowedCorsOrigins"] = allowedCorsOrigins; doc["allowAccessToAllScopes"] = client.AllowAccessToAllScopes; doc["allowAccessToAllCustomGrantTypes"] = client.AllowAccessToAllCustomGrantTypes; doc["allowClientCredentialsOnly"] = client.AllowClientCredentialsOnly; doc["allowAccessTokensViaBrowser"] = client.AllowAccessTokensViaBrowser; doc["logoutSessionRequired"] = client.LogoutSessionRequired; doc["requireSignOutPrompt"] = client.RequireSignOutPrompt; doc.SetIfNotNull("logoutUri", client.LogoutUri); return(doc); }