Example #1
0
        public BaseEndpoint(IOAuth2Wrapper oAuth2Wrapper, int retryMax)
        {
            if (oAuth2Wrapper.isAnonymous)
            {
                _client             = new HttpClient();
                _client.BaseAddress = oAuth2Wrapper.baseUri;
                _retry_max          = retryMax;
                _oAuth2Wrapper      = oAuth2Wrapper;
                return;
            }

            _oAuth2Wrapper = oAuth2Wrapper;
            _retry_max     = retryMax;

            if (_oAuth2Wrapper.isInitialized && _oAuth2Wrapper.tokenExpires > DateTime.UtcNow)
            {
                _token = _oAuth2Wrapper.accessToken;
            }
            else
            {
                _oAuth2Wrapper.isInitialized = _oAuth2Wrapper.GetBearTokenAsync().Result;
            }

            if (_oAuth2Wrapper.isInitialized)
            {
                _client             = new HttpClient();
                _client.BaseAddress = _oAuth2Wrapper.baseUri;
                _client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization",
                                                                      $"Bearer {_oAuth2Wrapper.accessToken}");
            }
        }
Example #2
0
        internal bool SignToken()
        {
            _oAuth2Wrapper.isInitialized = _oAuth2Wrapper.GetBearTokenAsync().Result;
            if (_oAuth2Wrapper.isInitialized)
            {
                _client.Dispose();

                _client             = new HttpClient();
                _client.BaseAddress = _oAuth2Wrapper.baseUri;
                _client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization",
                                                                      $"Bearer {_oAuth2Wrapper.accessToken}");
            }
            return(_oAuth2Wrapper.isInitialized);
        }