use of okhttp3.Challenge in project MiMangaNu by raulhaag.
the class CFInterceptor method resolveOverCF.
public Response resolveOverCF(Chain chain, Response response) throws IOException {
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Request request = response.request();
String content = response.body().string();
String domain = request.url().host().trim();
String rawOperation = getFirstMatch(OPERATION_PATTERN, content);
String challenge = getFirstMatch(CHALLENGE_PATTERN, content);
String challengePass = getFirstMatch(PASS_PATTERN, content);
if (rawOperation == null || challengePass == null || challenge == null) {
Log.e("CFI", "couldn't resolve over cloudflare");
// returning null here is not a good idea since it could stop a download ~xtj-9182
return response;
}
String operation = rawOperation.replaceAll("a\\.value =(.+?) \\+ .+?;.*", "$1").replaceAll("\\s{3,}[a-z](?: = |\\.).+", "");
String js = operation.replace("\n", "");
Duktape duktape = Duktape.create();
long result = 0;
try {
String res = (String) duktape.evaluate(js + ".toString()");
result = Long.parseLong(res);
} catch (Exception e) {
e.printStackTrace();
} finally {
duktape.close();
}
String answer = String.valueOf(result + domain.length());
String url = new HttpUrl.Builder().scheme("http").host(domain).addPathSegment("cdn-cgi").addPathSegment("l").addPathSegment("chk_jschl").addEncodedQueryParameter("jschl_vc", challenge).addEncodedQueryParameter("pass", challengePass).addEncodedQueryParameter("jschl_answer", answer).build().toString();
Request request1 = new Request.Builder().url(url).header("User-Agent", Navigator.USER_AGENT).header("Referer", request.url().toString()).build();
response.body().close();
// generate the cookie
response = chain.proceed(request1);
response.body().close();
try {
// give it a time and complete the 5 seconds
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
response = chain.proceed(request.newBuilder().build());
return response;
}
use of okhttp3.Challenge in project okhttp-digest by rburgst.
the class WrongOrderedAuthenticationHeaderTest method testWithCorrectOrder.
/**
* See: https://github.com/square/okhttp/issues/2780
*/
@Test
public void testWithCorrectOrder() {
// Strict RFC 2617 header
Headers headers = new Headers.Builder().add("WWW-Authenticate", "Digest realm=\"myrealm\", nonce=\"fjalskdflwejrlaskdfjlaskdjflaksjdflkasdf\", qop=\"auth\", stale=\"FALSE\"").build();
List<Challenge> challenges = HttpHeaders.parseChallenges(headers, "WWW-Authenticate");
assertEquals(1, challenges.size());
assertEquals("Digest", challenges.get(0).scheme());
assertEquals("myrealm", challenges.get(0).realm());
}
use of okhttp3.Challenge in project okhttp-digest by rburgst.
the class WrongOrderedAuthenticationHeaderTest method testWithWrongOrder.
@Test
public void testWithWrongOrder() {
// Not strict RFC 2617 header.
Headers headers = new Headers.Builder().add("WWW-Authenticate", "Digest qop=\"auth\", realm=\"myrealm\", nonce=\"fjalskdflwejrlaskdfjlaskdjflaksjdflkasdf\", stale=\"FALSE\"").build();
List<Challenge> challenges = HttpHeaders.parseChallenges(headers, "WWW-Authenticate");
assertEquals(1, challenges.size());
assertEquals(1, challenges.size());
assertEquals("Digest", challenges.get(0).scheme());
assertEquals("myrealm", challenges.get(0).realm());
}
use of okhttp3.Challenge in project okhttp-digest by rburgst.
the class DispatchingAuthenticator method authenticate.
@Override
public Request authenticate(Route route, Response response) throws IOException {
List<Challenge> challenges = response.challenges();
if (!challenges.isEmpty()) {
for (Challenge challenge : challenges) {
final String scheme = challenge.scheme();
Authenticator authenticator = null;
if (scheme != null) {
authenticator = authenticatorRegistry.get(scheme.toLowerCase(Locale.getDefault()));
}
if (authenticator != null) {
return authenticator.authenticate(route, response);
}
}
}
throw new IllegalArgumentException("unsupported auth scheme " + challenges);
}
use of okhttp3.Challenge in project legendarybot by greatman.
the class AffixPlugin method getWeekAffixes.
public Map<Long, String> getWeekAffixes(String region) throws IOException, ParseException {
Map<Long, String> affixes = new HashMap<>();
OkHttpClient clientBattleNet = new OkHttpClient.Builder().addInterceptor(new BattleNetAPIInterceptor(getBot())).build();
HttpUrl url = new HttpUrl.Builder().scheme("https").host(region + ".api.battle.net").addPathSegments("/data/wow/mythic-challenge-mode/").addQueryParameter("namespace", "dynamic-" + region).build();
Request request = new Request.Builder().url(url).build();
String result = clientBattleNet.newCall(request).execute().body().string();
JSONParser parser = new JSONParser();
JSONObject mythicPlusDocument = (JSONObject) parser.parse(result);
if (mythicPlusDocument.containsKey("current_keystone_affixes")) {
JSONArray array = (JSONArray) mythicPlusDocument.get("current_keystone_affixes");
for (Object keystoneAffixObject : array) {
JSONObject keystoneAffixJson = (JSONObject) keystoneAffixObject;
JSONObject keystoneAffixNameObject = (JSONObject) keystoneAffixJson.get("keystone_affix");
affixes.put((long) keystoneAffixJson.get("starting_level"), (String) keystoneAffixNameObject.get("name"));
}
}
return affixes;
}
Aggregations