Beispiel #1
0
        private async Task ProcessRedirect(HttpListenerContext context, string clientId, string secret, string redirectUrl)
        {
            var error = HttpUtility.ParseQueryString(context.Request.Url.Query).Get("error_description");

            if (error != null)
            {
                throw new InvalidOperationException(error);
            }

            var code = HttpUtility.ParseQueryString(context.Request.Url.Query).Get("code");

            await SendRedirectResponse(context.Response).ConfigureAwait(false);

            var form = new Dictionary <string, string>
            {
                { "grant_type", "authorization_code" },
                { "code", code },
                { "client_id", clientId },
                { "client_secret", secret },
                { "redirect_uri", redirectUrl }
            };

            Token = await http.PostForm <AuthToken>("https://api.amazon.com/auth/o2/token", form).ConfigureAwait(false);

            if (Token != null)
            {
                OnTokenUpdate?.Invoke(Token.access_token, Token.refresh_token, DateTime.UtcNow.AddSeconds(Token.expires_in));
            }

            await Account.GetEndpoint().ConfigureAwait(false);
        }
Beispiel #2
0
        private async Task UpdateToken()
        {
            updatingToken = true;
            var form = new Dictionary <string, string>
            {
                { "grant_type", "refresh_token" },
                { "refresh_token", Token.refresh_token },
                { "client_id", clientId },
                { "client_secret", clientSecret }
            };

            Token = await http.PostForm <AuthToken>("https://api.amazon.com/auth/o2/token", form).ConfigureAwait(false);

            if (Token != null)
            {
                OnTokenUpdate?.Invoke(Token.access_token, Token.refresh_token, DateTime.UtcNow.AddSeconds(Token.expires_in));
            }
            updatingToken = false;
        }