Laravel-based OAuth/IAM service with Passport, Vue 3 frontend, and Docker Compose setup for local and production deployment. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
146 lines
4.5 KiB
Vue
146 lines
4.5 KiB
Vue
<script setup lang="ts">
|
|
import { onMounted, reactive, ref } from 'vue';
|
|
import axios from 'axios';
|
|
import { useI18n } from 'vue-i18n';
|
|
import type { PersonalAccessToken, Scope } from '../types/models';
|
|
|
|
const { t } = useI18n();
|
|
|
|
const tokens = ref<PersonalAccessToken[]>([]);
|
|
const scopes = ref<Scope[]>([]);
|
|
const loading = ref(true);
|
|
const creating = ref(false);
|
|
const newToken = ref<string | null>(null);
|
|
|
|
const form = reactive<{ name: string; scopes: string[] }>({ name: '', scopes: [] });
|
|
const errors = ref<Record<string, string[]>>({});
|
|
|
|
async function load(): Promise<void> {
|
|
loading.value = true;
|
|
const [tokensRes, scopesRes] = await Promise.all([
|
|
axios.get<PersonalAccessToken[]>('/web-api/personal-access-tokens'),
|
|
axios.get<Scope[]>('/web-api/scopes'),
|
|
]);
|
|
tokens.value = tokensRes.data;
|
|
scopes.value = scopesRes.data;
|
|
loading.value = false;
|
|
}
|
|
|
|
async function create(): Promise<void> {
|
|
creating.value = true;
|
|
errors.value = {};
|
|
newToken.value = null;
|
|
|
|
try {
|
|
const { data } = await axios.post<{ access_token: string }>('/web-api/personal-access-tokens', form);
|
|
newToken.value = data.access_token;
|
|
form.name = '';
|
|
form.scopes = [];
|
|
await load();
|
|
} catch (e: any) {
|
|
errors.value = e.response?.data?.errors ?? {};
|
|
} finally {
|
|
creating.value = false;
|
|
}
|
|
}
|
|
|
|
async function revoke(token: PersonalAccessToken): Promise<void> {
|
|
if (!confirm(t('tokens.revokeConfirm', { name: token.name }))) return;
|
|
|
|
await axios.delete(`/web-api/personal-access-tokens/${token.id}`);
|
|
await load();
|
|
}
|
|
|
|
onMounted(load);
|
|
</script>
|
|
|
|
<template>
|
|
<div>
|
|
<h1 class="page-title">{{ t('tokens.title') }}</h1>
|
|
<p class="page-subtitle">{{ t('tokens.subtitle') }}</p>
|
|
|
|
<div v-if="newToken" class="banner banner--warning">
|
|
<p class="banner__title">{{ t('tokens.tokenWarning') }}</p>
|
|
<p class="banner__line tokens__token"><code class="banner__code">{{ newToken }}</code></p>
|
|
<button class="banner__close" @click="newToken = null">{{ t('common.close') }}</button>
|
|
</div>
|
|
|
|
<form class="card tokens__form" @submit.prevent="create">
|
|
<h2 class="card__title">{{ t('tokens.newToken') }}</h2>
|
|
|
|
<div class="field">
|
|
<label class="field__label">{{ t('tokens.name') }}</label>
|
|
<input v-model="form.name" required :placeholder="t('tokens.namePlaceholder')" class="field__input" />
|
|
<p v-if="errors.name" class="field__error">{{ errors.name[0] }}</p>
|
|
</div>
|
|
|
|
<div class="field">
|
|
<label class="field__label">{{ t('tokens.scopes') }}</label>
|
|
<div class="tokens__scopes">
|
|
<label v-for="scope in scopes" :key="scope.id" class="field__checkbox-row">
|
|
<input type="checkbox" :value="scope.id" v-model="form.scopes" class="field__checkbox" />
|
|
{{ scope.id }} — {{ scope.description }}
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<button type="submit" :disabled="creating" class="btn btn--primary">
|
|
{{ creating ? t('common.creating') : t('tokens.create') }}
|
|
</button>
|
|
</div>
|
|
</form>
|
|
|
|
<div class="tokens__list">
|
|
<p v-if="loading" class="page-subtitle">{{ t('common.loading') }}</p>
|
|
<p v-else-if="!tokens.length" class="page-subtitle">{{ t('tokens.empty') }}</p>
|
|
|
|
<div v-for="token in tokens" :key="token.id" class="card tokens__item">
|
|
<div>
|
|
<p class="card__title">{{ token.name }}</p>
|
|
<p class="tokens__item-meta">{{ t('tokens.scopesLabel') }}: {{ token.scopes?.join(', ') || t('common.none') }}</p>
|
|
</div>
|
|
<button @click="revoke(token)" class="link link--danger">{{ t('tokens.revoke') }}</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.tokens__form {
|
|
margin-top: 1.5rem;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 1rem;
|
|
}
|
|
|
|
.tokens__scopes {
|
|
margin-top: 0.25rem;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.25rem;
|
|
}
|
|
|
|
.tokens__token {
|
|
word-break: break-all;
|
|
}
|
|
|
|
.tokens__list {
|
|
margin-top: 1.5rem;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.75rem;
|
|
}
|
|
|
|
.tokens__item {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
}
|
|
|
|
.tokens__item-meta {
|
|
font-size: 0.75rem;
|
|
color: var(--color-text-muted);
|
|
}
|
|
</style>
|