コード例 #1
0
        public async Task <IActionResult> GetDiscordAuth([FromQuery(Name = "code")] string code)
        {
            try
            {
                Profile profile = await _discord.Authenticate(code);

                return(Ok(new { refreshToken = _tokenManager.CreateRefreshToken(profile) }));
            }
            catch (AuthProviderErrorException)
            {
                return(BadRequest(new APIError("Authentication Failure", "ERR_AUTH_FAILED")));
            }
            catch (UserLookupErrorException)
            {
                return(BadRequest(new APIError("Database query for Discord authentication failed", "ERR_DB_LOOKUP")));
            }
            catch (Exception)
            {
                return(BadRequest(new APIError("An unknown error occurred.", "ERR_UNKNOWN")));
            }
        }
コード例 #2
0
        private static dynamic AuthenticateAndRetrieveData(string deviceCode, QueryOptions queryOptions)
        {
            var tokenManager = new TokenManager(deviceCode, Storage, ApiClient);

            dynamic realTimeData = null;

            var policy =
                Policy
                .Handle <UnauthorizedException>()
                .Retry(1, (exception, retryCount) =>
            {
                tokenManager.CreateRefreshToken();
                realTimeData = ApiClient.GetRealTimeData(queryOptions, tokenManager.GetAccessToken());
            });

            policy.Execute(() =>
            {
                realTimeData = ApiClient.GetRealTimeData(queryOptions, tokenManager.GetAccessToken());
            });

            return(realTimeData);
        }