Skip to content

Instantly share code, notes, and snippets.

@ocap-kirk
Created December 16, 2015 19:40
Show Gist options
  • Save ocap-kirk/3444301fb50509ae101a to your computer and use it in GitHub Desktop.
Save ocap-kirk/3444301fb50509ae101a to your computer and use it in GitHub Desktop.
Java SDK Proxy Example
package proxyServerTest.com.test;
import java.io.IOException;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import com.okta.sdk.clients.AuthApiClient;
import com.okta.sdk.clients.UserApiClient;
import com.okta.sdk.framework.ApiClientConfiguration;
import com.okta.sdk.framework.ProxyConfiguration;
import com.okta.sdk.models.auth.AuthResult;
import com.okta.sdk.models.users.User;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
ApiClientConfiguration oktaSettings = new ApiClientConfiguration(
"https://{org}.okta.com",
"{api-key}");
String proxyAddress = "192.168.1.200";
int proxyPort= 31289;
String proxyUsername = "proxy_user1";
String proxyPassword = "Password1!";
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(proxyAddress, proxyPort),
new UsernamePasswordCredentials(proxyUsername, proxyPassword));
ProxyConfiguration proxyConfig = new ProxyConfiguration(proxyAddress, proxyPort, credsProvider);
// AuthApiClient authClient = new AuthApiClient(oktaSettings,proxyConfig);
// AuthResult result;
UserApiClient usersClient = new UserApiClient(oktaSettings,proxyConfig);
// UserApiClient usersClient = new UserApiClient(oktaSettings);
try {
User user = usersClient.getUser("tkirk");
System.out.print(user.getId() + " " + user.getProfile().getFirstName()+ " " + user.getProfile().getLastName());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment