Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get authorization_code in OAuth 2.0 without web browser in Java?

Tags:

java

oauth-2.0

As I understand, in authorization code flow we need to get authorization code and use it to get token after. We can get this code only when user confirms specified access. After that browser redirects us to redirect_uri and response will contain authorization code as parameter. So, the question: is it possible to get this authorization code without browser or any self made UI? Can we get it in application after correct request to, for example https://mysite.tuz/authorize ?

like image 219
Илья Белейчев Avatar asked Feb 16 '18 07:02

Илья Белейчев


People also ask

Does OAuth require browser?

OAuth 2.0 requires a browser for user consent once A browser is required, so that the user can agree to the request of the app to access the users data. After the user agreed on sharing the data with the app, the app can use the refresh token without a browser based flow.

How does OAuth2 work in Java?

OAuth2. 0 is an open authorization protocol, which allows accessing the resources of the resource owner by enabling the client applications on HTTP services such as Facebook, GitHub, etc. It allows sharing of resources stored on one site to another site without using their credentials.

How do I get URL redirect code?

You can have a frontend app under the redirect URI. Then you can run the code you pasted in your browser. You can use javascript to get the query string of the current page (e.g. by calling window. location.search and then splitting the string using & as the delimiter).


Video Answer


1 Answers

As you are using authorization code flow, the client requires a user agent (i.e browser or mobile app) to get the authorization code from the authorization server.

The whole purpose of using authorization code is that it can be passed via the user's web browser (user agent) instead of passing the access tokens directly via the web browser (user agent) which is not desired. Using authorization code,the Client then can directly retrieve an Access Token from the authorization server.

So the user agent is required to get the authorization code and act as an intermediary between client and authorization server.

If you do not require a browser then authorization code flow may not the correct choice. OAuth 2.0 supports several different grants i.e ways of retrieving an Access Token. Deciding which one is suited for your case depends mostly on your Client's type.

This might help you in deciding which flow to use https://auth0.com/docs/api-auth/which-oauth-flow-to-use

like image 158
Mohit_Kalra Avatar answered Sep 24 '22 10:09

Mohit_Kalra