LINE.apk(点击下载) / YahooJapanAccount.java


package jp.naver.line.android.sns.yahoo;

import ai.clova.cic.clientlib.exoplayer2.metadata.icy.IcyHeaders;
import android.content.Context;
import android.net.Uri;
import android.util.Base64;
import androidx.lifecycle.c0;
import androidx.lifecycle.d0;
import com.linecorp.andromeda.Universe;
import com.linecorp.line.constants.BuildConfig;
import dz2.c;
import dz2.g;
import dz2.i;
import dz2.j;
import dz2.k;
import dz2.l;
import dz2.n;
import dz2.o;
import dz2.r;
import em3.q;
import g93.m;
import java.io.IOException;
import java.math.RoundingMode;
import java.security.MessageDigest;
import java.security.SecureRandom;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import kotlin.NoWhenBranchMatchedException;
import kotlin.TuplesKt;
import n7.h;
import okhttp3.Request;
import okhttp3.RequestBody;
import ql3.f0;
import ql3.g0;
import ql3.p;
import ql3.u;
import ra.h0;
import wg.a;
import yi3.c;
import yi3.e;
import yi3.f;
import yk3.ai;
import zi3.b;
import zi3.d;

public final class YahooJapanAccount implements f {

    /* renamed from: i  reason: collision with root package name */
    public static final String f97777i;

    /* renamed from: j  reason: collision with root package name */
    public static final String f97778j;

    /* renamed from: k  reason: collision with root package name */
    public static final Map<String, String> f97779k = g0.j(TuplesKt.to("utm_source", "line"), TuplesKt.to("utm_medium", "line"));

    /* renamed from: a  reason: collision with root package name */
    public final Context f97780a;

    /* renamed from: b  reason: collision with root package name */
    public final e f97781b;

    /* renamed from: c  reason: collision with root package name */
    public final Set<r> f97782c = h.n(r.OPENID);

    /* renamed from: d  reason: collision with root package name */
    public final c f97783d = c.S256;

    /* renamed from: e  reason: collision with root package name */
    public final d f97784e;

    /* renamed from: f  reason: collision with root package name */
    public String f97785f;

    /* renamed from: g  reason: collision with root package name */
    public final c0 f97786g;

    /* renamed from: h  reason: collision with root package name */
    public final j f97787h;

    public static final class a implements j {

        /* renamed from: a  reason: collision with root package name */
        public final /* synthetic */ YahooJapanAccount f97788a;

        public a(YahooJapanAccount yahooJapanAccount) {
            this.f97788a = yahooJapanAccount;
        }

        @Override // dz2.j
        public void a() {
        }

        @Override // dz2.j
        public void b(n nVar) {
            q.f(nVar, "loginResult");
            YahooJapanAccount yahooJapanAccount = this.f97788a;
            Objects.requireNonNull(yahooJapanAccount);
            String str = nVar.f65793a;
            List j14 = p.j("Login succeeded...");
            j14.add(nVar.toString());
            j14.add("authorization code: " + str);
            j14.add("state: " + nVar.f65794b);
            u.Z(j14, "\n", null, null, 0, null, null, 62);
            d dVar = yahooJapanAccount.f97784e;
            String str2 = yahooJapanAccount.f97785f;
            zi3.a aVar = new zi3.a(yahooJapanAccount);
            b bVar = new b(yahooJapanAccount);
            Objects.requireNonNull(dVar);
            q.f(str, "authenticationCode");
            q.f(str2, "codeVerifier");
            StringBuilder a14 = b.d.a("grant_type=authorization_code\n&client_id=");
            z1.a.a(a14, d.f199416d, "\n&code=", str, "\n&redirect_uri=");
            dVar.f199419b.newCall(new Request.Builder().url(d.f199415c).post(RequestBody.Companion.create(a1.e.a(a14, dVar.f199418a, "\n&code_verifier=", str2), d.f199417e)).build()).enqueue(new zi3.c(bVar, aVar));
        }

        @Override // dz2.j
        public void c(i iVar) {
            q.f(iVar, "loginError");
            YahooJapanAccount yahooJapanAccount = this.f97788a;
            Objects.requireNonNull(yahooJapanAccount);
            List j14 = p.j("Login failed...");
            j14.add(iVar.toString());
            if (iVar instanceof i.a) {
                StringBuilder a14 = b.d.a("reason: ");
                i.a aVar = (i.a) iVar;
                a14.append(dz2.e.b(aVar.f65775a));
                j14.add(a14.toString());
                j14.add("detail: " + aVar.f65776b);
                yahooJapanAccount.f97781b.a(m.YAHOOJAPAN, new IllegalStateException(u.Z(j14, "\n", null, null, 0, null, null, 62)));
            } else if (iVar instanceof i.b) {
                StringBuilder a15 = b.d.a("reason: ");
                a15.append(g.a(((i.b) iVar).f65777a));
                j14.add(a15.toString());
                yahooJapanAccount.f97781b.a(m.YAHOOJAPAN, new IllegalStateException(u.Z(j14, "\n", null, null, 0, null, null, 62)));
            } else if (iVar instanceof i.e) {
                yahooJapanAccount.f97781b.c(m.YAHOOJAPAN);
            } else {
                yahooJapanAccount.f97781b.a(m.YAHOOJAPAN, new IllegalStateException(u.Z(j14, "\n", null, null, 0, null, null, 62)));
            }
            u.Z(j14, "\n", null, null, 0, null, null, 62);
        }
    }

    static {
        String str = BuildConfig.YAHOO_JAPAN_CLIENT_ID;
        q.e(str, "YAHOO_JAPAN_CLIENT_ID");
        f97777i = str;
        String str2 = BuildConfig.YAHOO_JAPAN_CONNECT_URL;
        q.e(str2, "YAHOO_JAPAN_CONNECT_URL");
        f97778j = str2;
    }

    public YahooJapanAccount(Context context, e eVar, d0 d0Var) {
        q.f(context, "context");
        q.f(eVar, "onAuthListener");
        q.f(d0Var, "lifecycleOwner");
        this.f97780a = context;
        this.f97781b = eVar;
        StringBuilder a14 = b.d.a("android-app://");
        a14.append(context.getPackageName());
        a14.append("/yj-line-connect//");
        String sb4 = a14.toString();
        this.f97784e = new d(context, sb4);
        this.f97785f = "";
        YahooJapanAccount$lifecycleObserver$1 yahooJapanAccount$lifecycleObserver$1 = new YahooJapanAccount$lifecycleObserver$1();
        this.f97786g = yahooJapanAccount$lifecycleObserver$1;
        a aVar = new a(this);
        this.f97787h = aVar;
        l lVar = l.f65782a;
        String str = f97777i;
        Uri parse = Uri.parse(sb4);
        q.e(parse, "parse(this)");
        q.f(str, "clientId");
        l.f65783b = new dz2.h(str, parse, null, false, 12);
        Uri parse2 = Uri.parse(f97778j);
        q.e(parse2, "parse(YJ_CONNECT_URL)");
        String authority = parse2.getAuthority();
        q.d(authority);
        if (!sm3.r.q(authority, "yahoo.co.jp", false, 2)) {
            throw new RuntimeException("[yjloginsdk] Please set valid issuer.");
        } else if (q.b(parse2.getPath(), "/yconnect/v2")) {
            dz2.h hVar = l.f65783b;
            if (hVar != null) {
                hVar.f65773c = parse2;
            }
            l.f65784c = aVar;
            d0Var.getLifecycle().a(yahooJapanAccount$lifecycleObserver$1);
        } else {
            throw new RuntimeException("[yjloginsdk] Please set valid issuer.");
        }
    }

    @Override // yi3.f
    public void a(yi3.c cVar) {
        Map map;
        Set n14;
        String str;
        if (cVar instanceof c.C3465c) {
            c.C3465c cVar2 = (c.C3465c) cVar;
            c.C3465c.a aVar = cVar2.f188766b;
            if (aVar instanceof c.C3465c.a.C3466a) {
                map = g0.j(TuplesKt.to("utm_campaign", "setting"), TuplesKt.to("login_hint", ((c.C3465c.a.C3466a) aVar).f188767a));
            } else if (q.b(aVar, c.C3465c.a.b.f188768a)) {
                map = f0.b(TuplesKt.to("utm_campaign", "recovery"));
            } else {
                throw new NoWhenBranchMatchedException();
            }
            Map n15 = g0.n(f97779k, map);
            c.C3465c.a aVar2 = cVar2.f188766b;
            if (aVar2 instanceof c.C3465c.a.C3466a) {
                n14 = h.n(dz2.p.CONSENT);
            } else if (q.b(aVar2, c.C3465c.a.b.f188768a)) {
                n14 = h.n(dz2.p.LOGIN);
            } else {
                throw new NoWhenBranchMatchedException();
            }
            l lVar = l.f65782a;
            Context context = this.f97780a;
            Set<r> set = this.f97782c;
            String str2 = cVar2.f188765a;
            byte[] bArr = new byte[32];
            new SecureRandom().nextBytes(bArr);
            String encodeToString = Base64.encodeToString(bArr, 11);
            q.e(encodeToString, "encodeToString(code, Bas…RAP or Base64.NO_PADDING)");
            this.f97785f = encodeToString;
            byte[] bytes = encodeToString.getBytes(sm3.b.f143621c);
            q.e(bytes, "this as java.lang.String).getBytes(charset)");
            MessageDigest instance = MessageDigest.getInstance("SHA-256");
            q.e(instance, "getInstance(\"SHA-256\")");
            instance.update(bytes, 0, bytes.length);
            byte[] digest = instance.digest();
            q.e(digest, "messageDigest.digest()");
            a.e eVar = (a.e) wg.a.f176900b;
            Character ch4 = eVar.f176911d;
            a.e eVar2 = eVar;
            if (ch4 != null) {
                eVar2 = eVar.f(eVar.f176910c, null);
            }
            Objects.requireNonNull(eVar2);
            int length = digest.length;
            h0.m(0, length + 0, digest.length);
            a.C3209a aVar3 = eVar2.f176910c;
            StringBuilder sb4 = new StringBuilder(xg.a.a(length, aVar3.f176906f, RoundingMode.CEILING) * aVar3.f176905e);
            try {
                eVar2.c(sb4, digest, 0, length);
                String sb5 = sb4.toString();
                q.e(sb5, "base64Url().omitPadding().encode(digest)");
                dz2.c cVar3 = this.f97783d;
                q.f(context, "context");
                q.f(set, "scopes");
                q.f(str2, "nonce");
                q.f(cVar3, "codeChallengeMethod");
                j jVar = l.f65784c;
                dz2.h hVar = l.f65783b;
                if (hVar != null) {
                    pc.b bVar = (pc.b) a1.g.f186d;
                    bVar.b("Begin to login");
                    if (jVar != null) {
                        jVar.a();
                    }
                    dz2.f fVar = l.f65785d;
                    if (fVar != null && fVar.a()) {
                        bVar.b("Login process running");
                        if (jVar != null) {
                            jVar.c(i.c.f65778a);
                            return;
                        }
                        return;
                    }
                    Uri uri = hVar.f65773c;
                    if (uri == null) {
                        str = null;
                    } else {
                        str = uri.toString();
                    }
                    if (str == null) {
                        str = "https://auth.login.yahoo.co.jp/yconnect/v2";
                    }
                    String str3 = hVar.f65771a;
                    String uri2 = hVar.f65772b.toString();
                    q.e(uri2, "configuration.redirectUri.toString()");
                    dz2.q qVar = dz2.q.CODE;
                    byte[] bArr2 = new byte[32];
                    new SecureRandom().nextBytes(bArr2);
                    String encodeToString2 = Base64.encodeToString(bArr2, 11);
                    q.e(encodeToString2, "encodeToString(\n        …G or Base64.NO_WRAP\n    )");
                    q.f(str3, "clientId");
                    q.f(qVar, "responseType");
                    Map l14 = g0.l(TuplesKt.to("client_id", str3), TuplesKt.to("redirect_uri", uri2), TuplesKt.to("response_type", qVar.d()), TuplesKt.to("scope", u.Z(set, " ", null, null, 0, null, dz2.a.f65766b, 30)), TuplesKt.to("nonce", str2), TuplesKt.to("code_challenge", sb5), TuplesKt.to("code_challenge_method", cVar3.d()), TuplesKt.to(Universe.EXTRA_STATE, encodeToString2));
                    LinkedHashMap linkedHashMap = new LinkedHashMap();
                    linkedHashMap.putAll(l14);
                    LinkedHashMap linkedHashMap2 = new LinkedHashMap();
                    linkedHashMap2.put("bail", IcyHeaders.REQUEST_HEADER_ENABLE_METADATA_VALUE);
                    linkedHashMap2.put("prompt", u.Z(n14, " ", null, null, 0, null, o.f65795b, 30));
                    for (Map.Entry entry : n15.entrySet()) {
                        linkedHashMap2.put(entry.getKey(), entry.getValue());
                    }
                    linkedHashMap.putAll(linkedHashMap2);
                    Uri.Builder buildUpon = Uri.parse(q.j(str, "/authorization")).buildUpon();
                    for (Map.Entry entry2 : linkedHashMap.entrySet()) {
                        buildUpon.appendQueryParameter((String) entry2.getKey(), (String) entry2.getValue());
                    }
                    Uri build = buildUpon.build();
                    q.e(build, "builder.build()");
                    dz2.m mVar = new dz2.m(context, build, hVar.f65774d, new k(jVar));
                    l.f65785d = mVar;
                    mVar.d();
                    return;
                }
                throw new RuntimeException("[yjloginsdk] Please call setup function before login.");
            } catch (IOException e14) {
                throw new AssertionError(e14);
            }
        } else {
            throw new IllegalStateException("Check failed.".toString());
        }
    }

    @Override // yi3.f
    public void logout() {
        yi3.a.a(this.f97780a.getApplicationContext(), ai.YAHOOJAPAN);
    }
}