Skip to content

Commit

Permalink
Revert "implement MiAuth (#55)"
Browse files Browse the repository at this point in the history
This reverts commit 0bf980f.
  • Loading branch information
fruitriin committed Feb 21, 2023
1 parent 7571d6c commit 711b911
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 54 deletions.
3 changes: 0 additions & 3 deletions capacitor.config.dev.json
Expand Up @@ -6,9 +6,6 @@
"plugins": {
"PushNotifications": {
"presentationOptions": ["badge", "sound", "alert"]
},
"CapacitorHttp": {
"enabled": true
}
},
"server": {
Expand Down
3 changes: 0 additions & 3 deletions capacitor.config.prod.json
Expand Up @@ -6,9 +6,6 @@
"plugins": {
"PushNotifications": {
"presentationOptions": ["badge", "sound", "alert"]
},
"CapacitorHttp": {
"enabled": true
}
}
}
Expand Down
1 change: 0 additions & 1 deletion ios/App/Podfile
Expand Up @@ -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'
Expand Down
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -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",
Expand Down
42 changes: 8 additions & 34 deletions src/components/MkSignin.vue
Expand Up @@ -19,7 +19,6 @@
required
/>
</template>
<!--
{{ i18n.ts.ririca.accessToken }}
<MkInput
v-model="token"
Expand All @@ -28,7 +27,6 @@
required
data-cy-signin-username
></MkInput>
-->
<MkButton
class="_formBlock"
type="submit"
Expand All @@ -55,8 +53,6 @@ import * as os from "@/os";
import { login } from "@/account";
import { instance } from "@/instance";
import { i18n } from "@/i18n";
import { quickAuth, Permissions } from "@/miauth"
import { Browser } from "@capacitor/browser"
let signing = $ref(false);
let user = $ref(null);
Expand Down Expand Up @@ -130,7 +126,7 @@ function queryKey() {
.get({
publicKey: {
challenge: byteify(challengeData.challenge, "base64"),
allowCredentials: challengeData.securityKeys.map((key: { id: string; }) => ({
allowCredentials: challengeData.securityKeys.map((key) => ({
id: byteify(key.id, "hex"),
type: "public-key",
transports: ["usb", "nfc", "ble", "internal"],
Expand Down Expand Up @@ -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({
Expand Down
13 changes: 6 additions & 7 deletions src/miauth.ts
@@ -1,5 +1,3 @@
import { CapacitorHttp } from "@capacitor/core";

function join(...paths: string[]) {
return paths.join("/");
}
Expand Down Expand Up @@ -78,15 +76,16 @@ export class MiAuth {
join("api", "miauth", this.session, "check"),
this.origin
);
const data: Record<string, unknown> = await CapacitorHttp.request(
{
method: "POST",
url: url.href
}).then(res => res.data)

const data: Record<string, unknown> = await fetch(url).then((res) =>
res.json()
);
const token = String(data.token);

if (typeof data.token === "undefined") {
throw new AuthenticationError();
}

return token;
}

Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Expand Up @@ -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"
Expand Down

1 comment on commit 711b911

@vercel
Copy link

@vercel vercel bot commented on 711b911 Feb 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

miss-ririca – ./

miss-ririca.vercel.app
miss-ririca-git-main-fruitriin.vercel.app
miss-ririca-fruitriin.vercel.app

Please sign in to comment.