Пример #1
0
        public async Task SaveTokenSet(string athleteId, string accessToken, string refreshToken, DateTime accessTokenExpiresAtUtc)
        {
            AccessTokenTableEntity byAthelete = new AccessTokenTableEntity
            {
                AccessToken               = accessToken,
                AccessTokenExpiryUtc      = accessTokenExpiresAtUtc,
                AthleteId                 = athleteId,
                PartitionKey              = AccessTokenTableEntity.GetPartitionKeyByAthleteId(athleteId),
                RefreshToken              = refreshToken,
                RefreshTokenObtainedAtUtc = DateTime.UtcNow,
                RowKey = AccessTokenTableEntity.GetRowKeyByAthleteId()
            };
            AccessTokenTableEntity byAccessToken = new AccessTokenTableEntity
            {
                AccessToken               = accessToken,
                AccessTokenExpiryUtc      = accessTokenExpiresAtUtc,
                AthleteId                 = athleteId,
                PartitionKey              = AccessTokenTableEntity.GetPartitionKeyByAccessToken(accessToken),
                RefreshToken              = refreshToken,
                RefreshTokenObtainedAtUtc = DateTime.UtcNow,
                RowKey = AccessTokenTableEntity.GetRowKeyByAccessToken()
            };

            await Task.WhenAll(
                _byAtheleteIdTable.ExecuteAsync(TableOperation.InsertOrReplace(byAthelete)),
                _byAccessTokenTable.ExecuteAsync(TableOperation.InsertOrReplace(byAccessToken))
                );
        }
Пример #2
0
        public async Task <RepositoryEnrichedTokenSet> GetForAccessToken(string accessToken)
        {
            TableResult tableResult = await _byAccessTokenTable.ExecuteAsync(TableOperation.Retrieve <AccessTokenTableEntity>(
                                                                                 AccessTokenTableEntity.GetPartitionKeyByAccessToken(accessToken),
                                                                                 AccessTokenTableEntity.GetRowKeyByAccessToken()));

            if (tableResult != null)
            {
                AccessTokenTableEntity tableEntity = (AccessTokenTableEntity)tableResult.Result;
                return(CreatedEnrichedTokenSet(tableEntity));
            }

            return(null);
        }
Пример #3
0
        public async Task DeleteTokenSetForAccessToken(string existingAccessToken)
        {
            TableResult byAccessTokenTableResult = await _byAtheleteIdTable.ExecuteAsync(TableOperation.Retrieve <AccessTokenTableEntity>(
                                                                                             AccessTokenTableEntity.GetPartitionKeyByAccessToken(existingAccessToken),
                                                                                             AccessTokenTableEntity.GetRowKeyByAccessToken()));

            if (byAccessTokenTableResult != null)
            {
                AccessTokenTableEntity byAccessTokenTableEntity = (AccessTokenTableEntity)byAccessTokenTableResult.Result;
                TableResult            byAthleteTableResult     = await _byAtheleteIdTable.ExecuteAsync(TableOperation.Retrieve <AccessTokenTableEntity>(
                                                                                                            AccessTokenTableEntity.GetPartitionKeyByAthleteId(byAccessTokenTableEntity.AthleteId),
                                                                                                            AccessTokenTableEntity.GetRowKeyByAthleteId()));

                if (byAthleteTableResult != null)
                {
                    AccessTokenTableEntity byAthleteTableEntity = (AccessTokenTableEntity)byAthleteTableResult.Result;
                    await _byAtheleteIdTable.ExecuteAsync(TableOperation.Delete(byAthleteTableEntity));
                }

                await _byAccessTokenTable.ExecuteAsync(TableOperation.Delete(byAccessTokenTableEntity));
            }
        }