Пример #1
0
        /// <summary>
        /// Creates a new token.
        /// </summary>
        /// <param name="token">The token 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 token.
        /// </returns>
        public virtual async Task <OpenIddictToken> CreateAsync(OpenIddictToken token, CancellationToken cancellationToken)
        {
            if (token == null)
            {
                throw new ArgumentNullException(nameof(token));
            }

            if (String.IsNullOrWhiteSpace(token.Id))
            {
                token.Id = Guid.NewGuid().ToString("N");
            }

            await _dynamoDb.PutItemAsync(TableName, new Dictionary <string, AttributeValue> {
                { "Id", new AttributeValue {
                      S = token.Id
                  } },
                { "Subject", new AttributeValue {
                      S = token.Subject
                  } },
                { "Type", new AttributeValue {
                      S = token.Type
                  } },
                { "ApplicationId", DynamoDBHelper.CreateAttributeVale(token.ApplicationId) },
                { "AuthorizationId", DynamoDBHelper.CreateAttributeVale(token.AuthorizationId) }
            });

            return(token);
        }
Пример #2
0
        public async Task <IdentityResult> CreateAsync(UserInfo user, CancellationToken cancellationToken)
        {
            var request = new UpdateItemRequest
            {
                Key = new Dictionary <string, AttributeValue>()
                {
                    { "Id", new AttributeValue {
                          N = "-1"
                      } }
                },
                ExpressionAttributeValues = new Dictionary <string, AttributeValue>()
                {
                    { ":incr", new AttributeValue {
                          N = "1"
                      } }
                },
                UpdateExpression = "SET UserCounter = UserCounter + :incr",
                TableName        = "Users",
                ReturnValues     = "UPDATED_NEW" // Give me all attributes of the updated item.
            };
            var response = await _dynamoDb.UpdateItemAsync(request);

            var userId = response.Attributes["UserCounter"].N;

            await _dynamoDb.PutItemAsync("Users", new Dictionary <string, AttributeValue>
            {
                { "Id", new AttributeValue {
                      N = userId
                  } },
                { "UserName", new AttributeValue(user.UserName) },
                { "Email", new AttributeValue(user.Email) },
                { "PasswordHash", new AttributeValue(user.PasswordHash) }
            },
                                         cancellationToken);

            user.Id = userId;

            return(IdentityResult.Success);
        }