2020-01-29 11:37:25 -08:00
|
|
|
<template>
|
2021-11-19 02:36:12 -08:00
|
|
|
<div v-if="$i && fetching" class="">
|
2020-10-17 04:12:00 -07:00
|
|
|
<MkLoading/>
|
2020-01-29 11:37:25 -08:00
|
|
|
</div>
|
2020-12-18 17:55:52 -08:00
|
|
|
<div v-else-if="$i">
|
2020-10-17 04:12:00 -07:00
|
|
|
<XForm
|
2020-01-29 11:37:25 -08:00
|
|
|
v-if="state == 'waiting'"
|
2021-11-19 02:36:12 -08:00
|
|
|
ref="form"
|
|
|
|
class="form"
|
2020-01-29 11:37:25 -08:00
|
|
|
:session="session"
|
|
|
|
@denied="state = 'denied'"
|
|
|
|
@accepted="accepted"
|
|
|
|
/>
|
2021-11-19 02:36:12 -08:00
|
|
|
<div v-if="state == 'denied'" class="denied">
|
2020-12-25 17:47:36 -08:00
|
|
|
<h1>{{ $ts._auth.denied }}</h1>
|
2020-01-29 11:37:25 -08:00
|
|
|
</div>
|
2021-11-19 02:36:12 -08:00
|
|
|
<div v-if="state == 'accepted'" class="accepted">
|
2022-06-20 01:38:49 -07:00
|
|
|
<h1>{{ session.app.isAuthorized ? $t('already-authorized') : $ts.allowed }}</h1>
|
2020-12-25 17:47:36 -08:00
|
|
|
<p v-if="session.app.callbackUrl">{{ $ts._auth.callback }}<MkEllipsis/></p>
|
|
|
|
<p v-if="!session.app.callbackUrl">{{ $ts._auth.pleaseGoBack }}</p>
|
2020-01-29 11:37:25 -08:00
|
|
|
</div>
|
2021-11-19 02:36:12 -08:00
|
|
|
<div v-if="state == 'fetch-session-error'" class="error">
|
2020-12-25 17:47:36 -08:00
|
|
|
<p>{{ $ts.somethingHappened }}</p>
|
2020-01-29 11:37:25 -08:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-11-19 02:36:12 -08:00
|
|
|
<div v-else class="signin">
|
2020-10-17 04:12:00 -07:00
|
|
|
<MkSignin @login="onLogin"/>
|
2020-01-29 11:37:25 -08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 04:12:00 -07:00
|
|
|
import { defineComponent } from 'vue';
|
2020-01-29 11:37:25 -08:00
|
|
|
import XForm from './auth.form.vue';
|
2022-08-30 08:24:33 -07:00
|
|
|
import MkSignin from '@/components/MkSignin.vue';
|
2021-11-11 09:02:25 -08:00
|
|
|
import * as os from '@/os';
|
|
|
|
import { login } from '@/account';
|
2020-01-29 11:37:25 -08:00
|
|
|
|
2020-10-17 04:12:00 -07:00
|
|
|
export default defineComponent({
|
2020-01-29 11:37:25 -08:00
|
|
|
components: {
|
2020-02-20 06:07:20 -08:00
|
|
|
XForm,
|
|
|
|
MkSignin,
|
2020-01-29 11:37:25 -08:00
|
|
|
},
|
2022-06-20 01:38:49 -07:00
|
|
|
props: ['token'],
|
2020-01-29 11:37:25 -08:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
state: null,
|
|
|
|
session: null,
|
2022-06-20 01:38:49 -07:00
|
|
|
fetching: true,
|
2020-01-29 11:37:25 -08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
2020-12-18 17:55:52 -08:00
|
|
|
if (!this.$i) return;
|
2020-01-29 11:37:25 -08:00
|
|
|
|
|
|
|
// Fetch session
|
2020-10-17 04:12:00 -07:00
|
|
|
os.api('auth/session/show', {
|
2022-06-20 01:38:49 -07:00
|
|
|
token: this.token,
|
2020-01-29 11:37:25 -08:00
|
|
|
}).then(session => {
|
|
|
|
this.session = session;
|
|
|
|
this.fetching = false;
|
|
|
|
|
|
|
|
// 既に連携していた場合
|
|
|
|
if (this.session.app.isAuthorized) {
|
2020-10-17 04:12:00 -07:00
|
|
|
os.api('auth/accept', {
|
2022-06-20 01:38:49 -07:00
|
|
|
token: this.session.token,
|
2020-01-29 11:37:25 -08:00
|
|
|
}).then(() => {
|
|
|
|
this.accepted();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.state = 'waiting';
|
|
|
|
}
|
|
|
|
}).catch(error => {
|
|
|
|
this.state = 'fetch-session-error';
|
|
|
|
this.fetching = false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
accepted() {
|
|
|
|
this.state = 'accepted';
|
|
|
|
if (this.session.app.callbackUrl) {
|
2023-02-09 01:01:12 -08:00
|
|
|
const url = new URL(this.session.app.callbackUrl);
|
|
|
|
if (['javascript:', 'file:', 'data:', 'mailto:', 'tel:'].includes(url.protocol)) throw new Error('invalid url');
|
2020-01-29 11:37:25 -08:00
|
|
|
location.href = `${this.session.app.callbackUrl}?token=${this.session.token}`;
|
|
|
|
}
|
2020-03-13 23:59:02 -07:00
|
|
|
}, onLogin(res) {
|
2020-12-18 17:55:52 -08:00
|
|
|
login(res.i);
|
2022-06-20 01:38:49 -07:00
|
|
|
},
|
|
|
|
},
|
2020-01-29 11:37:25 -08:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2022-12-27 01:29:39 -08:00
|
|
|
<style lang="scss" scoped>
|
2020-01-29 11:37:25 -08:00
|
|
|
|
|
|
|
</style>
|