Ejemplo n.º 1
0
        public override async Task AuthenticateAsync(IConnection connection, CancellationToken cancellationToken = default)
        {
            using var op = new SaslStart
                  {
                      Key        = MechanismType.GetDescription(),
                      Content    = GetAuthData(_username, _password),
                      Opaque     = SequenceGenerator.GetNext(),
                      Transcoder = new LegacyTranscoder()
                  };

            await SendAsync(op, connection, cancellationToken);
        }
 public override async Task AuthenticateAsync(IConnection connection, CancellationToken cancellationToken = default)
 {
     using var rootSpan = Tracer.RootSpan(CouchbaseTags.Service, OperationNames.AuthenticatePlain);
     using var op       = new SaslStart
           {
               Key     = MechanismType.GetDescription(),
               Content = GetAuthData(_username, _password),
               Opaque  = SequenceGenerator.GetNext(),
               Span    = rootSpan,
           };
     OperationConfigurator.Configure(op, SaslOptions.Instance);
     await SendAsync(op, connection, cancellationToken).ConfigureAwait(false);
 }
Ejemplo n.º 3
0
        public async Task <bool> AuthenticateAsync(IConnection connection, CancellationToken cancellationToken = default)
        {
            var tcs = new TaskCompletionSource <bool>();

            using var op = new SaslStart
                  {
                      Key        = MechanismType,
                      Content    = GetAuthData(Username, Password),
                      Opaque     = SequenceGenerator.GetNext(),
                      Transcoder = new DefaultTranscoder(),
                      Completed  = s =>
                      {
                          //Status will be AuthenticationError if auth failed otherwise false
                          tcs.TrySetResult(s.Status == ResponseStatus.Success);
                          return(tcs.Task);
                      }
                  };

            IDisposable?cancellationTokenRegistration = null;

            if (cancellationToken.CanBeCanceled)
            {
                // Not the default, so register the callback

                cancellationTokenRegistration = cancellationToken.Register(() =>
                {
                    tcs.TrySetCanceled(cancellationToken);
                });
            }

            try
            {
                await op.SendAsync(connection).ConfigureAwait(false);

                return(await tcs.Task.ConfigureAwait(false));
            }
            finally
            {
                cancellationTokenRegistration?.Dispose();
            }
        }
Ejemplo n.º 4
0
        public async Task <bool> AuthenticateAsync(IConnection connection)
        {
            var tcs = new TaskCompletionSource <bool>();

            using (var op = new SaslStart
            {
                Key = MechanismType,
                Content = GetAuthData(Username, Password),
                Opaque = SequenceGenerator.GetNext(),
                Converter = new DefaultConverter(),
                Transcoder = new DefaultTranscoder(new DefaultConverter()),
                Completed = s =>
                {
                    //Status will be AuthenticationError if auth failed otherwise false
                    tcs.TrySetResult(s.Status == ResponseStatus.Success);
                    return(tcs.Task);
                }
            })
            {
                await op.SendAsync(connection).ConfigureAwait(false);

                return(await tcs.Task.ConfigureAwait(false));
            }
        }