Exemple #1
0
 public DataRepositoryGitFetcher(ILoggerFactory loggerFactory, IProcessRunner runner, IFileHasher fileHasher, ICredentialHelper credentialHelper)
 {
     this.logger           = loggerFactory.CreateLogger <DataRepositoryGitFetcher>();
     this.runner           = runner;
     this.fileHasher       = fileHasher;
     this.credentialHelper = credentialHelper;
 }
        public AudioticaService(
            ICredentialHelper credentialHelper,
            IAppSettingsHelper appSettingsHelper,
            IDispatcherHelper dispatcherHelper,
            INotificationManager notificationManager)
        {
            _credentialHelper    = credentialHelper;
            _appSettingsHelper   = appSettingsHelper;
            _dispatcherHelper    = dispatcherHelper;
            _notificationManager = notificationManager;

            var cred = _credentialHelper.GetCredentials("AudioticaCloud");

            if (cred == null)
            {
                return;
            }

            AuthenticationToken = cred.GetPassword();

            CurrentUser = _appSettingsHelper.ReadJsonAs <AudioticaUser>("AudioticaCloudUser");

            var refreshCred = _credentialHelper.GetCredentials("AudioticaCloudRefreshToken");

            if (refreshCred == null)
            {
                return;
            }

            _refreshToken = refreshCred.GetPassword();
        }
Exemple #3
0
        public async Task <SecretCredential> LookupAsync(string credentialSpec, ICredentialHelper credentialHelper)
        {
            var specAndUrl = credentialSpec.Split(':', 2);

            if (specAndUrl.Length != 2)
            {
                throw new ArgumentOutOfRangeException(nameof(credentialSpec));
            }

            var spec     = specAndUrl[0];
            var resource = specAndUrl[1];

            if (spec != Protocol)
            {
                throw new NotImplementedException($"spec {spec} not {Protocol}");
            }

            var url = $"http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource={resource}";

            this.logger.LogInformation($"GET {url}");
            using var request = new HttpRequestMessage(HttpMethod.Get, url);
            request.Headers.Add("Metadata", "true");
            using var response = await this.client.SendAsync(request);

            response.EnsureSuccessStatusCode();
            var tokenJson = await response.Content.ReadAsStringAsync();

            var accessToken      = ReadJsonValue(tokenJson, "access_token");
            var expiresInString  = ReadJsonValue(tokenJson, "expires_in");
            var expiresInSeconds = long.Parse(expiresInString);
            var expiry           = TimeSpan.FromSeconds(expiresInSeconds);

            return(new SecretCredential(accessToken, this.clock.Get() + expiry));
        }
Exemple #4
0
        public async Task <SecretCredential> LookupAsync(string credentialSpec, ICredentialHelper credentialHelper)
        {
            var specSplits = credentialSpec.Split(':', 3);

            if (specSplits.Length != 3)
            {
                throw new ArgumentOutOfRangeException(nameof(credentialSpec));
            }

            var spec     = specSplits[0];
            var kvName   = specSplits[1];
            var kvSecret = specSplits[2];

            if (spec != Protocol)
            {
                throw new NotImplementedException($"spec {spec} not {Protocol}");
            }

            var kvResourceUrl = "https://vault.azure.net";
            var accessToken   = await credentialHelper.LookupAsync($"{CredentialProviderForAzureManagedIdentity.ProtocolName}:{kvResourceUrl}");

            var requestUrl = $"https://{kvName}.vault.azure.net/secrets/{kvSecret}?api-version=7.0";

            this.logger.LogInformation($"GET {requestUrl}");
            using var request             = new HttpRequestMessage(HttpMethod.Get, requestUrl);
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken.Secret);
            using var response            = await this.client.SendAsync(request);

            response.EnsureSuccessStatusCode();
            var secretJson = await response.Content.ReadAsStringAsync();

            var value = ReadJsonValue(secretJson, "value");

            return(new SecretCredential(value, this.clock.Get() + SecretCacheTimeout));
        }
Exemple #5
0
 public SettingViewModel(IAppSettingsHelper _helper, ICredentialHelper credential)
 {
     _appSettingsHelper = _helper;
     _credential        = credential;
     //LoginClickRelay = new Command(LoginButtonClicked);
     Glyph = "\uE1E2";
     LoginAsync();
 }
 public ScrobblerService(ICredentialHelper credentialHelper)
 {
     _credentialHelper = credentialHelper;
     _auth = new LastAuth(ApiKeys.LastFmId, ApiKeys.LastFmSecret);
     _albumApi = new AlbumApi(_auth);
     _artistApi = new ArtistApi(_auth);
     _chartApi = new ChartApi(_auth);
     _trackApi = new TrackApi(_auth);
     _userApi = new UserApi(_auth);
     GetSessionTokenAsync();
 }
 public ScrobblerService(ICredentialHelper credentialHelper)
 {
     _credentialHelper = credentialHelper;
     _auth             = new LastAuth(ApiKeys.LastFmId, ApiKeys.LastFmSecret);
     _albumApi         = new AlbumApi(_auth);
     _artistApi        = new ArtistApi(_auth);
     _chartApi         = new ChartApi(_auth);
     _trackApi         = new TrackApi(_auth);
     _userApi          = new UserApi(_auth);
     GetSessionTokenAsync();
 }
        public SettingsViewModel(IScrobblerService service, ICredentialHelper credentialHelper, IAppSettingsHelper appSettingsHelper)
        {
            _service = service;
            _appSettingsHelper = appSettingsHelper;
            LoginClickRelay = new RelayCommand(LoginButtonClicked);
            DeveloperModeClickRelay = new RelayCommand(DeveloperModeExecute);

            var creds = credentialHelper.GetCredentials("lastfm");
            if (creds == null) return;

            LastFmUsername = creds.GetUsername();
            LastFmPassword = creds.GetPassword();
            IsLoggedIn = true;
        }
