/// <summary>
        /// Refreshes the token.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <returns></returns>
        protected internal override async Task <bool> ReauthorizeAsync(IBaseApiRequestor client)
        {
            // Check an access token is provided before attempting.
            if (string.IsNullOrEmpty(_refreshToken))
            {
                return(false);
            }

            // Create the form data
            var exchangeContent = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("client_id", _clientID),
                new KeyValuePair <string, string>("client_secret", _clientSecret),
                new KeyValuePair <string, string>("grant_type", "refresh_token"),
                new KeyValuePair <string, string>("refresh_token", _refreshToken)
            });

            // Create the client
            BaseApiClient authorizationClient = new ApiClient();

            // Make request
            try
            {
                OAuth2TokenResponseEntity response = await authorizationClient.RequestJsonSerializedWithFormDataAsync <OAuth2TokenResponseEntity>(HttpMethod.Post, $"{_baseUrl ?? DefaultUrl}/token", exchangeContent, default(CancellationToken));

                _accessToken  = response.AccessToken;
                _refreshToken = response.RefreshToken;

                return(true);
            } catch (Exception) {
                return(false);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Creates a user operations object.
 /// </summary>
 /// <param name="client">The client.</param>
 protected internal UserOperations(IBaseApiRequestor client)
 {
     _client = client;
 }
 /// <summary>
 /// No support for refresh tokens.
 /// </summary>
 /// <param name="client">The client.</param>
 /// <returns></returns>
 protected internal override Task <bool> ReauthorizeAsync(IBaseApiRequestor client)
 {
     return(Task.FromResult(false));
 }
 /// <summary>
 /// Attempt to refresh the authorization.
 /// </summary>
 /// <param name="client">The client.</param>
 /// <returns>If the request should be attempted again.</returns>
 protected internal abstract Task <bool> ReauthorizeAsync(IBaseApiRequestor client);
Esempio n. 5
0
 public SoundOperations(IBaseApiRequestor client)
 {
     _client = client;
 }
Esempio n. 6
0
 public AdminOperations(IBaseApiRequestor client)
 {
     _client = client;
 }