-
-
Save LSTANCZYK/7d0e62311681ea1c4fbbe4086928b003 to your computer and use it in GitHub Desktop.
OAuth2 C# RestSharp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string url = "https://myurl.com"; | |
string client_id = "client_id"; | |
string client_secret = "client_secret"; | |
//request token | |
var restclient = new RestClient(url); | |
RestRequest request = new RestRequest("request/oauth") {Method = Method.POST}; | |
request.AddHeader("Accept", "application/json"); | |
request.AddHeader("Content-Type", "application/x-www-form-urlencoded"); | |
request.AddParameter("client_id", client_id); | |
request.AddParameter("client_secret", client_secret); | |
request.AddParameter("grant_type", "client_credentials"); | |
var tResponse = restclient.Execute(request); | |
var responseJson = tResponse.Content; | |
var token = JsonConvert.DeserializeObject<Dictionary<string,object>>(responseJson)["access_token"].ToString(); | |
return token.Length > 0 ? token : null; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment