Last active
August 29, 2015 14:28
-
-
Save CiprianPorumbescu/9e4fb2bf06b57778cfbb to your computer and use it in GitHub Desktop.
An example of how to authorize Nylas from .Net
This file contains hidden or 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
public async Task<ActionResult> NylasAuthenticationResult(string code) | |
{ | |
using (HttpClient httpClient = new HttpClient()) | |
{ | |
httpClient.BaseAddress = new Uri("https://api.nylas.com"); | |
//tried as JSON | |
var nylasAuthorizeRequest = new NylasAuthorizeRequest | |
{ | |
ClientId = "cf7jhxlkkvimkxvd2vnkkzci", | |
GrantType = "authorization_code", | |
Code = code | |
}; | |
var authorizeResponseMessage = await httpClient.PostAsJsonAsync<NylasAuthorizeRequest>("oauth/token", nylasAuthorizeRequest).ConfigureAwait(false); | |
// tried as x-www-form-encoded | |
var postData = new List<KeyValuePair<string, string>>(); | |
postData.Add(new KeyValuePair<string, string>("client_id", "cf7jhxlkkvimkxvd2vnkkzci")); | |
postData.Add(new KeyValuePair<string, string>("grant_type ", "authorization_code")); | |
postData.Add(new KeyValuePair<string, string>("code ", code)); | |
HttpContent content = new FormUrlEncodedContent(postData); | |
var authorizeResponseMessage = await httpClient.PostAsync("oauth/token", content).ConfigureAwait(false); | |
var authorizeResponse = authorizeResponseMessage.Content.ReadAsAsync<NylasAuthorizeResponse>().Result; | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment