コード例 #1
0
 public static void LoadAuthenticatedUserFromCache(ILoginMethods login, ISecureBlobCache loginCache)
 {
     Observable.Zip(loginCache.GetObjectAsync <string>("BaseUrl"), loginCache.GetObjectAsync <string>("Token"),
                    (url, name) => new Tuple <string, string>(url, name))
     .Catch(Observable.Return <Tuple <string, string> >(null))
     .Subscribe(x => {
     });
 }
コード例 #2
0
        /// <summary>
        /// Saves a username and password.
        /// </summary>
        /// <param name="blobCache">The blob cache to insert the item into.</param>
        /// <param name="user">The username to store.</param>
        /// <param name="password">The password to store.</param>
        /// <param name="host">The host to store against.</param>
        /// <param name="expiration">A timespan that will be added to the current DateTime.</param>
        /// <returns>A observable which will signal when the item is added.</returns>
        public static IObservable <Unit> SaveLogin(this ISecureBlobCache blobCache, string user, string password, string host, TimeSpan expiration)
        {
            if (blobCache is null)
            {
                throw new ArgumentNullException(nameof(blobCache));
            }

            return(blobCache.SaveLogin(user, password, host, blobCache.Scheduler.Now + expiration));
        }
コード例 #3
0
ファイル: BlobCache.cs プロジェクト: GavinHwa/Akavache
 static BlobCache()
 {
     if (RxApp.InUnitTestRunner())
     {
         localMachine = new TestBlobCache(RxApp.TaskpoolScheduler);
         userAccount = new TestBlobCache(RxApp.TaskpoolScheduler);
         secure = new TestBlobCache(RxApp.TaskpoolScheduler);
     }
 }
        private void GetSecretLocalMachineCache()
        {
            var secretCache = new Lazy <ISecureBlobCache>(() =>
            {
                _filesystemProvider.CreateRecursive(_filesystemProvider.GetDefaultSecretCacheDirectory()).SubscribeOn(BlobCache.TaskpoolScheduler).Wait();
                return(new SQLiteEncryptedBlobCache(Path.Combine(_filesystemProvider.GetDefaultSecretCacheDirectory(), "secret.db"), new PlatformCustomAkavacheEncryptionProvider(), BlobCache.TaskpoolScheduler));
            });

            this.SecretLocalMachineCache = secretCache.Value;
        }
コード例 #5
0
 protected SharedCache(IBlobCache userAccountCache, IBlobCache localMachineCache, ISecureBlobCache secureCache)
 {
     if (secureCache == null)
     {
         try
         {
             BlobCache.Secure = new CredentialCache();
             secureCache = BlobCache.Secure;
         }
         catch (Exception e)
         {
             log.Error("Failed to set up secure cache.", e);
             secureCache = new InMemoryBlobCache();
         }
     }
     UserAccount = userAccountCache ?? GetBlobCacheWithFallback(() => BlobCache.UserAccount, "UserAccount");
     LocalMachine = localMachineCache ?? GetBlobCacheWithFallback(() => BlobCache.LocalMachine, "LocalMachine");
     Secure = secureCache;
 }
コード例 #6
0
ファイル: SharedCache.cs プロジェクト: yj1995/VisualStudio
 protected SharedCache(IBlobCache userAccountCache, IBlobCache localMachineCache, ISecureBlobCache secureCache)
 {
     if (secureCache == null)
     {
         try
         {
             BlobCache.Secure = new CredentialCache();
             secureCache      = BlobCache.Secure;
         }
         catch (Exception e)
         {
             log.Error(e, "Failed to set up secure cache");
             secureCache = new InMemoryBlobCache();
         }
     }
     UserAccount  = userAccountCache ?? GetBlobCacheWithFallback(() => BlobCache.UserAccount, "UserAccount");
     LocalMachine = localMachineCache ?? GetBlobCacheWithFallback(() => BlobCache.LocalMachine, "LocalMachine");
     Secure       = secureCache;
 }
コード例 #7
0
        public SettingsService(ILogger logger = null, ISecureBlobCache secureBlobCache = null, IBlobCache localMachineCache = null)
        {
            _logger            = logger ?? Locator.Current.GetService <ILogger>();
            _secureBlobCache   = secureBlobCache ?? Locator.Current.GetService <ISecureBlobCache>();
            _localMachineCache = localMachineCache ?? Locator.Current.GetService <IBlobCache>();

            BaseApiUrl = @"http://test.test.no/api";
            var log = _logger.ForContext <SettingsService>();

            log.Information($"Instantiated: {nameof(SettingsService)}");

            // Check and set access token
            GetToken()
            .ToObservable()
            .LogException(log, "Unable to get access token")
            .Subscribe();

            _localMachineCache.GetObject <bool>(IsNewUserKey)
            .Catch <bool, Exception>(ex => Observable.Return(true))
            .Subscribe(newUser => IsNewUser = newUser);
        }
コード例 #8
0
 /// <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)));
 }
コード例 #9
0
 /// <summary>
 /// Save a user/password combination in a secure blob cache. Note that
 /// this method only allows exactly *one* user/pass combo to be saved,
 /// calling this more than once will overwrite the previous entry.
 /// </summary>
 /// <param name="blobCache">The blob cache where to store the data.</param>
 /// <param name="user">The user name to save.</param>
 /// <param name="password">The associated password.</param>
 /// <param name="host">The host to associate with the data.</param>
 /// <param name="absoluteExpiration">An optional expiration date.</param>
 /// <returns>A observable which signals when the insert is completed.</returns>
 public static IObservable <Unit> SaveLogin(this ISecureBlobCache blobCache, string user, string password, string host = "default", DateTimeOffset?absoluteExpiration = null)
 {
     return(blobCache.InsertObject("login:" + host, new Tuple <string, string>(user, password), absoluteExpiration));
 }
コード例 #10
0
        public GitHubCredentialProvider(ISharedCache sharedCache)
        {
            Guard.ArgumentNotNull(sharedCache, nameof(sharedCache));

            secureCache = sharedCache.Secure;
        }
コード例 #11
0
 public static void LoadAuthenticatedUserFromCache(ILoginMethods login, ISecureBlobCache loginCache)
 {
     Observable.Zip(loginCache.GetObjectAsync<string>("BaseUrl"), loginCache.GetObjectAsync<string>("Token"),
         (url, name) => new Tuple<string, string>(url, name))
         .Catch(Observable.Return<Tuple<string, string>>(null))
         .Subscribe(x => {
         });
 }
コード例 #12
0
 public static void SaveLogin(this ISecureBlobCache This, string user, string password, string host, TimeSpan expiration)
 {
     This.SaveLogin(user, password, host, This.Scheduler.Now + expiration);
 }
コード例 #13
0
 /// <summary>
 /// Erases the login associated with the specified host
 /// </summary>
 public static void EraseLogin(this ISecureBlobCache This, string host = "default")
 {
     This.InvalidateObject <Tuple <string, string> >("login:" + host);
 }
コード例 #14
0
 public GitHubCredentialProvider(ISharedCache sharedCache)
 {
     secureCache = sharedCache.Secure;
 }
コード例 #15
0
 /// <summary>
 /// Save a user/password combination in a secure blob cache. Note that
 /// this method only allows exactly *one* user/pass combo to be saved,
 /// calling this more than once will overwrite the previous entry.
 /// </summary>
 /// <param name="user">The user name to save.</param>
 /// <param name="password">The associated password</param>
 /// <param name="absoluteExpiration">An optional expiration date.</param>
 public static void SaveLogin(this ISecureBlobCache This, string user, string password, string host = "default", DateTimeOffset?absoluteExpiration = null)
 {
     This.InsertObject("login:" + host, new Tuple <string, string>(user, password), absoluteExpiration);
 }
コード例 #16
0
 /// <summary>
 /// Erases the login associated with the specified host.
 /// </summary>
 /// <param name="blobCache">The blob cache where to erase the data.</param>
 /// <param name="host">The host associated with the data.</param>
 /// <returns>A observable which signals when the erase is completed.</returns>
 public static IObservable <Unit> EraseLogin(this ISecureBlobCache blobCache, string host = "default")
 {
     return(blobCache.InvalidateObject <Tuple <string, string> >("login:" + host));
 }
コード例 #17
0
 public static IObservable <Unit> SaveLogin(this ISecureBlobCache This, string user, string password, string host, TimeSpan expiration)
 {
     return(This.SaveLogin(user, password, host, This.Scheduler.Now + expiration));
 }
コード例 #18
0
 public GitHubCredentialProvider(ISharedCache sharedCache)
 {
     secureCache = sharedCache.Secure;
 }