c.lopez | 2021-10-22 10:10:41 UTC | #1
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(PROXYURL, PROXYPORT)); *
* 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(CLIENTID, CLIENTSECRET);* * 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 CLIENTID CLIENTSECRET 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":"invalidclient","description":"no client id provided","errordescription":"no client id provided"}
Please, could you assist? Thanks!
c.lopez | 2021-10-25 06:14:57 UTC | #2
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(PROXYURL, PROXYPORT)); * apiClient = ApiClient.Builder.standard().withBasePath(PURECLOUDURL).withAuthenticatedProxy(proxy,proxyUser,proxyPass).build(); *Configuration.setDefaultApiClient(apiClient); apiClient.setAccessToken("<<<valid access token>>>"); AnalyticsApi api = new AnalyticsApi(); api.....
John_Carnell | 2021-10-26 12:28:21 UTC | #3
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
c.lopez | 2021-11-04 06:36:11 UTC | #4
Hi,
I found a solution here: https://www.stefanbruhns.tech/make-http-get-post-requests-java/
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("granttype=clientcredentials&clientid=" + Config.CLIENTID + "&clientsecret=" + Config.CLIENTSECRET); HashMap<String, String> params = new HashMap<String, String>(); request.params = params; ProxyAuthenticator authenticator = new ProxyAuthenticator(Config.PROXYUSER, Config.PROXYPASS); ProxyFactory proxyFactory = new ProxyFactory(Config.PROXYURL, Config.PROXYPORT, 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
system | 2021-12-04 07:26:17 UTC | #5
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 12445