Authenticated Proxy Issue

Hi,

I'm trying to connect to Genesys cloud using SDK version 137.0.0
Using the following code I can't authenticate when I'm on a enterprise network with proxy (with variable useProxy=true). However, when I'm using a direct connection without proxy (useProxy=false) it works fine:

*public static void initializePurecloudInstance() {*
*			System.out.println("Initializing PureCloud instance...");*
*			if (useProxy){*
*				Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(PROXY_URL, PROXY_PORT));	*
*				apiClient = ApiClient.Builder.standard().withBasePath(PURECLOUDURL).withAuthenticatedProxy(proxy,proxyUser,pass).build();*
*			}*
*			else{*
*				apiClient = ApiClient.Builder.standard().withBasePath(PURECLOUDURL).build();*
*			}		*
*			Configuration.setDefaultApiClient(apiClient);*
*			try {*
*				ApiResponse<AuthResponse> authResponse = apiClient.authorizeClientCredentials(CLIENT_ID, CLIENT_SECRET);*
*				System.out.println("...Done. TOKEN EXPIRES ON "+authResponse.getBody().getExpires_in()+" SECONDS");*
*			} catch (ApiException e) {*
*				System.out.println("Error: "+e.getLocalizedMessage()+e.toString());*
*				e.printStackTrace();*
*				System.out.println(e.getRawBody());*
*			}	 catch (IOException e) {*
*				System.out.println("Error: "+e.getLocalizedMessage()+e.toString());*
*				e.printStackTrace();*
*				System.out.println(e.getMessage());*
*			}*
*		}*

This is the consule log. What means "no client id provided"? the contants CLIENT_ID CLIENT_SECRET are correctly informed.

Initializing PureCloud instance...
oct 22, 2021 11:51:41 A. M. org.apache.http.impl.auth.HttpAuthenticator generateAuthResponse
WARNING: NEGOTIATE authentication error: No valid credentials provided (Mechanism level: No valid credentials provided (Mechanism level: Failed to find any Kerberos tgt))
oct 22, 2021 11:51:41 A. M. org.apache.http.impl.auth.HttpAuthenticator generateAuthResponse
WARNING: NTLM authentication error: Credentials cannot be used for NTLM authentication: com.mypurecloud.sdk.v2.connector.apache.ApacheHttpCredentialsProvider$CredentialsWrapper
Error: errorcom.mypurecloud.sdk.v2.ApiException: error
com.mypurecloud.sdk.v2.ApiException: error

  • at com.mypurecloud.sdk.v2.ApiClient.interpretConnectorResponse(ApiClient.java:705)*
  • at com.mypurecloud.sdk.v2.ApiClient.getAPIResponse(ApiClient.java:757)*
  • at com.mypurecloud.sdk.v2.ApiClient.authorizeClientCredentials(ApiClient.java:302)*
  • at Main.initializePurecloudInstance(Main.java:86)*
  • at Main.main(Main.java:66)*
    {"error":"invalid_client","description":"no client id provided","error_description":"no client id provided"}

Please, could you assist?
Thanks!

Hi again,

Could it be that the proxy is dropping the authentication headers?
When I use a valid token directly it works:

System.out.println("Initializing PureCloud instance...");
*Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(PROXY_URL, PROXY_PORT)); *
apiClient = ApiClient.Builder.standard().withBasePath(PURECLOUDURL).withAuthenticatedProxy(proxy,proxyUser,proxyPass).build();
*Configuration.setDefaultApiClient(apiClient);
apiClient.setAccessToken("<<>>");
AnalyticsApi api = new AnalyticsApi();
api.....

Hi Carlos,

Thanks for posting. In reviewing the SDK we do not currently support NTLM for proxy authentication. I am going to chat with our product manager today and open a ticket for my dev team to add support. I can't commit to a date on when we would do this work.

Thanks,
John Carnell

Hi,

I found a solution here: HTTP GET and POST Requests in Java with NTLM Proxy - Stefan Bruhns

private static String obtenerNuevoToken() throws Exception {
HttpPOSTRequest request = new HttpPOSTRequest();
request.domain = Config.PURECLOUDLOGINDOMAIN;
request.port = 443;
request.isHttps = true;
request.setResource("/oauth/token");
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/x-www-form-urlencoded");
request.headers = headers;
request.setData("grant_type=client_credentials&client_id=" + Config.CLIENT_ID + "&client_secret=" + Config.CLIENT_SECRET);
HashMap<String, String> params = new HashMap<String, String>();
request.params = params;
ProxyAuthenticator authenticator = new ProxyAuthenticator(Config.PROXY_USER, Config.PROXY_PASS);
ProxyFactory proxyFactory = new ProxyFactory(Config.PROXY_URL, Config.PROXY_PORT, authenticator);
HttpConnector connector = new HttpConnector(proxyFactory.getProxy());
HttpResponse response = connector.makeRequest(request);
return new String(response.content);
}

this method returns the json with the token info that you should parse

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.