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