未经授权的客户端,用于验证单个用户

时间:2019-12-05 05:34:57

标签: oauth-2.0 restsharp

我目前正在尝试使用Hexoskin API(https://api.hexoskin.com/docs/index.html)通过oauth2对单个用户进行身份验证。根据他们的文档(https://api.hexoskin.com/docs/page/oauth2/),我有POST请求应该是什么样子

POST https://api.hexoskin.com/api/connect/oauth2/token/

username=USERNAME&
password=PASSWORD&
scope=SCOPE&
grant_type=password

但是,当我尝试在RestSharp中实现请求时,我不断收到未授权的客户端错误。这是我的尝试:

private void Button_Click(object sender, RoutedEventArgs e)
        {
            string client_id = clientId;
            string client_secret = clientSecret;
            string username = myUsername;
            string password = myPassword;

            var client = new RestClient("https://api.hexoskin.com");
            RestRequest request = new RestRequest("/api/connect/oauth2/token/",Method.POST );


            request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
            client.Authenticator = new HttpBasicAuthenticator(client_id, client_secret);
            request.AddHeader("Accept", "application/json");
            request.AddParameter("grant_type", "password");
            request.AddParameter("username", username);
            request.AddParameter("password", password);
            request.AddParameter("client_id", client_id);

            var response = client.Execute(request);
            //POST https://api.authorization-server.com/token
            //grant_type = password &
            //username = USERNAME &
            //password = PASSWORD &
            //client_id = CLIENT_ID


            return;
        }

Hexoskin API没有任何有关使用C#访问API的文档,我必须即时学习。我只想弄清楚我所缺少的。任何帮助都将不胜感激。 (如果我措辞怪异,也很抱歉)。

0 个答案:

没有答案