2020-03-28 04:24:37 +02:00
|
|
|
<template>
|
2023-02-09 19:18:27 +02:00
|
|
|
<MkStickyContainer>
|
|
|
|
<template #header><MkPageHeader :actions="headerActions" :tabs="headerTabs" /></template>
|
|
|
|
<MkSpacer :content-max="800">
|
|
|
|
<div v-if="$i">
|
|
|
|
<div v-if="state == 'waiting'">
|
2022-07-21 18:17:52 +03:00
|
|
|
<MkLoading/>
|
|
|
|
</div>
|
2023-02-09 19:18:27 +02:00
|
|
|
<div v-if="state == 'denied'">
|
2022-07-21 18:17:52 +03:00
|
|
|
<p>{{ i18n.ts._auth.denied }}</p>
|
|
|
|
</div>
|
2023-02-09 19:18:27 +02:00
|
|
|
<div v-else-if="state == 'accepted'" class="accepted">
|
2022-07-21 18:17:52 +03:00
|
|
|
<p v-if="callback">{{ i18n.ts._auth.callback }}<MkEllipsis/></p>
|
|
|
|
<p v-else>{{ i18n.ts._auth.pleaseGoBack }}</p>
|
|
|
|
</div>
|
2023-02-09 19:18:27 +02:00
|
|
|
<div v-else>
|
|
|
|
<div v-if="_permissions.length > 0">
|
2023-02-09 19:29:22 +02:00
|
|
|
<p v-if="name">{{ $t('_auth.permission', { name }) }}</p>
|
|
|
|
<p v-else>{{ i18n.ts._auth.permissionAsk }}</p>
|
2023-02-09 19:18:27 +02:00
|
|
|
<ul>
|
|
|
|
<li v-for="p in _permissions" :key="p">{{ $t(`_permissions.${p}`) }}</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2023-02-09 19:29:22 +02:00
|
|
|
<div v-if="name">{{ $t('_auth.shareAccess', { name }) }}</div>
|
|
|
|
<div v-else>{{ i18n.ts._auth.shareAccessAsk }}</div>
|
2023-02-09 19:18:27 +02:00
|
|
|
<div :class="$style.buttons">
|
|
|
|
<MkButton inline @click="deny">{{ i18n.ts.cancel }}</MkButton>
|
|
|
|
<MkButton inline primary @click="accept">{{ i18n.ts.accept }}</MkButton>
|
|
|
|
</div>
|
2022-07-21 18:17:52 +03:00
|
|
|
</div>
|
2020-03-28 04:24:37 +02:00
|
|
|
</div>
|
2023-02-09 19:18:27 +02:00
|
|
|
<div v-else>
|
|
|
|
<p :class="$style.loginMessage">{{ i18n.ts._auth.pleaseLogin }}</p>
|
|
|
|
<MkSignin @login="onLogin"/>
|
|
|
|
</div>
|
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
2020-03-28 04:24:37 +02:00
|
|
|
</template>
|
|
|
|
|
2022-07-21 18:17:52 +03:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { } from 'vue';
|
2022-08-30 18:24:33 +03:00
|
|
|
import MkSignin from '@/components/MkSignin.vue';
|
2022-09-06 12:21:49 +03:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2021-11-11 19:02:25 +02:00
|
|
|
import * as os from '@/os';
|
2022-07-21 18:17:52 +03:00
|
|
|
import { $i, login } from '@/account';
|
|
|
|
import { i18n } from '@/i18n';
|
2023-02-09 19:18:27 +02:00
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
2022-07-21 18:17:52 +03:00
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
session: string;
|
|
|
|
callback?: string;
|
|
|
|
name: string;
|
|
|
|
icon: string;
|
|
|
|
permission: string; // コンマ区切り
|
|
|
|
}>();
|
|
|
|
|
2023-02-09 19:18:27 +02:00
|
|
|
const _permissions = props.permission ? props.permission.split(',') : [];
|
2022-07-21 18:17:52 +03:00
|
|
|
|
|
|
|
let state = $ref<string | null>(null);
|
|
|
|
|
|
|
|
async function accept(): Promise<void> {
|
|
|
|
state = 'waiting';
|
|
|
|
await os.api('miauth/gen-token', {
|
|
|
|
session: props.session,
|
|
|
|
name: props.name,
|
|
|
|
iconUrl: props.icon,
|
|
|
|
permission: _permissions,
|
|
|
|
});
|
|
|
|
|
|
|
|
state = 'accepted';
|
|
|
|
if (props.callback) {
|
2023-01-05 10:18:32 +02:00
|
|
|
const cbUrl = new URL(props.callback);
|
2023-02-09 11:01:12 +02:00
|
|
|
if (['javascript:', 'file:', 'data:', 'mailto:', 'tel:'].includes(cbUrl.protocol)) throw new Error('invalid url');
|
2023-01-05 10:18:32 +02:00
|
|
|
cbUrl.searchParams.set('session', props.session);
|
|
|
|
location.href = cbUrl.href;
|
2022-07-21 18:17:52 +03:00
|
|
|
}
|
|
|
|
}
|
2020-03-28 04:24:37 +02:00
|
|
|
|
2022-07-21 18:17:52 +03:00
|
|
|
function deny(): void {
|
|
|
|
state = 'denied';
|
|
|
|
}
|
2020-03-28 04:24:37 +02:00
|
|
|
|
2022-07-21 18:17:52 +03:00
|
|
|
function onLogin(res): void {
|
|
|
|
login(res.i);
|
|
|
|
}
|
2023-02-09 19:18:27 +02:00
|
|
|
|
|
|
|
const headerActions = $computed(() => []);
|
|
|
|
|
|
|
|
const headerTabs = $computed(() => []);
|
|
|
|
|
|
|
|
definePageMetadata({
|
|
|
|
title: 'MiAuth',
|
|
|
|
icon: 'ti ti-apps',
|
|
|
|
});
|
2020-03-28 04:24:37 +02:00
|
|
|
</script>
|
|
|
|
|
2023-02-09 19:18:27 +02:00
|
|
|
<style lang="scss" module>
|
|
|
|
.buttons {
|
|
|
|
margin-top: 16px;
|
|
|
|
display: flex;
|
|
|
|
gap: 8px;
|
|
|
|
flex-wrap: wrap;
|
|
|
|
}
|
2020-03-28 04:24:37 +02:00
|
|
|
|
2023-02-09 19:18:27 +02:00
|
|
|
.loginMessage {
|
|
|
|
text-align: center;
|
|
|
|
margin: 8px 0 24px;
|
|
|
|
}
|
2020-03-28 04:24:37 +02:00
|
|
|
</style>
|