예제 #1
0
        private async Task <BedrockTokenPair> RefreshAccessToken(string refreshToken)
        {
            if (string.IsNullOrEmpty(refreshToken))
            {
                throw new ArgumentException("The refresh token is missing.");
            }

            try
            {
                AccessTokens tokens = await Get($"{RefreshUri}", new Dictionary <string, string> {
                    { "client_id", ClientId },
                    { "grant_type", "refresh_token" },
                    { "scope", "service::user.auth.xboxlive.com::MBI_SSL" },
                    { "redirect_uri", RedirectUri },
                    { "refresh_token", refreshToken }
                }).ConfigureAwait(false);

                return(new BedrockTokenPair()
                {
                    AccessToken = tokens.AccessToken,
                    ExpiryTime = DateTime.UtcNow.AddSeconds(tokens.Expiration),
                    RefreshToken = tokens.RefreshToken
                });
            }
            catch (WebException ex)
            {
                Log.Warn("RefreshAccessToken failed likely due to an invalid client ID or refresh token\n" + ex.ToString());
            }

            return(null);
        }
예제 #2
0
        private async Task <AccessTokens> Get(string uri, Dictionary <string, string> parameters)
        {
            AccessTokens tokens = null;

            var client         = _httpClient;
            var encodedContent = new FormUrlEncodedContent(parameters);
            var response       = await client.PostAsync(uri, encodedContent);

            var res = await response.Content.ReadAsStringAsync();

            tokens = JsonConvert.DeserializeObject <AccessTokens>(res);

            return(tokens);
        }