public async Task <AuthTokens> GetToken() { string accessToken = "", refreshToken = ""; try { if (string.IsNullOrEmpty(_accessToken)) { accessToken = await _secureBlobCache.GetObject <string>(AccessTokenKey); _accessToken = accessToken; } else { accessToken = _accessToken; } AccessToken = accessToken; } catch (Exception) { //var byteArray = Encoding.ASCII.GetBytes($"{Constants.App.ApiKeyUsername}:{Constants.App.ApiKeyPassword}"); //var token = Convert.ToBase64String(byteArray); //return new AuthTokens() //{ // AccessToken = token, // TokenType = "Basic" //}; } try { if (string.IsNullOrEmpty(_refreshToken)) { refreshToken = await _secureBlobCache.GetObject <string>(RefreshTokenKey); _refreshToken = refreshToken; } else { refreshToken = _refreshToken; } } catch { }; return(new AuthTokens { AccessToken = accessToken, TokenType = "Bearer", RefreshToken = refreshToken }); }
/// <summary> /// This is a callback from libgit2 /// </summary> /// <returns></returns> public Credentials HandleCredentials(string url, string username, SupportedCredentialTypes types) { if (url == null) { return(null); // wondering if we should return DefaultCredentials instead } var host = HostAddress.Create(url); return(secureCache.GetObject <Tuple <string, SecureString> >("login:" + host.CredentialCacheKeyHost) .Select(CreateCredentials) .Catch(Observable.Return <Credentials>(null)) .Wait()); }
/// <summary> /// Returns the currently cached user/password. If the cache does not /// contain a user/password, this returns an Observable which /// OnError's with KeyNotFoundException. /// </summary> /// <param name="blobCache">The blob cache where to get the data.</param> /// <param name="host">The host associated with the data.</param> /// <returns>A Future result representing the user/password Tuple.</returns> public static IObservable <LoginInfo> GetLoginAsync(this ISecureBlobCache blobCache, string host = "default") { return(blobCache.GetObject <Tuple <string, string> >("login:" + host).Select(x => new LoginInfo(x))); }