简体   繁体   中英

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. 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. 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}

Which is the best way to "show" the login page to the user and wait the redirect with the access code using java?

I'm writing a simple desktop application that sometimes needs to upload a compressed archive to OneDrive

You may try to use the device authorization grant flow .

The service will return a signin URL and a code. Your application then

  • opens a browser to the returned URL
  • reguralry polls for a token, which is returned if the user signs in and enters the code

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.

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