/// <summary> /// Creates a new authorization. /// </summary> /// <param name="authorization">The authorization to create.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param> /// <returns> /// A <see cref="Task"/> that can be used to monitor the asynchronous operation, whose result returns the authorization. /// </returns> public virtual async Task <OpenIddictAuthorization> CreateAsync(OpenIddictAuthorization authorization, CancellationToken cancellationToken) { if (authorization == null) { throw new ArgumentNullException(nameof(authorization)); } if (String.IsNullOrWhiteSpace(authorization.Id)) { authorization.Id = Guid.NewGuid().ToString("N"); } await _dynamoDb.PutItemAsync(DBName, new Dictionary <string, AttributeValue> { { "Id", new AttributeValue { S = authorization.Id } }, { "Subject", new AttributeValue { S = authorization.Subject } }, { "Scope", new AttributeValue { S = authorization.Scope } }, { "ApplicationId", DynamoDBHelper.CreateAttributeVale(authorization.ApplicationId) } }); return(authorization); }
/// <summary> /// Updates an existing token. /// </summary> /// <param name="token">The token to update.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param> /// <returns> /// A <see cref="Task"/> that can be used to monitor the asynchronous operation. /// </returns> public virtual async Task UpdateAsync(OpenIddictToken token, CancellationToken cancellationToken) { if (token == null) { throw new ArgumentNullException(nameof(token)); } await _dynamoDb.UpdateItemAsync(TableName, new Dictionary <string, AttributeValue> { { "Id", new AttributeValue(token.Id) }, }, new Dictionary <string, AttributeValueUpdate> { { "ApplicationId", new AttributeValueUpdate(DynamoDBHelper.CreateAttributeVale(token.ApplicationId), AttributeAction.PUT) }, { "AuthorizationId", new AttributeValueUpdate(DynamoDBHelper.CreateAttributeVale(token.AuthorizationId), AttributeAction.PUT) }, { "Subject", new AttributeValueUpdate(new AttributeValue(token.Subject), AttributeAction.PUT) }, { "Type", new AttributeValueUpdate(new AttributeValue(token.Type), AttributeAction.PUT) } }); }