Exemplo n.º 1
0
 public static async Task <bool> LoginAsync(this IPersistentAccessToken token)
 {
     try
     {
         return((await token.CurrentAccessToken()).AccessToken != "");
     }
     catch (TokenAuthenticationException)
     {
         return(false);
     }
 }
Exemplo n.º 2
0
        private static async Task AttemptLogin(IPersistentAccessToken holder)
        {
            if (await holder.LoginAsync())
            {
                var token = await holder.CurrentAccessToken();

                Console.WriteLine("Token Obtained: " + token.AccessToken);
                Console.WriteLine("Token Expiration: " + token.ExpiresAt);
            }
            else
            {
                Console.WriteLine("Login Failed");
            }
        }
Exemplo n.º 3
0
 public HubLogConnection(TargetSite site)
 {
     connection = new HubConnectionBuilder()
                  .WithUrl(site.Url.TrimEnd('/', '\\') + "/MelvilleSpecialLoggingHubWellKnownUrl",
                           o => o.AccessTokenProvider = GetAccessToken)
                  .WithAutomaticReconnect()
                  .Build();
     disposeToStopReadingEvents = connection.On("SendEvent", (Action <string>)HandleLogEvent);
     if (site.Secret.Length > 0)
     {
         token = CapWebTokenFactory.CreateCapWebClient(site.Name, site.Secret);
     }
     connection.StartAsync();
 }
 public AuthenticatedHttpHandler(IPersistentAccessToken tokenHolder, HttpMessageHandler?innerHandler = null) :
     base(innerHandler ?? new HttpClientHandler())
 {
     this.tokenHolder = tokenHolder;
 }
Exemplo n.º 5
0
 public static async ValueTask AddBearerToken(this IPersistentAccessToken tokenSource, HttpClient client) =>
 client.SetBearerToken((await tokenSource.CurrentAccessToken()).AccessToken);
Exemplo n.º 6
0
 public static HttpClient AuthenticatedClient(this IPersistentAccessToken tokenSource,
                                              HttpMessageHandler?innerHandler = null) =>
 new HttpClient(new AuthenticatedHttpHandler(tokenSource, innerHandler));