2020-03-27 19:24:37 -07:00
|
|
|
<template>
|
2022-07-21 08:17:52 -07:00
|
|
|
<MkSpacer :content-max="800">
|
|
|
|
<div v-if="$i">
|
2023-01-05 16:41:14 -08:00
|
|
|
<div v-if="state == 'waiting'" class="waiting">
|
|
|
|
<div class="">
|
2022-07-21 08:17:52 -07:00
|
|
|
<MkLoading/>
|
|
|
|
</div>
|
2020-03-27 19:24:37 -07:00
|
|
|
</div>
|
2023-01-05 16:41:14 -08:00
|
|
|
<div v-if="state == 'denied'" class="denied">
|
|
|
|
<div class="">
|
2022-07-21 08:17:52 -07:00
|
|
|
<p>{{ i18n.ts._auth.denied }}</p>
|
|
|
|
</div>
|
2020-03-27 19:24:37 -07:00
|
|
|
</div>
|
2023-01-05 16:41:14 -08:00
|
|
|
<div v-else-if="state == 'accepted'" class="accepted">
|
|
|
|
<div class="">
|
2022-07-21 08:17:52 -07:00
|
|
|
<p v-if="callback">{{ i18n.ts._auth.callback }}<MkEllipsis/></p>
|
|
|
|
<p v-else>{{ i18n.ts._auth.pleaseGoBack }}</p>
|
|
|
|
</div>
|
2020-03-27 19:24:37 -07:00
|
|
|
</div>
|
2023-01-05 16:41:14 -08:00
|
|
|
<div v-else class="">
|
|
|
|
<div v-if="name" class="">{{ $t('_auth.shareAccess', { name: name }) }}</div>
|
|
|
|
<div v-else class="">{{ i18n.ts._auth.shareAccessAsk }}</div>
|
|
|
|
<div class="">
|
2022-07-21 08:17:52 -07:00
|
|
|
<p>{{ i18n.ts._auth.permissionAsk }}</p>
|
|
|
|
<ul>
|
|
|
|
<li v-for="p in _permissions" :key="p">{{ $t(`_permissions.${p}`) }}</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2023-01-05 16:41:14 -08:00
|
|
|
<div class="">
|
2022-07-21 08:17:52 -07:00
|
|
|
<MkButton inline @click="deny">{{ i18n.ts.cancel }}</MkButton>
|
|
|
|
<MkButton inline primary @click="accept">{{ i18n.ts.accept }}</MkButton>
|
|
|
|
</div>
|
2020-03-27 19:24:37 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-07-21 08:17:52 -07:00
|
|
|
<div v-else class="signin">
|
|
|
|
<MkSignin @login="onLogin"/>
|
|
|
|
</div>
|
|
|
|
</MkSpacer>
|
2020-03-27 19:24:37 -07:00
|
|
|
</template>
|
|
|
|
|
2022-07-21 08:17:52 -07:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { } from 'vue';
|
2022-08-30 08:24:33 -07:00
|
|
|
import MkSignin from '@/components/MkSignin.vue';
|
2022-09-06 02:21:49 -07:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2021-11-11 09:02:25 -08:00
|
|
|
import * as os from '@/os';
|
2022-07-21 08:17:52 -07:00
|
|
|
import { $i, login } from '@/account';
|
|
|
|
import { i18n } from '@/i18n';
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
session: string;
|
|
|
|
callback?: string;
|
|
|
|
name: string;
|
|
|
|
icon: string;
|
|
|
|
permission: string; // コンマ区切り
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const _permissions = props.permission.split(',');
|
|
|
|
|
|
|
|
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 00:18:32 -08:00
|
|
|
const cbUrl = new URL(props.callback);
|
2023-02-09 01:01:12 -08:00
|
|
|
if (['javascript:', 'file:', 'data:', 'mailto:', 'tel:'].includes(cbUrl.protocol)) throw new Error('invalid url');
|
2023-01-05 00:18:32 -08:00
|
|
|
cbUrl.searchParams.set('session', props.session);
|
|
|
|
location.href = cbUrl.href;
|
2022-07-21 08:17:52 -07:00
|
|
|
}
|
|
|
|
}
|
2020-03-27 19:24:37 -07:00
|
|
|
|
2022-07-21 08:17:52 -07:00
|
|
|
function deny(): void {
|
|
|
|
state = 'denied';
|
|
|
|
}
|
2020-03-27 19:24:37 -07:00
|
|
|
|
2022-07-21 08:17:52 -07:00
|
|
|
function onLogin(res): void {
|
|
|
|
login(res.i);
|
|
|
|
}
|
2020-03-27 19:24:37 -07:00
|
|
|
</script>
|
|
|
|
|
2022-12-27 01:29:39 -08:00
|
|
|
<style lang="scss" scoped>
|
2020-03-27 19:24:37 -07:00
|
|
|
|
|
|
|
</style>
|