1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| public static string GetBearer ()
{
var clientToken = new RestClient(globalVar.baseURL); // mon site interne
clientToken.Timeout = -1;
var requestToken = new RestRequest("api/axs/v9/oauth/token", Method.POST); // l'api d'identification
requestToken.AddHeader("Content-Type", "application/x-www-form-urlencoded");
requestToken.AddParameter("client_id", "Porteur");
requestToken.AddParameter("username", globalVar.username);
requestToken.AddParameter("tenant_id", "");
requestToken.AddParameter("grant_type", "password");
requestToken.AddParameter("password", globalVar.password);
IRestResponse ResponseToken = clientToken.Execute(requestToken);
string repToken = ResponseToken.Content;
string[] separatorToken = new string[] { "\"" };
string[] resultToken = repToken.Split(separatorToken, StringSplitOptions.None);
globalVar.bearer = resultToken[3]; // Recupération de mon token
dynamic takeToken = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(ResponseToken.Content); |
Partager