use of org.apache.http.auth.AuthScope in project api-snippets by TwilioDevEd.
the class Example method main.
public static void main(String[] args) throws Exception {
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope("lookups.twilio.com", 80), new UsernamePasswordCredentials("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "your_auth_token"));
CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
try {
HttpGet httpget = new HttpGet("https://lookups.twilio.com/v1/PhoneNumbers/+16502530000/?AddOns=payfone_tcpa_compliance&AddOns.payfone_tcpa_compliance.RightPartyContactedDate=20160101");
System.out.println("Executing request " + httpget.getRequestLine());
CloseableHttpResponse response = httpclient.execute(httpget);
try {
System.out.println(response.getStatusLine());
System.out.println(EntityUtils.toString(response.getEntity()));
} finally {
response.close();
}
} finally {
httpclient.close();
}
}
use of org.apache.http.auth.AuthScope in project SeaStar by 13120241790.
the class SyncHttpClient method setBasicAuth.
/**
* Sets basic authentication for the request. Uses AuthScope.ANY. This is
* the same as setBasicAuth('username','password',AuthScope.ANY)
*
* @param username
* Basic Auth username
* @param password
* Basic Auth password
*/
public void setBasicAuth(String username, String password) {
AuthScope scope = AuthScope.ANY;
setBasicAuth(username, password, scope);
}
use of org.apache.http.auth.AuthScope in project SeaStar by 13120241790.
the class AsyncHttpClient method setBasicAuth.
/**
* Sets basic authentication for the request. Uses AuthScope.ANY. This is the same as
* setBasicAuth('username','password',AuthScope.ANY)
*
* @param username Basic Auth username
* @param password Basic Auth password
*/
public void setBasicAuth(String username, String password) {
AuthScope scope = AuthScope.ANY;
setBasicAuth(username, password, scope);
}
use of org.apache.http.auth.AuthScope in project orientdb by orientechnologies.
the class BaseHttpTest method exec.
protected BaseHttpTest exec() throws IOException {
final HttpHost targetHost = new HttpHost(getHost(), getPort(), getProtocol());
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(targetHost), new UsernamePasswordCredentials(getUserName(), getUserPassword()));
// Create AuthCache instance
AuthCache authCache = new BasicAuthCache();
// Generate BASIC scheme object and add it to the local auth cache
BasicScheme basicAuth = new BasicScheme();
authCache.put(targetHost, basicAuth);
// Add AuthCache to the execution context
HttpClientContext context = HttpClientContext.create();
context.setCredentialsProvider(credsProvider);
context.setAuthCache(authCache);
if (keepAlive != null)
request.addHeader("Connection", keepAlive ? "Keep-Alive" : "Close");
if (payload != null && request instanceof HttpEntityEnclosingRequestBase)
((HttpEntityEnclosingRequestBase) request).setEntity(payload);
final CloseableHttpClient httpClient = HttpClients.createDefault();
// DefaultHttpMethodRetryHandler retryhandler = new DefaultHttpMethodRetryHandler(retry, false);
// context.setAttribute(HttpMethodParams.RETRY_HANDLER, retryhandler);
response = httpClient.execute(targetHost, request, context);
return this;
}
use of org.apache.http.auth.AuthScope in project apex-core by apache.
the class WebServicesClientTest method checkUserCredentials.
public static void checkUserCredentials(String username, String password, AuthScheme authScheme) throws NoSuchFieldException, IllegalAccessException {
CredentialsProvider provider = getCredentialsProvider();
String httpScheme = AuthScope.ANY_SCHEME;
if (authScheme == AuthScheme.BASIC) {
httpScheme = AuthSchemes.BASIC;
} else if (authScheme == AuthScheme.DIGEST) {
httpScheme = AuthSchemes.DIGEST;
}
AuthScope authScope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, httpScheme);
Credentials credentials = provider.getCredentials(authScope);
Assert.assertNotNull("Credentials", credentials);
Assert.assertTrue("Credentials type is user", UsernamePasswordCredentials.class.isAssignableFrom(credentials.getClass()));
UsernamePasswordCredentials pwdCredentials = (UsernamePasswordCredentials) credentials;
Assert.assertEquals("Username", username, pwdCredentials.getUserName());
Assert.assertEquals("Password", password, pwdCredentials.getPassword());
}
Aggregations