Exemple #9
0
        public async Task <SecretCredential> LookupAsync(string credentialSpec, ICredentialHelper credentialHelper)
        {
            var specSplits = credentialSpec.Split(':', 4);

            if (specSplits.Length != 4)
            {
                throw new ArgumentOutOfRangeException(nameof(credentialSpec));
            }

            var spec             = specSplits[0];
            var resource         = specSplits[1];
            var clientId         = specSplits[2];
            var clientSecretSpec = specSplits[3];

            if (spec != Protocol)
            {
                throw new NotImplementedException($"spec {spec} not {Protocol}");
            }

            var clientSecret = await credentialHelper.LookupAsync(clientSecretSpec);

            var requestUrl = $"https://app.vssps.visualstudio.com/oauth2/token";

            this.logger.LogInformation($"POST {requestUrl}");
            using var request = new HttpRequestMessage(HttpMethod.Post, requestUrl);
            var postBody = new List <KeyValuePair <string?, string?> >()
            {
                new KeyValuePair <string?, string?>("grant_type", "client_credentials"),
                new KeyValuePair <string?, string?>("scope", "vso.code"),
                new KeyValuePair <string?, string?>("client_id", clientId),
                new KeyValuePair <string?, string?>("client_secret", clientSecret.Secret),
                new KeyValuePair <string?, string?>("resource", resource),
            };

            request.Content = new FormUrlEncodedContent(postBody);
            request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("applicaiton/json"));
            using var response = await this.client.SendAsync(request);

            response.EnsureSuccessStatusCode();
            var secretJson = await response.Content.ReadAsStringAsync();

            var accessToken     = ReadJsonValue(secretJson, "access_token");
            var expiresInString = ReadJsonValue(secretJson, "expires_in");
            var expiresIn       = long.Parse(expiresInString);
            var expires         = this.clock.Get() + TimeSpan.FromSeconds(expiresIn);

            return(new SecretCredential($"bearer {accessToken}", expires));
        }
Exemple #10
0
        public SettingsViewModel(IScrobblerService service, ICredentialHelper credentialHelper, IAppSettingsHelper appSettingsHelper)
        {
            _service                = service;
            _appSettingsHelper      = appSettingsHelper;
            LoginClickRelay         = new RelayCommand(LoginButtonClicked);
            DeveloperModeClickRelay = new RelayCommand(DeveloperModeExecute);

            var creds = credentialHelper.GetCredentials("lastfm");

            if (creds == null)
            {
                return;
            }

            LastFmUsername = creds.GetUsername();
            LastFmPassword = creds.GetPassword();
            IsLoggedIn     = true;
        }
Exemple #11
0
        public Task <SecretCredential> LookupAsync(string credentialSpec, ICredentialHelper credentialHelper)
        {
            var specAndUrl = credentialSpec.Split(':', 2);

            if (specAndUrl.Length != 2)
            {
                throw new ArgumentOutOfRangeException(nameof(credentialSpec));
            }

            var spec = specAndUrl[0];
            var url  = specAndUrl[1];

            if (spec != EnvSecret)
            {
                throw new NotImplementedException($"spec {spec} not {EnvSecret}");
            }

            // expire very far in the future (using MaxValue could cause unintended overflows)
            return(Task.FromResult(new SecretCredential(Environment.GetEnvironmentVariable(url) ?? string.Empty, DateTimeOffset.FromUnixTimeSeconds(4_000_000_000))));
        }
Exemple #12
0
 public AccountService(IHttpClientHelper httpClientHelper, ICredentialHelper credentialHelper)
 {
     _httpClientHelper = httpClientHelper;
     _httpClient       = InitHttpClient(credentialHelper.GetCredential());
 }
 public AudioticaService(
     ICredentialHelper credentialHelper,
     IAppSettingsHelper appSettingsHelper) : this(credentialHelper, appSettingsHelper, null, null)
 {
 }
Exemple #14
0
 public SecretWriter(ILoggerFactory loggerFactory, IOptions <SecretWriterOptions> options, ICredentialHelper credentialHelper)
 {
     this.logger           = loggerFactory.CreateLogger <SecretWriter>();
     this.options          = options;
     this.credentialHelper = credentialHelper;
 }