简体   繁体   中英

How to GET code Parameter from Slack Redirect URL in C#

Currently I have a slack button in my WPF application that opens a webpage and asks for user for access.

System.Diagnostics.Process.Start("https://slack.com/oauth/authorize?scope=client&client_id=XXXXXXXXXXXXXXXXXXXXXX");

After authorizing, the page gets redirected to a URL which has a generated code in the parameter that I need to get a token later on. The problem is how do I get this code. For now I have set the the redirect URL to, www.slack.com. And the following url is generated.

 https://slack.com/?code=8XXXXXXXXXXXXXXX.XXXXXXXXXXXXXX5&state=

How do get the code back into my application. I am using the following but am not getting the response I need and this executes before the user can even authorize.

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(URL);
var response =req.RequestUri.ToString();

Alternative solutions and suggestions would be good to implement my authorization for a desktop application using C#.

  1. As part of the oauth process Slack will call your application using the redirect url and return the code parameter. So you the redirect URL needs to point to your application. Not to slack.com.
  2. You will need to read the url parameters that your application as been called with. In C# that can be done with code = Request.QueryString["code"];
  3. Your c# application needs to run as ASP script on a webserver that is accessible from the Internet, so that Slack can reach it.

In order to use Slack for authentication your application needs to implement the complete oauth process as described here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM