简体   繁体   English

使用 Process.Start(Url) 获取 Token 响应

[英]Using Process.Start(Url) to get the Token response

I have the following code and With this code I would like to get the token from the browser.我有以下代码,我想使用此代码从浏览器获取令牌。 I already tried to using Process.Start(login) but I don't know how to get the response with the token.我已经尝试使用 Process.Start(login) 但我不知道如何使用令牌获取响应。 Summarizing, I would like to run my desktop application, then the browser open, get the token generated by the user login, and then close, so my application can manipulate the data from Zoho.Is there a way to use this solution or one better solution for it总结一下,我想运行我的桌面应用程序,然后打开浏览器,获取用户登录生成的令牌,然后关闭,这样我的应用程序就可以操作来自 Zoho 的数据。有没有办法使用这个解决方案或更好的解决方案解决方案

string scope = "ZohoProjects.projects.READ";
string responseType = "code";
string client_id = "100*****H";
string scrt = "02d1********3";
string state = "testing";
string redirect_uri = "https://www.getpostman.com/oauth2/callback";
string login = $"https://accounts.zoho.com/oauth/v2/auth?scope={scope}&client_id={client_id}&response_type=code&access_type=online&redirect_uri={redirect_uri}&prompt=consent";

RestClient client = new RestClient(login);

RestRequest request = new RestRequest(Method.POST);
var response =  client.Execute(request);

There is a C# sample here which demonstrates getting a browser response.这里有一个 C# 示例它演示了如何获得浏览器响应。

Desktop OAuth ideally works as follows:理想情况下,桌面 OAuth 的工作方式如下:

  • Use the recommended flow for a desktop app, which is Authorization Code Flow (PKCE) - there is no client secret使用桌面应用程序的推荐流程,即授权代码流程 (PKCE) - 没有客户端机密
  • Login via the system browser通过系统浏览器登录
  • Receive the response via a Private URI Scheme or Loopback Web Server通过私有 URI 方案或环回 Web 服务器接收响应

This can be tricky to implement though - and another common option is to use a web view as Kevin says, though there are a couple of problems with that:虽然这可能很难实现 - 另一个常见的选择是使用凯文所说的网络视图,尽管有几个问题:

  • Password autofill won't work密码自动填充不起作用
  • Some providers (Google) will block logins on a web view某些提供商 (Google) 会阻止 Web 视图上的登录

If it helps I have some detailed desktop write ups and an online desktop code sample that you can run - though my samples are in Javacscript and not C#.如果它有帮助,我有一些详细的桌面编写和您可以运行的在线桌面代码示例- 尽管我的示例使用 Javascript 而不是 C#。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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