简体   繁体   English

Java - OAuth 2.0 获取访问令牌

[英]Java - OAuth 2.0 obtaining the access token

I'm writing a simple desktop application that sometimes needs to upload a compressed archive to OneDrive.我正在编写一个简单的桌面应用程序,有时需要将压缩存档上传到 OneDrive。 It's the first time I'm messing up with OAuth and I'm trying to understand how to show the user the login page and obtain back the access token.这是我第一次搞砸 OAuth,我试图了解如何向用户显示登录页面并获取访问令牌。 I understand that the login page is called via this url: https://login.live.com/oauth20_authorize.srf?client_id={client_id}&scope={scope}&response_type=token&redirect_uri={redirect_uri}我知道登录页面是通过这个 url 调用的: https://login.live.com/oauth20_authorize.srf?client_id={client_id}&scope={scope}&response_type=token&redirect_uri={redirect_uri} : https://login.live.com/oauth20_authorize.srf?client_id={client_id}&scope={scope}&response_type=token&redirect_uri={redirect_uri} client_id https://login.live.com/oauth20_authorize.srf?client_id={client_id}&scope={scope}&response_type=token&redirect_uri={redirect_uri} scope https://login.live.com/oauth20_authorize.srf?client_id={client_id}&scope={scope}&response_type=token&redirect_uri={redirect_uri} response_type https://login.live.com/oauth20_authorize.srf?client_id={client_id}&scope={scope}&response_type=token&redirect_uri={redirect_uri} token https://login.live.com/oauth20_authorize.srf?client_id={client_id}&scope={scope}&response_type=token&redirect_uri={redirect_uri} redirect_uri https://login.live.com/oauth20_authorize.srf?client_id={client_id}&scope={scope}&response_type=token&redirect_uri={redirect_uri}

Which is the best way to "show" the login page to the user and wait the redirect with the access code using java?哪个是向用户“显示”登录页面并使用 java 等待使用访问代码重定向的最佳方式?

I'm writing a simple desktop application that sometimes needs to upload a compressed archive to OneDrive我正在编写一个简单的桌面应用程序,有时需要将压缩存档上传到 OneDrive

You may try to use the device authorization grant flow .您可以尝试使用设备授权授予流程

The service will return a signin URL and a code.该服务将返回登录 URL 和代码。 Your application then然后你的申请

  • opens a browser to the returned URL打开浏览器访问返回的 URL
  • reguralry polls for a token, which is returned if the user signs in and enters the code regularry 轮询令牌,如果用户登录并输入代码,则返回令牌

There are ways to embed a web page in the java app , but then you will have to handle the redirect urls, etc.. So for the desktop apps, I find the device grant flow the simplest to implement.有多种方法可以在 java 应用程序中嵌入网页,但是您必须处理重定向 url 等。因此,对于桌面应用程序,我发现设备授权流程最容易实现。

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

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