From 7fdc84a9b791ed62cf6398e4d573e78851906243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Mon, 30 Apr 2018 16:33:29 +0200 Subject: [PATCH] Make PopulateAsync() public and provide an overload allowing to populate a descriptor --- .../Managers/OpenIddictApplicationManager.cs | 198 ++++++++++-------- .../OpenIddictAuthorizationManager.cs | 110 ++++++---- .../Managers/OpenIddictScopeManager.cs | 105 ++++++---- .../Managers/OpenIddictTokenManager.cs | 123 ++++++----- 4 files changed, 317 insertions(+), 219 deletions(-) diff --git a/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs b/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs index ddb20a09..e18443b2 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs @@ -811,6 +811,108 @@ namespace OpenIddict.Core return Store.ListAsync(query, state, cancellationToken); } + /// + /// Populates the application using the specified descriptor. + /// + /// The application. + /// The descriptor. + /// The that can be used to abort the operation. + /// + /// A that can be used to monitor the asynchronous operation. + /// + public virtual async Task PopulateAsync([NotNull] TApplication application, + [NotNull] OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default) + { + if (application == null) + { + throw new ArgumentNullException(nameof(application)); + } + + if (descriptor == null) + { + throw new ArgumentNullException(nameof(descriptor)); + } + + await Store.SetClientIdAsync(application, descriptor.ClientId, cancellationToken); + await Store.SetClientSecretAsync(application, descriptor.ClientSecret, cancellationToken); + await Store.SetClientTypeAsync(application, descriptor.Type, cancellationToken); + await Store.SetConsentTypeAsync(application, descriptor.ConsentType, cancellationToken); + await Store.SetDisplayNameAsync(application, descriptor.DisplayName, cancellationToken); + await Store.SetPermissionsAsync(application, ImmutableArray.CreateRange(descriptor.Permissions), cancellationToken); + await Store.SetPostLogoutRedirectUrisAsync(application, ImmutableArray.CreateRange( + descriptor.PostLogoutRedirectUris.Select(address => address.OriginalString)), cancellationToken); + await Store.SetRedirectUrisAsync(application, ImmutableArray.CreateRange( + descriptor.RedirectUris.Select(address => address.OriginalString)), cancellationToken); + } + + /// + /// Populates the specified descriptor using the properties exposed by the application. + /// + /// The descriptor. + /// The application. + /// The that can be used to abort the operation. + /// + /// A that can be used to monitor the asynchronous operation. + /// + public virtual async Task PopulateAsync( + [NotNull] OpenIddictApplicationDescriptor descriptor, + [NotNull] TApplication application, CancellationToken cancellationToken = default) + { + if (descriptor == null) + { + throw new ArgumentNullException(nameof(descriptor)); + } + + if (application == null) + { + throw new ArgumentNullException(nameof(application)); + } + + descriptor.ClientId = await Store.GetClientIdAsync(application, cancellationToken); + descriptor.ClientSecret = await Store.GetClientSecretAsync(application, cancellationToken); + descriptor.ConsentType = await Store.GetConsentTypeAsync(application, cancellationToken); + descriptor.DisplayName = await Store.GetDisplayNameAsync(application, cancellationToken); + descriptor.Type = await Store.GetClientTypeAsync(application, cancellationToken); + descriptor.Permissions.Clear(); + descriptor.Permissions.UnionWith(await Store.GetPermissionsAsync(application, cancellationToken)); + descriptor.PostLogoutRedirectUris.Clear(); + descriptor.RedirectUris.Clear(); + + foreach (var address in await Store.GetPostLogoutRedirectUrisAsync(application, cancellationToken)) + { + // Ensure the address is not null or empty. + if (string.IsNullOrEmpty(address)) + { + throw new ArgumentException("Callback URLs cannot be null or empty."); + } + + // Ensure the address is a valid absolute URL. + if (!Uri.TryCreate(address, UriKind.Absolute, out Uri uri) || !uri.IsWellFormedOriginalString()) + { + throw new ArgumentException("Callback URLs must be valid absolute URLs."); + } + + descriptor.PostLogoutRedirectUris.Add(uri); + } + + foreach (var address in await Store.GetRedirectUrisAsync(application, cancellationToken)) + { + // Ensure the address is not null or empty. + if (string.IsNullOrEmpty(address)) + { + throw new ArgumentException("Callback URLs cannot be null or empty."); + } + + // Ensure the address is a valid absolute URL. + if (!Uri.TryCreate(address, UriKind.Absolute, out Uri uri) || !uri.IsWellFormedOriginalString()) + { + throw new ArgumentException("Callback URLs must be valid absolute URLs."); + } + + descriptor.RedirectUris.Add(uri); + } + } + /// /// Updates an existing application. /// @@ -878,75 +980,33 @@ namespace OpenIddict.Core /// Updates an existing application. /// /// The application to update. - /// The delegate used to update the application based on the given descriptor. + /// The descriptor used to update the application. /// The that can be used to abort the operation. /// /// A that can be used to monitor the asynchronous operation. /// public virtual async Task UpdateAsync([NotNull] TApplication application, - [NotNull] Func operation, CancellationToken cancellationToken = default) + [NotNull] OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default) { - if (operation == null) - { - throw new ArgumentNullException(nameof(operation)); - } - - // Store the original client secret for later comparison. - var secret = await Store.GetClientSecretAsync(application, cancellationToken); - - var descriptor = new OpenIddictApplicationDescriptor - { - ClientId = await Store.GetClientIdAsync(application, cancellationToken), - ClientSecret = secret, - ConsentType = await Store.GetConsentTypeAsync(application, cancellationToken), - DisplayName = await Store.GetDisplayNameAsync(application, cancellationToken), - Type = await Store.GetClientTypeAsync(application, cancellationToken) - }; - - descriptor.Permissions.UnionWith(await Store.GetPermissionsAsync(application, cancellationToken)); - - foreach (var address in await Store.GetPostLogoutRedirectUrisAsync(application, cancellationToken)) + if (application == null) { - // Ensure the address is not null or empty. - if (string.IsNullOrEmpty(address)) - { - throw new ArgumentException("Callback URLs cannot be null or empty."); - } - - // Ensure the address is a valid absolute URL. - if (!Uri.TryCreate(address, UriKind.Absolute, out Uri uri) || !uri.IsWellFormedOriginalString()) - { - throw new ArgumentException("Callback URLs must be valid absolute URLs."); - } - - descriptor.PostLogoutRedirectUris.Add(uri); + throw new ArgumentNullException(nameof(application)); } - foreach (var address in await Store.GetRedirectUrisAsync(application, cancellationToken)) + if (descriptor == null) { - // Ensure the address is not null or empty. - if (string.IsNullOrEmpty(address)) - { - throw new ArgumentException("Callback URLs cannot be null or empty."); - } - - // Ensure the address is a valid absolute URL. - if (!Uri.TryCreate(address, UriKind.Absolute, out Uri uri) || !uri.IsWellFormedOriginalString()) - { - throw new ArgumentException("Callback URLs must be valid absolute URLs."); - } - - descriptor.RedirectUris.Add(uri); + throw new ArgumentNullException(nameof(descriptor)); } - await operation(descriptor); + // Store the original client secret for later comparison. + var comparand = await Store.GetClientSecretAsync(application, cancellationToken); await PopulateAsync(application, descriptor, cancellationToken); // If the client secret was updated, re-obfuscate it before persisting the changes. - var comparand = await Store.GetClientSecretAsync(application, cancellationToken); + var secret = await Store.GetClientSecretAsync(application, cancellationToken); if (!string.Equals(secret, comparand, StringComparison.Ordinal)) { - await UpdateAsync(application, comparand, cancellationToken); + await UpdateAsync(application, secret, cancellationToken); return; } @@ -1233,40 +1293,6 @@ namespace OpenIddict.Core return false; } - /// - /// Populates the application using the specified descriptor. - /// - /// The application. - /// The descriptor. - /// The that can be used to abort the operation. - /// - /// A that can be used to monitor the asynchronous operation. - /// - protected virtual async Task PopulateAsync([NotNull] TApplication application, - [NotNull] OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default) - { - if (application == null) - { - throw new ArgumentNullException(nameof(application)); - } - - if (descriptor == null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - - await Store.SetClientIdAsync(application, descriptor.ClientId, cancellationToken); - await Store.SetClientSecretAsync(application, descriptor.ClientSecret, cancellationToken); - await Store.SetClientTypeAsync(application, descriptor.Type, cancellationToken); - await Store.SetConsentTypeAsync(application, descriptor.ConsentType, cancellationToken); - await Store.SetDisplayNameAsync(application, descriptor.DisplayName, cancellationToken); - await Store.SetPermissionsAsync(application, ImmutableArray.CreateRange(descriptor.Permissions), cancellationToken); - await Store.SetPostLogoutRedirectUrisAsync(application, ImmutableArray.CreateRange( - descriptor.PostLogoutRedirectUris.Select(address => address.OriginalString)), cancellationToken); - await Store.SetRedirectUrisAsync(application, ImmutableArray.CreateRange( - descriptor.RedirectUris.Select(address => address.OriginalString)), cancellationToken); - } - /// /// Obfuscates the specified client secret so it can be safely stored in a database. /// By default, this method returns a complex hashed representation computed using PBKDF2. diff --git a/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs b/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs index 989f8242..fba23032 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs @@ -803,6 +803,66 @@ namespace OpenIddict.Core return Store.ListAsync(query, state, cancellationToken); } + /// + /// Populates the authorization using the specified descriptor. + /// + /// The authorization. + /// The descriptor. + /// The that can be used to abort the operation. + /// + /// A that can be used to monitor the asynchronous operation. + /// + public virtual async Task PopulateAsync([NotNull] TAuthorization authorization, + [NotNull] OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default) + { + if (authorization == null) + { + throw new ArgumentNullException(nameof(authorization)); + } + + if (descriptor == null) + { + throw new ArgumentNullException(nameof(descriptor)); + } + + await Store.SetApplicationIdAsync(authorization, descriptor.ApplicationId, cancellationToken); + await Store.SetScopesAsync(authorization, ImmutableArray.CreateRange(descriptor.Scopes), cancellationToken); + await Store.SetStatusAsync(authorization, descriptor.Status, cancellationToken); + await Store.SetSubjectAsync(authorization, descriptor.Subject, cancellationToken); + await Store.SetTypeAsync(authorization, descriptor.Type, cancellationToken); + } + + /// + /// Populates the specified descriptor using the properties exposed by the authorization. + /// + /// The descriptor. + /// The authorization. + /// The that can be used to abort the operation. + /// + /// A that can be used to monitor the asynchronous operation. + /// + public virtual async Task PopulateAsync( + [NotNull] OpenIddictAuthorizationDescriptor descriptor, + [NotNull] TAuthorization authorization, CancellationToken cancellationToken = default) + { + if (descriptor == null) + { + throw new ArgumentNullException(nameof(descriptor)); + } + + if (authorization == null) + { + throw new ArgumentNullException(nameof(authorization)); + } + + descriptor.ApplicationId = await Store.GetApplicationIdAsync(authorization, cancellationToken); + descriptor.Scopes.Clear(); + descriptor.Scopes.UnionWith(await Store.GetScopesAsync(authorization, cancellationToken)); + descriptor.Status = await Store.GetStatusAsync(authorization, cancellationToken); + descriptor.Subject = await Store.GetSubjectAsync(authorization, cancellationToken); + descriptor.Type = await Store.GetTypeAsync(authorization, cancellationToken); + } + /// /// Removes the ad-hoc authorizations that are marked as invalid or have no valid token attached. /// @@ -890,33 +950,24 @@ namespace OpenIddict.Core /// Updates an existing authorization. /// /// The authorization to update. - /// The delegate used to update the authorization based on the given descriptor. + /// The descriptor used to update the authorization. /// The that can be used to abort the operation. /// /// A that can be used to monitor the asynchronous operation. /// public virtual async Task UpdateAsync([NotNull] TAuthorization authorization, - [NotNull] Func operation, CancellationToken cancellationToken = default) + [NotNull] OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default) { - if (operation == null) + if (authorization == null) { - throw new ArgumentNullException(nameof(operation)); + throw new ArgumentNullException(nameof(authorization)); } - var descriptor = new OpenIddictAuthorizationDescriptor - { - ApplicationId = await Store.GetApplicationIdAsync(authorization, cancellationToken), - Status = await Store.GetStatusAsync(authorization, cancellationToken), - Subject = await Store.GetSubjectAsync(authorization, cancellationToken), - Type = await Store.GetTypeAsync(authorization, cancellationToken) - }; - - foreach (var scope in await Store.GetScopesAsync(authorization, cancellationToken)) + if (descriptor == null) { - descriptor.Scopes.Add(scope); + throw new ArgumentNullException(nameof(descriptor)); } - await operation(descriptor); await PopulateAsync(authorization, descriptor, cancellationToken); await UpdateAsync(authorization, cancellationToken); } @@ -984,34 +1035,5 @@ namespace OpenIddict.Core builder.MoveToImmutable() : builder.ToImmutable(); } - - /// - /// Populates the authorization using the specified descriptor. - /// - /// The authorization. - /// The descriptor. - /// The that can be used to abort the operation. - /// - /// A that can be used to monitor the asynchronous operation. - /// - protected virtual async Task PopulateAsync([NotNull] TAuthorization authorization, - [NotNull] OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default) - { - if (authorization == null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - if (descriptor == null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - - await Store.SetApplicationIdAsync(authorization, descriptor.ApplicationId, cancellationToken); - await Store.SetScopesAsync(authorization, ImmutableArray.CreateRange(descriptor.Scopes), cancellationToken); - await Store.SetStatusAsync(authorization, descriptor.Status, cancellationToken); - await Store.SetSubjectAsync(authorization, descriptor.Subject, cancellationToken); - await Store.SetTypeAsync(authorization, descriptor.Type, cancellationToken); - } } } \ No newline at end of file diff --git a/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs b/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs index 23ccb595..31b110a9 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs @@ -468,6 +468,64 @@ namespace OpenIddict.Core return set.ToImmutableArray(); } + /// + /// Populates the scope using the specified descriptor. + /// + /// The scope. + /// The descriptor. + /// The that can be used to abort the operation. + /// + /// A that can be used to monitor the asynchronous operation. + /// + public virtual async Task PopulateAsync([NotNull] TScope scope, + [NotNull] OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default) + { + if (scope == null) + { + throw new ArgumentNullException(nameof(scope)); + } + + if (descriptor == null) + { + throw new ArgumentNullException(nameof(descriptor)); + } + + await Store.SetDescriptionAsync(scope, descriptor.Description, cancellationToken); + await Store.SetDisplayNameAsync(scope, descriptor.DisplayName, cancellationToken); + await Store.SetNameAsync(scope, descriptor.Name, cancellationToken); + await Store.SetResourcesAsync(scope, descriptor.Resources.ToImmutableArray(), cancellationToken); + } + + /// + /// Populates the specified descriptor using the properties exposed by the scope. + /// + /// The descriptor. + /// The scope. + /// The that can be used to abort the operation. + /// + /// A that can be used to monitor the asynchronous operation. + /// + public virtual async Task PopulateAsync( + [NotNull] OpenIddictScopeDescriptor descriptor, + [NotNull] TScope scope, CancellationToken cancellationToken = default) + { + if (descriptor == null) + { + throw new ArgumentNullException(nameof(descriptor)); + } + + if (scope == null) + { + throw new ArgumentNullException(nameof(scope)); + } + + descriptor.Description = await Store.GetDescriptionAsync(scope, cancellationToken); + descriptor.DisplayName = await Store.GetDisplayNameAsync(scope, cancellationToken); + descriptor.Name = await Store.GetNameAsync(scope, cancellationToken); + descriptor.Resources.Clear(); + descriptor.Resources.UnionWith(await Store.GetResourcesAsync(scope, cancellationToken)); + } + /// /// Updates an existing scope. /// @@ -496,29 +554,24 @@ namespace OpenIddict.Core /// Updates an existing scope. /// /// The scope to update. - /// The delegate used to update the scope based on the given descriptor. + /// The descriptor used to update the scope. /// The that can be used to abort the operation. /// /// A that can be used to monitor the asynchronous operation. /// public virtual async Task UpdateAsync([NotNull] TScope scope, - [NotNull] Func operation, CancellationToken cancellationToken = default) + [NotNull] OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default) { - if (operation == null) + if (scope == null) { - throw new ArgumentNullException(nameof(operation)); + throw new ArgumentNullException(nameof(scope)); } - var descriptor = new OpenIddictScopeDescriptor + if (descriptor == null) { - Description = await Store.GetDescriptionAsync(scope, cancellationToken), - DisplayName = await Store.GetDisplayNameAsync(scope, cancellationToken), - Name = await Store.GetNameAsync(scope, cancellationToken) - }; - - descriptor.Resources.UnionWith(await Store.GetResourcesAsync(scope, cancellationToken)); + throw new ArgumentNullException(nameof(descriptor)); + } - await operation(descriptor); await PopulateAsync(scope, descriptor, cancellationToken); await UpdateAsync(scope, cancellationToken); } @@ -574,33 +627,5 @@ namespace OpenIddict.Core builder.MoveToImmutable() : builder.ToImmutable(); } - - /// - /// Populates the scope using the specified descriptor. - /// - /// The scope. - /// The descriptor. - /// The that can be used to abort the operation. - /// - /// A that can be used to monitor the asynchronous operation. - /// - protected virtual async Task PopulateAsync([NotNull] TScope scope, - [NotNull] OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default) - { - if (scope == null) - { - throw new ArgumentNullException(nameof(scope)); - } - - if (descriptor == null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - - await Store.SetDescriptionAsync(scope, descriptor.Description, cancellationToken); - await Store.SetDisplayNameAsync(scope, descriptor.DisplayName, cancellationToken); - await Store.SetNameAsync(scope, descriptor.Name, cancellationToken); - await Store.SetResourcesAsync(scope, descriptor.Resources.ToImmutableArray(), cancellationToken); - } } } \ No newline at end of file diff --git a/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs b/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs index e97ef7ac..5a5fc637 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs @@ -693,6 +693,73 @@ namespace OpenIddict.Core } } + /// + /// Populates the token using the specified descriptor. + /// + /// The token. + /// The descriptor. + /// The that can be used to abort the operation. + /// + /// A that can be used to monitor the asynchronous operation. + /// + public virtual async Task PopulateAsync([NotNull] TToken token, + [NotNull] OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default) + { + if (token == null) + { + throw new ArgumentNullException(nameof(token)); + } + + if (descriptor == null) + { + throw new ArgumentNullException(nameof(descriptor)); + } + + await Store.SetApplicationIdAsync(token, descriptor.ApplicationId, cancellationToken); + await Store.SetAuthorizationIdAsync(token, descriptor.AuthorizationId, cancellationToken); + await Store.SetCreationDateAsync(token, descriptor.CreationDate, cancellationToken); + await Store.SetExpirationDateAsync(token, descriptor.ExpirationDate, cancellationToken); + await Store.SetPayloadAsync(token, descriptor.Payload, cancellationToken); + await Store.SetReferenceIdAsync(token, descriptor.ReferenceId, cancellationToken); + await Store.SetStatusAsync(token, descriptor.Status, cancellationToken); + await Store.SetSubjectAsync(token, descriptor.Subject, cancellationToken); + await Store.SetTokenTypeAsync(token, descriptor.Type, cancellationToken); + } + + /// + /// Populates the specified descriptor using the properties exposed by the token. + /// + /// The descriptor. + /// The token. + /// The that can be used to abort the operation. + /// + /// A that can be used to monitor the asynchronous operation. + /// + public virtual async Task PopulateAsync( + [NotNull] OpenIddictTokenDescriptor descriptor, + [NotNull] TToken token, CancellationToken cancellationToken = default) + { + if (descriptor == null) + { + throw new ArgumentNullException(nameof(descriptor)); + } + + if (token == null) + { + throw new ArgumentNullException(nameof(token)); + } + + descriptor.ApplicationId = await Store.GetApplicationIdAsync(token, cancellationToken); + descriptor.AuthorizationId = await Store.GetAuthorizationIdAsync(token, cancellationToken); + descriptor.CreationDate = await Store.GetCreationDateAsync(token, cancellationToken); + descriptor.ExpirationDate = await Store.GetExpirationDateAsync(token, cancellationToken); + descriptor.Payload = await Store.GetPayloadAsync(token, cancellationToken); + descriptor.ReferenceId = await Store.GetReferenceIdAsync(token, cancellationToken); + descriptor.Status = await Store.GetStatusAsync(token, cancellationToken); + descriptor.Subject = await Store.GetSubjectAsync(token, cancellationToken); + descriptor.Type = await Store.GetTokenTypeAsync(token, cancellationToken); + } + /// /// Removes the tokens that are marked as expired or invalid. /// @@ -815,33 +882,24 @@ namespace OpenIddict.Core /// Updates an existing token. /// /// The token to update. - /// The delegate used to update the token based on the given descriptor. + /// The descriptor used to update the token. /// The that can be used to abort the operation. /// /// A that can be used to monitor the asynchronous operation. /// public virtual async Task UpdateAsync([NotNull] TToken token, - [NotNull] Func operation, CancellationToken cancellationToken = default) + [NotNull] OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default) { - if (operation == null) + if (token == null) { - throw new ArgumentNullException(nameof(operation)); + throw new ArgumentNullException(nameof(token)); } - var descriptor = new OpenIddictTokenDescriptor + if (descriptor == null) { - ApplicationId = await Store.GetApplicationIdAsync(token, cancellationToken), - AuthorizationId = await Store.GetAuthorizationIdAsync(token, cancellationToken), - CreationDate = await Store.GetCreationDateAsync(token, cancellationToken), - ExpirationDate = await Store.GetExpirationDateAsync(token, cancellationToken), - Payload = await Store.GetPayloadAsync(token, cancellationToken), - ReferenceId = await Store.GetReferenceIdAsync(token, cancellationToken), - Status = await Store.GetStatusAsync(token, cancellationToken), - Subject = await Store.GetSubjectAsync(token, cancellationToken), - Type = await Store.GetTokenTypeAsync(token, cancellationToken) - }; + throw new ArgumentNullException(nameof(descriptor)); + } - await operation(descriptor); await PopulateAsync(token, descriptor, cancellationToken); await UpdateAsync(token, cancellationToken); } @@ -910,38 +968,5 @@ namespace OpenIddict.Core builder.MoveToImmutable() : builder.ToImmutable(); } - - /// - /// Populates the token using the specified descriptor. - /// - /// The token. - /// The descriptor. - /// The that can be used to abort the operation. - /// - /// A that can be used to monitor the asynchronous operation. - /// - protected virtual async Task PopulateAsync([NotNull] TToken token, - [NotNull] OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default) - { - if (token == null) - { - throw new ArgumentNullException(nameof(token)); - } - - if (descriptor == null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - - await Store.SetApplicationIdAsync(token, descriptor.ApplicationId, cancellationToken); - await Store.SetAuthorizationIdAsync(token, descriptor.AuthorizationId, cancellationToken); - await Store.SetCreationDateAsync(token, descriptor.CreationDate, cancellationToken); - await Store.SetExpirationDateAsync(token, descriptor.ExpirationDate, cancellationToken); - await Store.SetPayloadAsync(token, descriptor.Payload, cancellationToken); - await Store.SetReferenceIdAsync(token, descriptor.ReferenceId, cancellationToken); - await Store.SetStatusAsync(token, descriptor.Status, cancellationToken); - await Store.SetSubjectAsync(token, descriptor.Subject, cancellationToken); - await Store.SetTokenTypeAsync(token, descriptor.Type, cancellationToken); - } } } \ No newline at end of file