Exemplo n.º 1
0
        public void Refresh(string login, string refrehToken)
        {
            using (var client = new HttpClient())
            {
                using (var request = new HttpRequestMessage(HttpMethod.Post, $"{_urlBase}{login}"))
                {
                    request.Content = new FormUrlEncodedContent(new Dictionary <string, string>
                    {
                        ["grant_type"]    = "refresh_token",
                        ["refresh_token"] = refrehToken,
                        ["scope"]         = _scope
                    });

                    var response = client.SendAsync(request, HttpCompletionOption.ResponseContentRead).Result;
                    response.EnsureSuccessStatusCode();

                    var temp = new TokenOppenIdConnect(response.Content.ReadAsStringAsync().Result);
                    if (temp.HasError)
                    {
                        throw new InvalidOperationException("Error pour obtenir le token : " + TokenOpenId.Error);
                    }
                    TokenOpenId.AccessToken = temp.AccessToken;
                }
            }
        }
Exemplo n.º 2
0
        public void Connect(string login, string pwd, string urlLogin)
        {
            using (var client = new HttpClient())
            {
                using (var request = new HttpRequestMessage(HttpMethod.Post, $"{_urlBase}{urlLogin}"))
                {
                    request.Content = new FormUrlEncodedContent(new Dictionary <string, string>
                    {
                        ["grant_type"] = "password",
                        ["username"]   = login,
                        ["password"]   = pwd,
                        ["scope"]      = _scope,
                        ["client_id"]  = _clientId
                    });


                    var response = client.SendAsync(request, HttpCompletionOption.ResponseContentRead).Result;
                    response.EnsureSuccessStatusCode();


                    TokenOpenId = new TokenOppenIdConnect(response.Content.ReadAsStringAsync().Result);
                    if (TokenOpenId.HasError)
                    {
                        throw new InvalidOperationException("Error pour obtenir le token : " + TokenOpenId.Error);
                    }
                }
            }
        }