Exemple #1
0
        public async Task <bool> UpdateCacheKey(string partition, string old, string now)
        {
            var op     = TableOperation.Retrieve <TableTokenCacheItem>(partition, old);
            var result = await _table.ExecuteAsync(op).ConfigureAwait(true);

            if (result.HttpStatusCode < 300)
            {
                var oldItem = result.Result as TableTokenCacheItem;

                var newItem = new TableTokenCacheItem()
                {
                    PartitionKey = oldItem.PartitionKey,
                    RowKey       = now,
                    TokenData    = oldItem.TokenData,
                };
                var insert = await _table.ExecuteAsync(TableOperation.Insert(newItem)).ConfigureAwait(true);

                if (insert.HttpStatusCode < 300)
                {
                    var delete = await _table.ExecuteAsync(TableOperation.Delete(oldItem)).ConfigureAwait(true);

                    return(delete.HttpStatusCode < 300);
                }
            }
            return(false);
        }
Exemple #2
0
        public void AfterAccess(TokenCacheNotificationArgs args)
        {
            if (string.IsNullOrEmpty(_userCacheKey))
            {
                throw new ArgumentNullException(_userCacheKey);
            }
            _log.LogInformation($"AfterAccess; {_userCacheKey}, {args.ClientId}, State change? {args.HasStateChanged}");

            if (args.HasStateChanged)
            {
                var entity = new TableTokenCacheItem()
                {
                    PartitionKey = args.ClientId,
                    RowKey       = args.IsApplicationCache ? args.ClientId : _userCacheKey,
                    TokenData    = Convert.ToBase64String(args.TokenCache.SerializeMsalV3())
                };
                var op     = TableOperation.InsertOrReplace(entity);
                var result = _table.ExecuteAsync(op).Result;

                _log.LogInformation($"AfterAccess; {_userCacheKey}, {args.ClientId}, result {result.HttpStatusCode}");
            }
        }