2020-03-28 11:24:37 +09:00
|
|
|
<template>
|
2023-04-08 09:01:42 +09:00
|
|
|
<MkSpacer :content-max="800">
|
|
|
|
<div v-if="$i">
|
|
|
|
<div v-if="state == 'waiting'" class="waiting _section">
|
|
|
|
<div class="_content">
|
|
|
|
<MkLoading />
|
|
|
|
</div>
|
2022-07-22 00:17:52 +09:00
|
|
|
</div>
|
2023-04-08 09:01:42 +09:00
|
|
|
<div v-if="state == 'denied'" class="denied _section">
|
|
|
|
<div class="_content">
|
|
|
|
<p>{{ i18n.ts._auth.denied }}</p>
|
|
|
|
</div>
|
2022-07-22 00:17:52 +09:00
|
|
|
</div>
|
2023-04-08 09:01:42 +09:00
|
|
|
<div v-else-if="state == 'accepted'" class="accepted _section">
|
|
|
|
<div class="_content">
|
|
|
|
<p v-if="callback">
|
|
|
|
{{ i18n.ts._auth.callback }}<MkEllipsis />
|
|
|
|
</p>
|
|
|
|
<p v-else>{{ i18n.ts._auth.pleaseGoBack }}</p>
|
|
|
|
</div>
|
2022-07-22 00:17:52 +09:00
|
|
|
</div>
|
2023-04-08 09:01:42 +09:00
|
|
|
<div v-else class="_section">
|
|
|
|
<div v-if="name" class="_title">
|
|
|
|
{{ i18n.t("_auth.shareAccess", { name: name }) }}
|
|
|
|
</div>
|
|
|
|
<div v-else class="_title">
|
|
|
|
{{ i18n.ts._auth.shareAccessAsk }}
|
|
|
|
</div>
|
|
|
|
<div class="_content">
|
|
|
|
<p>{{ i18n.ts._auth.permissionAsk }}</p>
|
|
|
|
<ul>
|
|
|
|
<li v-for="p in _permissions" :key="p">
|
|
|
|
{{ i18n.t(`_permissions.${p}`) }}
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div class="_footer">
|
|
|
|
<MkButton inline @click="deny">{{
|
|
|
|
i18n.ts.cancel
|
|
|
|
}}</MkButton>
|
|
|
|
<MkButton inline primary @click="accept">{{
|
|
|
|
i18n.ts.accept
|
|
|
|
}}</MkButton>
|
|
|
|
</div>
|
2022-07-22 00:17:52 +09:00
|
|
|
</div>
|
2020-03-28 11:24:37 +09:00
|
|
|
</div>
|
2023-04-08 09:01:42 +09:00
|
|
|
<div v-else class="signin">
|
|
|
|
<MkSignin @login="onLogin" />
|
|
|
|
</div>
|
|
|
|
</MkSpacer>
|
2020-03-28 11:24:37 +09:00
|
|
|
</template>
|
|
|
|
|
2022-07-22 00:17:52 +09:00
|
|
|
<script lang="ts" setup>
|
2023-04-08 09:01:42 +09:00
|
|
|
import {} from "vue";
|
|
|
|
import MkSignin from "@/components/MkSignin.vue";
|
|
|
|
import MkButton from "@/components/MkButton.vue";
|
|
|
|
import * as os from "@/os";
|
|
|
|
import { $i, login } from "@/account";
|
|
|
|
import { appendQuery, query } from "@/scripts/url";
|
|
|
|
import { i18n } from "@/i18n";
|
2022-07-22 00:17:52 +09:00
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
session: string;
|
|
|
|
callback?: string;
|
|
|
|
name: string;
|
|
|
|
icon: string;
|
|
|
|
permission: string; // コンマ区切り
|
|
|
|
}>();
|
|
|
|
|
2023-04-08 09:01:42 +09:00
|
|
|
const _permissions = props.permission.split(",");
|
2022-07-22 00:17:52 +09:00
|
|
|
|
|
|
|
let state = $ref<string | null>(null);
|
|
|
|
|
|
|
|
async function accept(): Promise<void> {
|
2023-04-08 09:01:42 +09:00
|
|
|
state = "waiting";
|
|
|
|
await os.api("miauth/gen-token", {
|
2022-07-22 00:17:52 +09:00
|
|
|
session: props.session,
|
|
|
|
name: props.name,
|
|
|
|
iconUrl: props.icon,
|
|
|
|
permission: _permissions,
|
|
|
|
});
|
|
|
|
|
2023-04-08 09:01:42 +09:00
|
|
|
state = "accepted";
|
2022-07-22 00:17:52 +09:00
|
|
|
if (props.callback) {
|
2023-02-04 09:10:01 +09:00
|
|
|
const cbUrl = new URL(props.callback);
|
2023-04-08 09:01:42 +09:00
|
|
|
if (
|
|
|
|
["javascript:", "file:", "data:", "mailto:", "tel:"].includes(
|
|
|
|
cbUrl.protocol
|
|
|
|
)
|
|
|
|
)
|
|
|
|
throw new Error("invalid url");
|
|
|
|
location.href = appendQuery(
|
|
|
|
props.callback,
|
|
|
|
query({
|
|
|
|
session: props.session,
|
|
|
|
})
|
|
|
|
);
|
2022-07-22 00:17:52 +09:00
|
|
|
}
|
|
|
|
}
|
2020-03-28 11:24:37 +09:00
|
|
|
|
2023-02-11 04:50:42 +09:00
|
|
|
function deny(): void {
|
2023-04-08 09:01:42 +09:00
|
|
|
state = "denied";
|
2022-07-22 00:17:52 +09:00
|
|
|
}
|
2020-03-28 11:24:37 +09:00
|
|
|
|
2022-07-22 00:17:52 +09:00
|
|
|
function onLogin(res): void {
|
|
|
|
login(res.i);
|
|
|
|
}
|
2020-03-28 11:24:37 +09:00
|
|
|
</script>
|
|
|
|
|
2023-04-08 09:01:42 +09:00
|
|
|
<style lang="scss" scoped></style>
|