Skip to content

Instantly share code, notes, and snippets.

@sethdefontenay
Last active March 25, 2020 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sethdefontenay/cd5b6eab9403e48c0a49bcc579c20323 to your computer and use it in GitHub Desktop.
Save sethdefontenay/cd5b6eab9403e48c0a49bcc579c20323 to your computer and use it in GitHub Desktop.
Xero OAuth2
public void Test()
{
// log in to the users xero account
// send this call using browser: https://login.xero.com/identity/connect/authorize?response_type=code&client_id=E****************E&redirect_uri=https%3A%2F%2F**************************%2Fapi%2FAuthorize&scope=openid profile email offline_access accounting.transactions&state=123
// it should redirect to the function app which will send back the code
// the code only works once
HttpClient client = new HttpClient();
var clientId = "*******E";
var secret = "Q***********q";
client.SetToken("Basic", Base64Encode($"{clientId}:{secret}"));
var values = new Dictionary<string, string>
{
{ "grant_type", "authorization_code" },
{ "authorization", "6*********************************5" }, // paste code here
{ "redirect_uri", "https://**************/api/Authorize" }
};
var content = new FormUrlEncodedContent(values);
var response = client.PostAsync("https://identity.xero.com/connect/token", content).Result;
var responseString = response.Content.ReadAsStringAsync().Result;
}
@sonika1981
Copy link

From where i can get authorization code

@sethdefontenay
Copy link
Author

Follow instructions in the commented lines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment