Wallkin v1.86859532693版本的 MD5 值为:c3099a56aae2c3706b2239994117cc3a
以下内容为反编译后的 d.java 源代码,内容仅作参考
package com.joaomgcd.taskerm.net.auth;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import c.a.z;
import c.f.b.k;
import c.f.b.l;
import c.l.n;
import c.q;
import c.s;
import com.joaomgcd.taskerm.net.auth.b;
import com.joaomgcd.taskerm.net.o;
import com.joaomgcd.taskerm.rx.b;
import com.joaomgcd.taskerm.util.al;
import com.joaomgcd.taskerm.util.an;
import com.joaomgcd.taskerm.util.ao;
import java.net.HttpURLConnection;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.json.JSONObject;
public final class d implements com.joaomgcd.taskerm.net.auth.b {
private final Context f8119a;
private final String f8120b;
private final String f8121c;
private final String f8122d;
private final String f8123e;
private final String[] f8124f;
private final i g;
private final boolean h;
public static final class c extends l implements c.f.a.b<HttpURLConnection, s> {
final boolean f8130b;
c(boolean z) {
super(1);
this.f8130b = z;
}
@Override
public s invoke(HttpURLConnection httpURLConnection) {
a(httpURLConnection);
return s.f2131a;
}
public final void a(HttpURLConnection httpURLConnection) {
k.b(httpURLConnection, "it");
if (this.f8130b) {
String a2 = d.this.a(d.this.f8120b, d.this.f8121c);
k.a((Object) a2, "base64EncodeUserPass(clientId, clientSecret)");
an.a(httpURLConnection, a2);
}
an.b(httpURLConnection, d.this.g.a());
}
}
public d(Context context, String str, String str2, String str3, String str4, String[] strArr, i iVar, boolean z) {
k.b(context, "context");
k.b(str, "clientId");
k.b(str2, "clientSecret");
k.b(str3, "endpointCode");
k.b(str4, "endpointRefresh");
k.b(strArr, "scopes");
k.b(iVar, "tokenDataType");
this.f8119a = context;
this.f8120b = str;
this.f8121c = str2;
this.f8122d = str3;
this.f8123e = str4;
this.f8124f = strArr;
this.g = iVar;
this.h = z;
}
public String a(String str, String str2) {
k.b(str, "user");
k.b(str2, "pass");
return b.a.a(this, str, str2);
}
public String a(JSONObject jSONObject) {
k.b(jSONObject, "receiver$0");
return b.a.a(this, jSONObject);
}
public Long b(JSONObject jSONObject) {
k.b(jSONObject, "receiver$0");
return b.a.b(this, jSONObject);
}
public String c(JSONObject jSONObject) {
k.b(jSONObject, "receiver$0");
return b.a.c(this, jSONObject);
}
public d(Context context, String str, String str2, String str3, String str4, String[] strArr, i iVar, boolean z, int i, c.f.b.g gVar) {
this(context, str, str2, str3, str4, strArr, (i & 64) != 0 ? i.form : iVar, (i & 128) != 0 ? false : z);
}
private final String a() {
return c.a.d.a(this.f8124f, " ", (CharSequence) null, (CharSequence) null, 0, (CharSequence) null, (c.f.a.b) null, 62, (Object) null);
}
private final String a(boolean z) {
HashMap b2;
List<c.k> d2;
Uri.Builder appendQueryParameter = Uri.parse(this.f8122d).buildUpon().appendQueryParameter("client_id", this.f8120b).appendQueryParameter("response_type", "code");
String uuid = UUID.randomUUID().toString();
k.a((Object) uuid, "UUID.randomUUID().toString()");
Uri.Builder appendQueryParameter2 = appendQueryParameter.appendQueryParameter("state", n.a(uuid, "-", "", false, 4, (Object) null));
if (z) {
appendQueryParameter2.appendQueryParameter("redirect_uri", "https://tasker.joaoapps.com/auth.html");
}
if (!(this.f8124f.length == 0)) {
appendQueryParameter2.appendQueryParameter("scope", a());
}
b2 = f.b();
HashMap hashMap = (HashMap) b2.get(this.f8122d);
if (hashMap != null && (d2 = z.d(hashMap)) != null) {
for (c.k kVar : d2) {
appendQueryParameter2.appendQueryParameter((String) kVar.a(), (String) kVar.b());
}
}
if (this.h) {
appendQueryParameter2.appendQueryParameter("show_dialog", "true");
}
String uri = appendQueryParameter2.build().toString();
k.a((Object) uri, "Uri.parse(endpointCode).… .build().toString()");
return uri;
}
private final String b(String str, String str2) {
JSONObject jSONObject = new JSONObject();
jSONObject.put("grant_type", "authorization_code");
jSONObject.put("code", str);
if (str2 == null) {
str2 = "https://tasker.joaoapps.com/auth.html";
}
jSONObject.put("redirect_uri", str2);
jSONObject.put("client_id", this.f8120b);
jSONObject.put("client_secret", this.f8121c);
switch (this.g) {
case json:
String jSONObject2 = jSONObject.toString();
k.a((Object) jSONObject2, "fields.toString()");
return jSONObject2;
case form:
return an.a(jSONObject);
default:
throw new c.i();
}
}
private final String a(String str) {
JSONObject jSONObject = new JSONObject();
jSONObject.put("grant_type", "refresh_token");
jSONObject.put("refresh_token", str);
switch (this.g) {
case json:
String jSONObject2 = jSONObject.toString();
k.a((Object) jSONObject2, "fields.toString()");
return jSONObject2;
case form:
return an.a(jSONObject);
default:
throw new c.i();
}
}
private final String a(String str, boolean z) {
com.joaomgcd.taskerm.net.d dVar = new com.joaomgcd.taskerm.net.d(str, this.f8123e, null, null, 12, null);
dVar.a(new c(z));
return (String) com.joaomgcd.taskerm.net.l.a(new o(dVar), null, 1, null);
}
public static final class b<T> implements b.a.d.i<Object> {
public static final b f8128a = new b();
@Override
public final boolean a(Object obj) {
k.b(obj, "it");
return obj instanceof com.joaomgcd.taskerm.net.auth.a;
}
}
@Override
public b.a.l<h> a(long j) {
return com.joaomgcd.taskerm.rx.h.b(new a(j));
}
static final class a extends l implements c.f.a.a<C0209a> {
final long f8126b;
a(long j) {
super(0);
this.f8126b = j;
}
@Override
public final C0209a invoke() {
AuthInfo c2 = d.this.h ? null : d.this.c();
if (c2 == null) {
c2 = d.this.b(this.f8126b);
} else if (c2.isExpired()) {
c2 = d.this.a(c2, this.f8126b);
}
d.this.a(c2);
return new C0209a(c2);
}
public static final class C0209a extends h {
final AuthInfo f8127a;
C0209a(AuthInfo authInfo) {
this.f8127a = authInfo;
}
@Override
public void a(HashMap<String, String> hashMap) {
k.b(hashMap, "headers");
hashMap.put(this.f8127a.getAuthHeaderKey(), this.f8127a.getAuthHeaderValue());
}
}
}
public final AuthInfo a(AuthInfo authInfo, long j) {
try {
String refreshToken = authInfo.getRefreshToken();
if (refreshToken != null) {
JSONObject jSONObject = new JSONObject(a(a(refreshToken), true));
String c2 = c(jSONObject);
if (c2 == null) {
c2 = refreshToken;
}
String a2 = a(jSONObject);
if (a2 == null) {
throw new RuntimeException("Could not get access token");
}
return new AuthInfo(c2, a2, b(jSONObject));
}
return authInfo;
} catch (com.joaomgcd.taskerm.net.i unused) {
a((AuthInfo) null);
return b(j);
}
}
public final AuthInfo b(long j) {
String queryParameter;
String str = an.a(ao.C(this.f8122d)).get("redirect_uri");
String str2 = str;
al.a(this.f8119a, a(str2 == null || str2.length() == 0), true, false, true);
String str3 = null;
try {
c.f.a.b bVar = null;
b.a.h<Object> a2 = com.joaomgcd.taskerm.rx.b.f8673b.a().a((b.a.d.i<? super Object>) b.f8128a);
if (a2 != null) {
b.a.l<Object> a3 = a2.d().a();
if (a3 == null) {
throw new q("null cannot be cast to non-null type io.reactivex.Single<T>");
}
b.a.l<Object> b2 = a3.b(j, TimeUnit.MILLISECONDS);
k.a((Object) b2, "result.timeout(it, TimeUnit.MILLISECONDS)");
b2.a(b.c.f8684a, b.d.f8685a);
Uri a4 = ((com.joaomgcd.taskerm.net.auth.a) b2.b()).a();
if (a4 != null && (queryParameter = a4.getQueryParameter("error")) != null) {
throw new RuntimeException("Error getting code: " + queryParameter);
}
if (str3 == null) {
throw new RuntimeException("Could not get code");
}
JSONObject jSONObject = new JSONObject(a(b(str3, str), false));
String c2 = c(jSONObject);
String a5 = a(jSONObject);
if (a5 == null) {
throw new RuntimeException("Could not get access token");
}
return new AuthInfo(c2, a5, b(jSONObject));
}
throw new q("null cannot be cast to non-null type io.reactivex.Observable<T>");
} catch (RuntimeException e2) {
throw e2;
} catch (Exception unused) {
throw new RuntimeException("Timed out while getting code");
}
}
private final String b() {
return this.f8120b + ':' + this.f8121c + ':' + this.f8122d + ':' + this.f8123e + ':' + a();
}
public final AuthInfo c() {
Context context = this.f8119a;
String b2 = b();
SharedPreferences a2 = com.joaomgcd.taskerm.net.auth.c.a(this.f8119a);
k.a((Object) a2, "context.preferencesHttpAuth");
String string = a2.getString(b2, null);
return (AuthInfo) (string != null ? com.joaomgcd.taskerm.n.b.a().a(string, (Class<Object>) AuthInfo.class) : null);
}
public final void a(AuthInfo authInfo) {
Context context = this.f8119a;
String b2 = b();
SharedPreferences a2 = com.joaomgcd.taskerm.net.auth.c.a(this.f8119a);
k.a((Object) a2, "context.preferencesHttpAuth");
com.joaomgcd.taskerm.q.b.a(context, b2, authInfo, a2);
}
}