I have a spring boot Rest API. This API is invoked by some other spring boot application. I’m using Okta for security. These are the steps I have followed
- Create new App integration as API Services.
- Create a default scope in the authorization server.
- Create a new user in the okta Directory under People.
After configuring Okta, I’m trying to get access token for the created user as below
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
headers.setBasicAuth("<client_id>", "<client_secret>");
MultiValueMap<String, String> map= new LinkedMultiValueMap<>();
map.add("grant_type", "client_credentials");
map.add("username", "<user_email>");
map.add("password", "<user_password>");
HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(map, headers);
ResponseEntity<MyAccessTokenResponse> response = restTemplate.exchange("https://<my_okta_domain>.okta.com/oauth2/default/v1/token",
HttpMethod.POST, entity, MyAccessTokenResponse.class);
String accessToken = response.getBody().getAccessToken();
My question is even when I pass the wrong <user_email>, <user_password> I’m getting an access token. Also if I’m not passing <user_email>, <user_password> I’m still getting an access token.
So how can I get the validated access token? Using this token, I will invoke a secured API and extract the user email and do my business logic
Thanks in advance !!!