Hi Team,
Please help me on this below issue.
Getting status as "403 Forbidden " while trying to get information of current login user in OKTA through REST API by using Java and “Jersey” implementer. and hence not able to get the payload of current login user.
See my below code.
package com.vertiv.okta;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
public class Oktaclient {
public static void main(String[] args) {
// TODO Auto-generated method stub
ClientConfig clientConfig = new ClientConfig();
HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("username", "password");
clientConfig.register( feature) ;
System.out.println(clientConfig.register( feature));
Client client = ClientBuilder.newClient( clientConfig );
WebTarget webTarget = client.target("https://expample.okta.com/?api_key=00_23232sdfsdfffererdw3423_3dsglkxcmxc9Dwe").path("api/v1/users/me/");
Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON);
Response response = invocationBuilder.get();
System.out.println(response.getStatus());
System.out.println(response.getStatusInfo());
System.out.println("ammmmmmmm");
if(response.getStatus() == 200)
{
BufferedReader br = new BufferedReader(new
InputStreamReader((InputStream) (response.getEntity())));
String output;
System.out.println("============Output:============");
try
{
while ((output = br.readLine()) != null)
{
System.out.println(output);
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}
#Output of the code
403
Forbidden