diff --git a/capacitor.config.dev.json b/capacitor.config.dev.json index b93d060..a39ea36 100644 --- a/capacitor.config.dev.json +++ b/capacitor.config.dev.json @@ -6,9 +6,6 @@ "plugins": { "PushNotifications": { "presentationOptions": ["badge", "sound", "alert"] - }, - "CapacitorHttp": { - "enabled": true } }, "server": { diff --git a/capacitor.config.prod.json b/capacitor.config.prod.json index 550f490..cdfe998 100644 --- a/capacitor.config.prod.json +++ b/capacitor.config.prod.json @@ -6,9 +6,6 @@ "plugins": { "PushNotifications": { "presentationOptions": ["badge", "sound", "alert"] - }, - "CapacitorHttp": { - "enabled": true } } } diff --git a/ios/App/Podfile b/ios/App/Podfile index e9187b2..777e460 100644 --- a/ios/App/Podfile +++ b/ios/App/Podfile @@ -12,7 +12,6 @@ def capacitor_pods pod 'Capacitor', :path => '../../node_modules/@capacitor/ios' pod 'CapacitorCordova', :path => '../../node_modules/@capacitor/ios' pod 'CapacitorApp', :path => '../../node_modules/@capacitor/app' - pod 'CapacitorBrowser', :path => '../../node_modules/@capacitor/browser' pod 'CapacitorDevice', :path => '../../node_modules/@capacitor/device' pod 'CapacitorPreferences', :path => '../../node_modules/@capacitor/preferences' pod 'CapacitorPushNotifications', :path => '../../node_modules/@capacitor/push-notifications' diff --git a/package.json b/package.json index ad2bed7..0816ece 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,6 @@ "dependencies": { "@capacitor/android": "^4.5.0", "@capacitor/app": "^4.1.1", - "@capacitor/browser": "^4.1.1", "@capacitor/core": "^4.5.0", "@capacitor/device": "^4.1.0", "@capacitor/ios": "^4.5.0", diff --git a/src/components/MkSignin.vue b/src/components/MkSignin.vue index 479e5f9..294be55 100644 --- a/src/components/MkSignin.vue +++ b/src/components/MkSignin.vue @@ -19,7 +19,6 @@ required /> - ({ + allowCredentials: challengeData.securityKeys.map((key) => ({ id: byteify(key.id, "hex"), type: "public-key", transports: ["usb", "nfc", "ble", "internal"], @@ -171,38 +167,16 @@ function queryKey() { }); } -// TODO: Implement handling browser shutdown by user. -// On current implementation, arbitrary closing of browser by user is -// not detected. The button will be disabled until token fetching maxCount is reached. -// Also, MiAuth will try to get the token forever. -// Browser.addListener('browserFinished', ...) will work. -// https://capacitorjs.com/docs/apis/browser#addlistenerbrowserfinished- -async function onSubmit() { - const miauth = quickAuth(instanceUrlResult, {name: "missRirica", permission: Permissions}) - var maxCount = 100 - var miauthToken = "" +function onSubmit() { signing = true; - await Browser.open({url: miauth.authUrl(), presentationStyle: "popover"}) - - setTimeout(async function fetchToken() { - try { - maxCount-- - miauthToken = await miauth.getToken() - await Browser.close() // No-op in Android, User need to close Webview themselves. - login(miauthToken, instanceUrlResult) - signing = false - } catch (er) { - if (maxCount > 0) { - setTimeout(fetchToken, 3000) - } else if (maxCount === 0) { - loginFailed(er) - signing = false - } - } - }, 3000); + console.log("submit"); + if (!token.value) { + login(token, instanceUrlResult); + signing = false; + } } -function loginFailed(err: unknown) { +function loginFailed(err) { switch (err.id) { case "6cc579cc-885d-43d8-95c2-b8c7fc963280": { os.alert({ diff --git a/src/miauth.ts b/src/miauth.ts index a888446..176c067 100644 --- a/src/miauth.ts +++ b/src/miauth.ts @@ -1,5 +1,3 @@ -import { CapacitorHttp } from "@capacitor/core"; - function join(...paths: string[]) { return paths.join("/"); } @@ -78,15 +76,16 @@ export class MiAuth { join("api", "miauth", this.session, "check"), this.origin ); - const data: Record = await CapacitorHttp.request( - { - method: "POST", - url: url.href - }).then(res => res.data) + + const data: Record = await fetch(url).then((res) => + res.json() + ); const token = String(data.token); + if (typeof data.token === "undefined") { throw new AuthenticationError(); } + return token; } diff --git a/yarn.lock b/yarn.lock index 4450e09..5b2ea90 100644 --- a/yarn.lock +++ b/yarn.lock @@ -68,11 +68,6 @@ tslib "^2.0.3" yargs "^17.3.1" -"@capacitor/browser@^4.1.1": - version "4.1.1" - resolved "https://registry.yarnpkg.com/@capacitor/browser/-/browser-4.1.1.tgz#ef7f705bda5c63c5497d4cb3c9108bd6aa9db908" - integrity sha512-RJKNeRiLm6X668X75YiPN/9t3z1pxVEPjIhLM/AtWAEsHUb8bjroQQ3WGdW/30Wa60a7ywiw3YLqWctfRaYyFw== - "@capacitor/camera@^4.1.4": version "4.1.4" resolved "https://registry.yarnpkg.com/@capacitor/camera/-/camera-4.1.4.tgz#5d019f88d1f3547b537270e35bcb96084eb48df6"