Exemple #1
0
        private void Capture(string authorityUrl, CapturedAdalInput input, object output)
        {
            if (authorityUrl is null)
            {
                throw new ArgumentNullException(nameof(authorityUrl));
            }

            _context.Trace.WriteLine($"{nameof(CaptureAdal)}: \"{nameof(authorityUrl)}\".");

            lock (_syncpoint)
            {
                var capture = new CapturedAdalOperation
                {
                    AuthorityUrl = authorityUrl,
                    Input        = input,
                };

                if (output is Exception error)
                {
                    capture.Error = new CapturedAdalException
                    {
                        Message = error.Message,
                    };
                }
                else if (output is IAdalResult result)
                {
                    capture.Result = new CapturedAdalResult
                    {
                        AccessToken = capture.Result.AccessToken,
                        Authority   = result.Authority,
                        TenantId    = result.TenantId,
                        TokenType   = result.AccessTokenType,
                    };
                }

                _captures.Add(capture);
            }
        }
Exemple #2
0
        internal bool TryGetNextOperation(string authorityUrl, out CapturedAdalOperation operation)
        {
            if (authorityUrl != null)
            {
                if (_captures.TryGetValue(authorityUrl, out var queue) &&
                    queue.Count > 0)
                {
                    if (!_replayed.TryGetValue(authorityUrl, out var replayed))
                    {
                        replayed = new Queue <CapturedAdalOperation>(queue.Count);

                        _replayed.Add(authorityUrl, replayed);
                    }

                    operation = queue.Dequeue();
                    replayed.Enqueue(operation);

                    return(true);
                }
            }

            operation = default(CapturedAdalOperation);
            return(false);
        }