API
-
- {{ $t('token') }}
-
+ {{ $t('generateAccessToken') }}
{{ $t('regenerate') }}
@@ -26,6 +24,22 @@ export default Vue.extend({
};
},
methods: {
+ async generateToken() {
+ this.$root.new(await import('../../components/token-generate-window.vue').then(m => m.default), {
+ }).$on('ok', async ({ name, permissions }) => {
+ const { token } = await this.$root.api('miauth/gen-token', {
+ session: null,
+ name: name,
+ permission: permissions,
+ });
+
+ this.$root.dialog({
+ type: 'success',
+ title: this.$t('token'),
+ text: token
+ });
+ });
+ },
regenerateToken() {
this.$root.dialog({
title: this.$t('password'),
diff --git a/src/server/api/kinds.ts b/src/misc/api-permissions.ts
similarity index 100%
rename from src/server/api/kinds.ts
rename to src/misc/api-permissions.ts
diff --git a/src/server/api/endpoints/miauth/gen-token.ts b/src/server/api/endpoints/miauth/gen-token.ts
index d8c74ec8d..6476e79d7 100644
--- a/src/server/api/endpoints/miauth/gen-token.ts
+++ b/src/server/api/endpoints/miauth/gen-token.ts
@@ -13,7 +13,7 @@ export const meta = {
params: {
session: {
- validator: $.str
+ validator: $.nullable.str
},
name: {
@@ -52,4 +52,8 @@ export default define(meta, async (ps, user) => {
iconUrl: ps.iconUrl,
permission: ps.permission,
});
+
+ return {
+ token: accessToken
+ };
});
diff --git a/src/server/api/index.ts b/src/server/api/index.ts
index 93c6cfdac..aec4a9737 100644
--- a/src/server/api/index.ts
+++ b/src/server/api/index.ts
@@ -78,7 +78,7 @@ router.post('/miauth/:session/check', async ctx => {
session: ctx.params.session
});
- if (token && !token.fetched) {
+ if (token && token.session != null && !token.fetched) {
AccessTokens.update(token.id, {
fetched: true
});
diff --git a/src/server/api/openapi/description.ts b/src/server/api/openapi/description.ts
index 15831b3c9..e0527dd1a 100644
--- a/src/server/api/openapi/description.ts
+++ b/src/server/api/openapi/description.ts
@@ -1,6 +1,6 @@
import endpoints from '../endpoints';
import * as locale from '../../../../locales/';
-import { kinds as kindsList } from '../kinds';
+import { kinds as kindsList } from '../../../misc/api-permissions';
export interface IKindInfo {
endpoints: string[];