Пример #1
0
        public async Task <RefreshTokenModel> RefreshTokenAsync(string refreshToken)
        {
            if (string.IsNullOrEmpty(refreshToken))
            {
                return(new RefreshTokenModel(RefreshTokenStatus.InvalidGrant));
            }

            var builder = new StringBuilder("grant_type=refresh_token");

            builder.AppendFormat("&refresh_token={0}", refreshToken);
            builder.AppendFormat("&client_id={0}", _clientId);
            builder.AppendFormat("&client_secret={0}", _clientSecret);

            using (var client = CreateHttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();

                var request = new HttpRequestMessage(HttpMethod.Post, "api/token");
                request.Content = new StringContent(builder.ToString(), Encoding.UTF8, "application/x-www-form-urlencoded");

                var response = await client.SendAsync(request);

                if (response.IsSuccessStatusCode)
                {
                    var json = await response.Content.ReadAsStringAsync();

                    SaaSApiToken token = await response.Content.ReadAsAsync <SaaSApiToken>();

                    return(new RefreshTokenModel(token));
                }

                return(new RefreshTokenModel(RefreshTokenStatus.InvalidGrant));
            }
        }
        private async Task <SignInModel> _SignInAsync(StringBuilder data, string uri)
        {
            using (var client = CreateHttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();

                var request = new HttpRequestMessage(HttpMethod.Post, uri);
                request.Content = new StringContent(data.ToString(), Encoding.UTF8, "application/x-www-form-urlencoded");

                var response = await client.SendAsync(request);

                if (response.IsSuccessStatusCode)
                {
                    var json = await response.Content.ReadAsStringAsync();

                    SaaSApiToken token = await response.Content.ReadAsAsync <SaaSApiToken>();

                    return(new SignInModel(token));
                }

                return(new SignInModel(SignInStatus.InvalidGrant));
            }
        }
 public SignInModel(SignInStatus status, SaaSApiToken token)
 {
     Status = status;
     Token  = token;
 }
 public SignInModel(SaaSApiToken token)
 {
     Token = token;
 }
Пример #5
0
 public RefreshTokenModel(RefreshTokenStatus status, SaaSApiToken token)
 {
     Status = status;
     Token  = token;
 }
Пример #6
0
 public RefreshTokenModel(SaaSApiToken token)
 {
     Token = token;
 }