# Calling outh2/v1/authorize api from java redirects to login.html url

**URL:** <https://devforum.okta.com/t/calling-outh2-v1-authorize-api-from-java-redirects-to-login-html-url/14427>\
**Category:** Questions\
**Created:** [May 27, 2021, 12:04pm UTC](https://devforum.okta.com/t/calling-outh2-v1-authorize-api-from-java-redirects-to-login-html-url/14427 "2021-05-27T12:04:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jyoti](https://avatars.discourse-cdn.com/v4/letter/j/6f9a4e/32.png) [@jyoti](https://devforum.okta.com/u/jyoti)\
**Post date:** [May 27, 2021, 12:04pm UTC](https://devforum.okta.com/t/calling-outh2-v1-authorize-api-from-java-redirects-to-login-html-url/14427/1 "2021-05-27T12:04:25Z")

</div>

m calling following api from java(backend)  
[https://nielsen.okta.com/oauth2/v1/authorize](https://nielsen.okta.com/oauth2/v1/authorize)?  
client\_id=XXXXX  
&response\_type=code  
&scope=openid%20offline\_access  
&redirect\_uri=http%3A%2F%2FXXXXX%2Fimplicit%2Fcallback  
&state=XXXXX  
but its redirect to login.html url.  
why is it so??  
how can i get authorization\_code after calling authorize api

---

<div class="post-metadata">

**Author:** ![mraible](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/mraible/32/37_2.png) [@mraible](https://devforum.okta.com/u/mraible)\
**Post date:** [May 27, 2021, 3:32pm UTC](https://devforum.okta.com/t/calling-outh2-v1-authorize-api-from-java-redirects-to-login-html-url/14427/2 "2021-05-27T15:32:27Z")

</div>

Yep, that’s how OAuth works. You hit the authorize endpoint and it redirects you to login. See our “what the heck is OAuth” for more information.

> **[What the Heck is OAuth?](https://developer.okta.com/blog/2017/06/21/what-the-heck-is-oauth)**
>
> OAuth 2.0 is a standard that apps can use to provide client applications with secure delegated access. OAuth works over HTTPS and authorizes devices, APIs, servers, and applications with access tokens rather than credentials. OIDC adds a signed ID...

The authorize code will be returned after you log in.

---

<div class="post-metadata">

**Author:** ![alcar](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@alcar](https://devforum.okta.com/u/alcar)\
**Post date:** [June 3, 2021, 6:50am UTC](https://devforum.okta.com/t/calling-outh2-v1-authorize-api-from-java-redirects-to-login-html-url/14427/3 "2021-06-03T06:50:42Z")

</div>

I notice that you mention the back end here so am guessing the account may be one used for service operations that you do not expect the actual person to be logging into to frequently.

If this is the case then in a different API application using OAuth I did the following:

Used normal processing with the login screen to obtain the response with longer lived refresh\_token.  
Used the refresh\_token to obtain and new access\_token and id\_token when required.  
Maintain the refresh\_token using a scheduled task to renew it before it expired.

This is not the best process for doing this type of work.  
The better way if this is a backend service is to use an Administrative Token. There may be other options to consider as well.

If you are not doing machine-to-machine service authentication then you should look at redesigning your application so the user needing to authenticate to be presented with the Okta login page.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/oktadev/original/1X/589c4c5f80de422d01f47cee7185a7fb8227835c.png) [@system](https://devforum.okta.com/u/system)\
**Post date:** [February 8, 2024, 6:23pm UTC](https://devforum.okta.com/t/calling-outh2-v1-authorize-api-from-java-redirects-to-login-html-url/14427/4 "2024-02-08T18:23:14Z")

</div>

Closed on February 8, 2024, 6:23pm UTC

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
