简体   繁体   English

C#使用桌面应用程序自动登录网站

[英]C# autologin to website using desktop application

I have a website in PHP Laravel 5.2 . 我有一个PHP Laravel 5.2网站。

I want to create a desktop application (something like drop-box application for windows) using C# , in which there will be a button "Open web", clicking which the logged-in user (in desktop app) should get logged in to the web-site without asking any credentials. 我想使用C#创建一个桌面应用程序(类似于Windows的下拉框应用程序),其中将出现一个“打开网站”按钮,点击该按钮后,已登录的用户(在桌面应用程序中)应登录到网站,无需任何凭据。

In web-site, I am using api_token based authentication. 在网站上,我正在使用基于api_token的身份验证。

There is a possible way I can make an end-point in web-site to check the token an make user logged in if correct, but I think it is less secure. 我可以通过一种可能的方式在网站上建立一个端点来检查使make用户登录的令牌是否正确,但是我认为这种方法不太安全。

I've checked request-response log in fiddler for drop-box "Open dropbox.com" button, it does not sets any token in request. 我已经检查了提琴手的请求-响应日志中的下拉框“ Open dropbox.com”按钮,它没有在请求中设置任何令牌。

The question is how can I achieve it? 问题是我该如何实现?

One way would do the following: 一种方法将执行以下操作:

  1. Request a use-once (a nonce) unique code from the server in your desktop application, that refers to the user you want to log in as 从桌面应用程序中的服务器请求一次使用(随机数)唯一的代码,该代码指的是您要以以下身份登录的用户
  2. Open a webbrowser process with an address that contains this use-once code, something like this: 使用包含此一次性代码的地址打开一个网络浏览器进程,如下所示:

    http://www.your.server.com/the/page/you/want?auth=29874298798724982734 http://www.your.server.com/the/page/you/want?auth=29874298798724982734

The way Dropbox does this, is to create a temporary html file on disk which contains some javascript code that posts a "form" to a secure page on their server Dropbox这样做的方法是在磁盘上创建一个临时html文件,其中包含一些javascript代码,这些JavaScript代码会将“表单”发布到其服务器上的安全页面

https://www.dropbox.com/desktop_login

form fields:
    buildno=Dropbox-win-7.4.30
    u=home
    c=en_US
    i=<some number>
    n data-nonce-c=<some large hex string>

Then it spawns a webbrowser process to open this file. 然后,它会产生一个Web浏览器进程来打开此文件。

To see this file, use the globe link in your Dropbox app and then hit Esc as soon as the initial web page loads and grab the url which should look like this: 要查看此文件,请在Dropbox应用中使用Globe链接,然后在初始网页加载后立即点击Esc并获取应如下所示的网址:

file://C:/users/USERNAME/appdata/local/temp/RANDOM.html

Then open this file to inspect it. 然后打开此文件进行检查。

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

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