public static OpenIddictTokenModel ToModel(this OpenIddictToken entity) { if (entity == null) { return(null); } var model = new OpenIddictTokenModel { Id = entity.Id, ApplicationId = entity.ApplicationId, AuthorizationId = entity.AuthorizationId, CreationDate = entity.CreationDate, ExpirationDate = entity.ExpirationDate, Payload = entity.Payload, Properties = entity.Properties, RedemptionDate = entity.RedemptionDate, ReferenceId = entity.ReferenceId, Status = entity.Status, Subject = entity.Subject, Type = entity.Type }; foreach (var extraProperty in entity.ExtraProperties) { model.ExtraProperties.Add(extraProperty.Key, extraProperty.Value); } return(model); }
public static OpenIddictToken ToEntity(this OpenIddictTokenModel model, OpenIddictToken entity) { Check.NotNull(model, nameof(model)); Check.NotNull(entity, nameof(entity)); entity.ApplicationId = model.ApplicationId; entity.AuthorizationId = model.AuthorizationId; entity.CreationDate = model.CreationDate; entity.ExpirationDate = model.ExpirationDate; entity.Payload = model.Payload; entity.Properties = model.Properties; entity.RedemptionDate = model.RedemptionDate; entity.ReferenceId = model.ReferenceId; entity.Status = model.Status; entity.Subject = model.Subject; entity.Type = model.Type; foreach (var extraProperty in model.ExtraProperties) { entity.ExtraProperties.Remove(extraProperty.Key); entity.ExtraProperties.Add(extraProperty.Key, extraProperty.Value); } return(entity); }
public static OpenIddictToken ToEntity(this OpenIddictTokenModel model) { Check.NotNull(model, nameof(model)); var entity = new OpenIddictToken(model.Id) { ApplicationId = model.ApplicationId, AuthorizationId = model.AuthorizationId, CreationDate = model.CreationDate, ExpirationDate = model.ExpirationDate, Payload = model.Payload, Properties = model.Properties, RedemptionDate = model.RedemptionDate, ReferenceId = model.ReferenceId, Status = model.Status, Subject = model.Subject, Type = model.Type }; foreach (var extraProperty in model.ExtraProperties) { entity.ExtraProperties.Add(extraProperty.Key, extraProperty.Value); } return(entity); }
public virtual ValueTask SetCreationDateAsync(OpenIddictTokenModel token, DateTimeOffset?date, CancellationToken cancellationToken) { Check.NotNull(token, nameof(token)); token.CreationDate = date?.UtcDateTime; return(default);
public virtual async ValueTask CreateAsync(OpenIddictTokenModel token, CancellationToken cancellationToken) { Check.NotNull(token, nameof(token)); await Repository.InsertAsync(token.ToEntity(), autoSave : true, cancellationToken : cancellationToken); token = (await Repository.FindAsync(token.Id, cancellationToken: cancellationToken)).ToModel(); }
public virtual ValueTask <string> GetAuthorizationIdAsync(OpenIddictTokenModel token, CancellationToken cancellationToken) { Check.NotNull(token, nameof(token)); return(new ValueTask <string>(token.AuthorizationId.HasValue ? ConvertIdentifierToString(token.AuthorizationId.Value) : null)); }
public virtual ValueTask <DateTimeOffset?> GetRedemptionDateAsync(OpenIddictTokenModel token, CancellationToken cancellationToken) { Check.NotNull(token, nameof(token)); if (token.RedemptionDate is null) { return(new ValueTask <DateTimeOffset?>(result: null)); } return(new ValueTask <DateTimeOffset?>(DateTime.SpecifyKind(token.RedemptionDate.Value, DateTimeKind.Utc))); }
public virtual async ValueTask SetAuthorizationIdAsync(OpenIddictTokenModel token, string identifier, CancellationToken cancellationToken) { Check.NotNull(token, nameof(token)); if (!string.IsNullOrEmpty(identifier)) { var authorization = await AuthorizationRepository.GetAsync(ConvertIdentifierFromString(identifier), cancellationToken : cancellationToken); token.AuthorizationId = authorization.Id; } else { token.AuthorizationId = null; } }
public virtual async ValueTask DeleteAsync(OpenIddictTokenModel token, CancellationToken cancellationToken) { Check.NotNull(token, nameof(token)); await Repository.DeleteAsync(token.ToEntity(), autoSave : true, cancellationToken : cancellationToken); }
public virtual ValueTask <string> GetTypeAsync(OpenIddictTokenModel token, CancellationToken cancellationToken) { Check.NotNull(token, nameof(token)); return(new ValueTask <string>(token.Type)); }
public virtual ValueTask <ImmutableDictionary <string, JsonElement> > GetPropertiesAsync(OpenIddictTokenModel token, CancellationToken cancellationToken) { Check.NotNull(token, nameof(token)); if (string.IsNullOrEmpty(token.Properties)) { return(new ValueTask <ImmutableDictionary <string, JsonElement> >(ImmutableDictionary.Create <string, JsonElement>())); } using (var document = JsonDocument.Parse(token.Properties)) { var builder = ImmutableDictionary.CreateBuilder <string, JsonElement>(); foreach (var property in document.RootElement.EnumerateObject()) { builder[property.Name] = property.Value.Clone(); } return(new ValueTask <ImmutableDictionary <string, JsonElement> >(builder.ToImmutable())); } }
public virtual ValueTask <string> GetIdAsync(OpenIddictTokenModel token, CancellationToken cancellationToken) { Check.NotNull(token, nameof(token)); return(new ValueTask <string>(ConvertIdentifierToString(token.Id))); }