use of okhttp3.Credentials in project instagram-java-scraper by postaddictme.
the class AuthenticatedInstaTest method setUp.
@BeforeClass
public static void setUp() throws Exception {
Credentials credentials = new Credentials();
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);
OkHttpClient httpClient = new OkHttpClient.Builder().addNetworkInterceptor(loggingInterceptor).addInterceptor(new FakeBrowserInterceptor(UserAgents.OSX_CHROME)).addInterceptor(new ErrorInterceptor()).cookieJar(new DefaultCookieJar(new CookieHashSet())).build();
client = new Instagram(httpClient);
client.basePage();
client.login(credentials.getLogin(), credentials.getPassword());
client.basePage();
}
use of okhttp3.Credentials in project java-cloudant by cloudant.
the class CloudantClientTests method testBasicAuthFromCredentials.
/**
* Test that configuring the Basic Authentication interceptor from credentials and adding to
* the CloudantClient works.
*/
@Test
public void testBasicAuthFromCredentials() throws Exception {
BasicAuthInterceptor interceptor = BasicAuthInterceptor.createFromCredentials("username", "password");
// send back a mock OK 200
server.enqueue(new MockResponse());
CloudantClient client = CloudantClientHelper.newMockWebServerClientBuilder(server).interceptors(interceptor).build();
client.getAllDbs();
// expected 'username:password'
assertEquals("Basic dXNlcm5hbWU6cGFzc3dvcmQ=", server.takeRequest().getHeader("Authorization"));
}
use of okhttp3.Credentials in project java-cloudant by cloudant.
the class HttpTest method badCredsCookieThrows.
/**
* Test that cookie authentication throws a CouchDbException if the credentials were bad.
*
* @throws Exception
*/
@TestTemplate
public void badCredsCookieThrows() {
mockWebServer.enqueue(new MockResponse().setResponseCode(401));
CloudantClient c = CloudantClientHelper.newMockWebServerClientBuilder(mockWebServer).username("bad").password("worse").build();
CouchDbException re = assertThrows(CouchDbException.class, () -> c.executeRequest(Http.GET(c.getBaseUri())).responseAsString(), "Bad credentials should throw a CouchDbException.");
assertTrue(re.getMessage().startsWith("401 Credentials are incorrect for server"), "The " + "exception should have been for bad creds.");
}
use of okhttp3.Credentials in project azure-sdk-for-java by Azure.
the class ProviderRegistrationInterceptor method intercept.
@Override
public Response intercept(Chain chain) throws IOException {
Response response = chain.proceed(chain.request());
if (!response.isSuccessful()) {
String content = errorBody(response.body());
AzureJacksonAdapter jacksonAdapter = new AzureJacksonAdapter();
CloudError cloudError = jacksonAdapter.deserialize(content, CloudError.class);
if (cloudError != null && "MissingSubscriptionRegistration".equals(cloudError.code())) {
Pattern pattern = Pattern.compile("/subscriptions/([\\w-]+)/", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(chain.request().url().toString());
matcher.find();
RestClient restClient = new RestClient.Builder().withBaseUrl("https://" + chain.request().url().host()).withCredentials(credentials).withSerializerAdapter(jacksonAdapter).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).build();
ResourceManager resourceManager = ResourceManager.authenticate(restClient).withSubscription(matcher.group(1));
pattern = Pattern.compile(".*'(.*)'");
matcher = pattern.matcher(cloudError.message());
matcher.find();
Provider provider = registerProvider(matcher.group(1), resourceManager);
while (provider.registrationState().equalsIgnoreCase("Unregistered") || provider.registrationState().equalsIgnoreCase("Registering")) {
SdkContext.sleep(5 * 1000);
provider = resourceManager.providers().getByName(provider.namespace());
}
// Retry
response = chain.proceed(chain.request());
}
}
return response;
}
use of okhttp3.Credentials in project azure-sdk-for-java by Azure.
the class KeyVaultClientImpl method setCertificateIssuerWithServiceResponseAsync.
/**
* Sets the specified certificate issuer.
*
* @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net.
* @param issuerName The name of the issuer.
* @param provider The issuer provider.
* @param credentials The credentials to be used for the issuer.
* @param organizationDetails Details of the organization as provided to the issuer.
* @param attributes Attributes of the issuer object.
* @return the observable to the IssuerBundle object
*/
public Observable<ServiceResponse<IssuerBundle>> setCertificateIssuerWithServiceResponseAsync(String vaultBaseUrl, String issuerName, String provider, IssuerCredentials credentials, OrganizationDetails organizationDetails, IssuerAttributes attributes) {
if (vaultBaseUrl == null) {
throw new IllegalArgumentException("Parameter vaultBaseUrl is required and cannot be null.");
}
if (issuerName == null) {
throw new IllegalArgumentException("Parameter issuerName is required and cannot be null.");
}
if (this.apiVersion() == null) {
throw new IllegalArgumentException("Parameter this.apiVersion() is required and cannot be null.");
}
if (provider == null) {
throw new IllegalArgumentException("Parameter provider is required and cannot be null.");
}
Validator.validate(credentials);
Validator.validate(organizationDetails);
Validator.validate(attributes);
CertificateIssuerSetParameters parameter = new CertificateIssuerSetParameters();
parameter.withProvider(provider);
parameter.withCredentials(credentials);
parameter.withOrganizationDetails(organizationDetails);
parameter.withAttributes(attributes);
String parameterizedHost = Joiner.on(", ").join("{vaultBaseUrl}", vaultBaseUrl);
return service.setCertificateIssuer(issuerName, this.apiVersion(), this.acceptLanguage(), parameter, parameterizedHost, this.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<IssuerBundle>>>() {
@Override
public Observable<ServiceResponse<IssuerBundle>> call(Response<ResponseBody> response) {
try {
ServiceResponse<IssuerBundle> clientResponse = setCertificateIssuerDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
Aggregations