How do I get the Auth Code from the redirect url? OAuth2

痞子三分冷 提交于 2020-02-25 04:16:08

问题


I'm trying to authenticate my app with an API using OAuth2.0.

I'm new to OAuth and only have a basic understanding of it. I have implemented a way to get the access token and make the requests I want, however my method seems a bit inefficient. It could also be my slight lack of knowledge with http requests in Java. Just as a note, i am using the apache http client.

Currently what im doing to get authorized is I open the user authorization page directly in the browser with:

Desktop.getDesktop().browse(new URL(url.toURI());

This then redirects to the redirect url in the browser, with the "code" parameter in the url.

I dont know how to get that url and then retrieve the "code" parameter, so Im just copying it from the url itself and then pasting it into an input field, which then sends a request to retrieve the access token.

So my question is, how do I get rid of that step where the user has to copy and paste the code parameter from the redirect url into my program?

How do I send them to the authorization page and then receive the redirected url to take the code parameter from my program to request the access token?

If someone could point me in the right direction or maybe even show a bit of code, I would appreciate it very much.

来源:https://stackoverflow.com/questions/56873079/how-do-i-get-the-auth-code-from-the-redirect-url-oauth2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!