public BackblazeB2Client( string accountId, SecureString applicationKey, BackblazeConnectionInfo connectionInfo) { this.accountId = accountId; this.applicationKey = applicationKey; this.connectionInfo = connectionInfo; Assembly assembly = Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly(); this.userAgentString = string.Format( "SyncPro/{0}", assembly.GetName().Version); }
private async Task AuthorizeAccount() { HttpRequestMessage request = CreateRequestMessage( HttpMethod.Get, Constants.DefaultApiUrl + Constants.ApiAuthorizeAccountUrl); request.Headers.Authorization = new AuthenticationHeaderValue( "Basic", Convert.ToBase64String( Encoding.UTF8.GetBytes( this.accountId + ":" + this.applicationKey.GetDecrytped()))); LogApiCallCounter(request); using (HttpResponseMessage response = await this.httpClient.SendAsync(request).ConfigureAwait(false)) { await ThrowIfFatalResponse(response).ConfigureAwait(false); JObject responseObject = await response.Content.ReadAsJObjectAsync().ConfigureAwait(false); this.connectionInfo?.Dispose(); this.connectionInfo = new BackblazeConnectionInfo { AuthorizationToken = SecureStringExtensions.FromString( responseObject.Value <string>("authorizationToken")), ApiUrl = responseObject.Value <string>("apiUrl"), DownloadUrl = responseObject.Value <string>("downloadUrl"), RecommendedPartSize = responseObject.Value <int>("recommendedPartSize"), AbsoluteMinimumPartSize = responseObject.Value <int>("absoluteMinimumPartSize"), WhenAcquired = DateTime.UtcNow, }; this.ConnectionInfoChanged?.Invoke( this, new ConnectionInfoChangedEventArgs { AccountId = this.accountId, ConnectionInfo = this.connectionInfo }); } }