0

I created Oka application (API Services) for machine to machine Auth. I set client authentication as "Public key / Private key".

Can someone help with Spring boot application that connects to this API via public/private key method and gets access token.

I implemented Client Secret authentication by passing credentials in header.

I am new to public/private key method. Appreciate the help.

I am trying to implement public/private key auth method to get access token from OKTA.

2

1 Answer 1

0

For client credentials, basic auth, I am using this code: HttpHeaders httpHeaders = new HttpHeaders();

    httpHeaders.setContentType(MediaType.APPLICATION_JSON);
    String auth = "user name"+":"+"password";
    byte[] encodedAuth = java.util.Base64.getEncoder().encode(auth.getBytes());
    httpHeaders.set("Authorization", "Basic " + new String(encodedAuth));
    httpHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    httpHeaders.setAccept(List.of(MediaType.APPLICATION_JSON));
    MultiValueMap<String, String> reqBodyData = new LinkedMultiValueMap<>();
    reqBodyData.add("grant_type","client_credentials");
    HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(reqBodyData, httpHeaders);
    LinkedHashMap<String, String> result = (LinkedHashMap<String, String>) restTemplate.postForEntity("<<auth token end point>>",
            requestEntity, Object.class).getBody();
    String accessToken = result.get("access_token");

Will need to find a way for pub-private key insteasd of basic auth.

1
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Nov 6, 2023 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.