diff --git a/src/components/settings_modal/tabs/security_tab/security_tab.js b/src/components/settings_modal/tabs/security_tab/security_tab.js index fc732936..8306af96 100644 --- a/src/components/settings_modal/tabs/security_tab/security_tab.js +++ b/src/components/settings_modal/tabs/security_tab/security_tab.js @@ -2,6 +2,7 @@ import ProgressButton from 'src/components/progress_button/progress_button.vue' import Checkbox from 'src/components/checkbox/checkbox.vue' import Mfa from './mfa.vue' import localeService from 'src/services/locale/locale.service.js' +import oauth from 'src/services/new_api/oauth.js' const SecurityTab = { data () { @@ -24,7 +25,15 @@ const SecurityTab = { listAliasesError: false, addAliasTarget: '', addedAlias: false, - addAliasError: false + addAliasError: false, + scopes: { + read: true, + write: false, + follow: false + }, + clientId: '', + clientSecret: '', + accessToken: '', } }, created () { @@ -149,6 +158,49 @@ const SecurityTab = { this.$store.dispatch('logout') this.$router.replace('/') }, + generateAuthentication () { + const url = `${this.$store.state.instance.server}/api/v1/apps` + const form = new window.FormData() + + form.append('client_name', this.generateTokenAppName) + form.append('redirect_uris', 'urn:ietf:wg:oauth:2.0:oob') + form.append('scopes', Object.keys(this.scopes) + .filter((key) => this.scopes[key] === true) + .join(' ') + ) + + return window.fetch(url, { + method: 'POST', + body: form + }) + .then((data) => data.json()) + .then((app) => ({ clientId: app.client_id, clientSecret: app.client_secret })) + .then((app) => this.$store.commit('setClientData', app) || app) + .then((app) => { + const authUrl = `${this.$store.state.instance.server}/oauth/authorize?client_id=${app.clientId}&response_type=code&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=${encodeURIComponent( + form.get('scopes') + )}`; + window.open(authUrl, '_blank', 'width=500,height=800'); + + this.clientId = app.clientId + this.clientSecret = app.clientSecret + }); + }, + generateToken () { + if (!this.clientId || !this.clientSecret) { + return + } + + oauth.getToken({ + clientId: this.clientId, + clientSecret: this.clientSecret, + instance: this.$store.state.instance.server, + code: this.inputToken + }).then((tokenData) => { + this.$store.dispatch('fetchTokens') + this.accessToken = tokenData.access_token + }) + }, revokeToken (id) { if (window.confirm(`${this.$i18n.t('settings.revoke_token')}?`)) { this.$store.dispatch('revokeToken', id) diff --git a/src/components/settings_modal/tabs/security_tab/security_tab.vue b/src/components/settings_modal/tabs/security_tab/security_tab.vue index c74a0c67..896880c1 100644 --- a/src/components/settings_modal/tabs/security_tab/security_tab.vue +++ b/src/components/settings_modal/tabs/security_tab/security_tab.vue @@ -101,6 +101,55 @@ +
{{ $t('settings.client_name') }}
+ +{{ $t('settings.scopes') }}
+{{ $t('settings.input_token') }}
+ +{{ $t('settings.access_token') }}
+ +