0

I'm using Xero with c# winforms. Xero released a new topic OAuth2.0 and they are providing sample only for web applications. But I didn't get authorization code. I'm getting an html page as response not the authorization code. Can anyone help me? Thanks for the help in advance.

Here is my current code for getting authorization code:

string XeroUrl = "login.xero.com/identity/connect/authorize?response_type=code&client_id=xxxxxxxxxxxx&redirect_uri=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; 
string ScopeLimit = "openid profile email accounting.transactions&state=123"; 
string URL = "https://" + XeroUrl + "&scope=" + ScopeLimit; 
try { 
    HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(URL); 
    webRequest.AllowAutoRedirect = true; 
    webRequest.Method = WebRequestMethods.Http.Get; 
    webRequest.UseDefaultCredentials = false; 
    webRequest.PreAuthenticate = false; 
    HttpWebResponse response = null; 
    response = (HttpWebResponse)webRequest.GetResponse(); 
    StreamReader reader = new StreamReader(response.GetResponseStream()); 
    string output = reader.ReadToEnd(); 
}
quetzalcoatl
  • 32,194
  • 8
  • 68
  • 107
  • How is the WinForms relevant to this question? It's an UI framework, and all you're doing here is networking. Please remove that from the title. Also, remove "C#", it's already in the tags. Also, adding OAuth and Xero tags might be a good idea. – quetzalcoatl Jan 07 '20 at 10:52
  • You need to get the tag from the response instead of getting a string. – jdweng Jan 07 '20 at 10:52
  • Ponmurugan - it's OAuth2.0 not 0Auth2.0. It starts with a letter "Oo" not a digit "zero" – quetzalcoatl Jan 07 '20 at 11:08
  • @jdweng what do you mean by 'Tag from the response'? An HTTP response is either a string data, or binary payload (image, pdf, etc), the OP said he gets HTML in response, and uses StringReader, it looks perfectly fine as a first step of processing the result. Do you mean reading an html tag from the response content and extracting some data from it? How'd you imagine reading such tag-from-response without receiving the response as string in the first place? Got any stream-based html parser you could advise to the OP? And which tag to parse? I guess there's a lot of them there. – quetzalcoatl Jan 07 '20 at 11:09
  • Quetzalcoatl- Thanks for the correction. Already we are exporting data from our windows application to Xero for around 3 yrs. So Now we need to Implement OAuth2.0 in our windows Application. Is there any possibility to do this? – Ponmurugan Jan 07 '20 at 11:17
  • For windows application i had to use HttpListener to get the oauthcode as they provide code to callback url which you mention in App as well as in auth url. They have a good Demo for this you can get code from that easily but not actual access token. I am having hard time getting token from xero in windows application. – Jolly Feb 26 '21 at 09:07

0 Answers0