Trying Okta with Spring Boot. "[invalid_token_response] An error occurred while attempting to retrieve the OAuth 2.0 Access Token Response: 401 Unauthorized: [no body]"

Dear Okta developers,

New to Okta. I tried using Okta with a spring boot web app. When I start the spring boot web app and go to “http://localhost:8080” I get below:

Login with OAuth 2.0

[invalid_token_response] An error occurred while attempting to retrieve the OAuth 2.0 Access Token Response: 401 Unauthorized: [no body]

https://dev-37033089.okta.com/oauth2/default

Here is my application.properties:
okta.oauth2.issuer=https://dev-37033089.okta.com/oauth2/default

okta.oauth2.client_id=0oa9sl8zczvTnSUiL5d7

okta.oauth2.client.secret=whHEy9sjEoYHAM0BBt1dKBCP759T7RnMmtvE27YZ

okta_oauth2.redirect.uri=http://localhost:8080/authorization-code/callback

Here is my main Spring Boot Application class:
package com.example.OktaDemo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class OktaDemoApplication {

public static void main(String[] args) {
	SpringApplication.run(OktaDemoApplication.class, args);
}

@GetMapping("/")
	public String hello() {
	return "Hello";
}

}

After starting the spring boot web app when I go to the below url on a browser the first time:
http://localhost:8080

I get a login page. Not sure how I need to login here, but I login with my okta developer account email/password. Then it gives me the error I mentioned above.

I am stuck at this point and don’t know what to do. Any help and pointers will be greatly appreciated. Thanks.

Hi @amitkumar,

I would start by comparing to our sample Spring Boot app with Okta integration which may provide some clarity GitHub - okta-samples/okta-spring-boot-sample: Spring Boot + Okta.

Additionally, you might find these resources useful for troubleshooting your issue and understanding how to use Okta with Spring Boot:

2 Likes