gancio-upstream/pages/Authorize.vue

84 lines
2.3 KiB
Vue
Raw Normal View History

<template lang='pug'>
2020-07-29 02:18:46 +02:00
v-card.mt-5
2020-01-21 17:33:33 +01:00
h4(slot='header')
nuxt-link(to='/')
img(src='/favicon.ico')
span {{settings.title}} - {{$t('common.authorize')}}
<u>{{$auth.user.email}}</u>
2020-01-21 01:24:10 +01:00
div
2020-01-21 17:33:33 +01:00
p(v-html="$t('oauth.authorization_request', { app: client.name, instance_name: settings.title })")
ul
2020-01-21 17:33:33 +01:00
li(v-for="s in scope.split(' ')") {{$t(`oauth.scopes.${scope}`)}}
span(v-html="$t('oauth.redirected_to', {url: $route.query.redirect_uri})")
br
br
a(:href='authorizeURL')
2020-07-29 02:18:46 +02:00
v-btn.mr-1(plain color='success') {{$t('common.authorize')}}
2020-01-21 17:33:33 +01:00
a(href='/')
2020-07-29 02:18:46 +02:00
v-btn.mt-1(plain color='danger') {{$t('common.cancel')}}
</template>
<script>
2020-01-21 01:24:10 +01:00
import { mapState } from 'vuex'
export default {
layout: 'modal',
name: 'Authorize',
middleware: ['auth'],
2020-01-21 01:24:10 +01:00
async asyncData ({ $axios, query, error, req }) {
const { client_id, redirect_uri, scope, response_type } = query
let err = ''
if (!client_id) {
err = 'client_id is missing'
}
if (!redirect_uri) {
err = 'redirect_uri is missing'
}
2020-01-21 17:33:33 +01:00
if (!scope || scope !== 'event:write') {
2020-01-21 01:24:10 +01:00
err = 'scope is missing or wrong'
}
if (!response_type || response_type !== 'code') {
err = 'response_type is missing or wrong'
}
// retrieve client validity
try {
2020-01-21 01:24:10 +01:00
const client = await $axios.$get(`/client/${client_id}`)
if (!client) {
err = 'client not found'
}
if (err) {
return error({ statusCode: 404, message: err })
}
return { client, redirect_uri, scope, response_type }
2020-01-15 23:42:44 +01:00
} catch (e) {
2020-01-21 01:24:10 +01:00
error({ statusCode: 400, message: 'Something goes wrong with OAuth authorization' })
}
},
2020-01-15 23:42:44 +01:00
data () {
return {
client: { name: 'Test' }
}
},
computed: {
...mapState(['settings']),
authorizeURL () {
const { scope, response_type, client_id, redirect_uri, state } = this.$route.query
const query = `client_id=${client_id}&response_type=${response_type}&scope=${scope}&redirect_uri=${redirect_uri}&state=${state}`
return `oauth/authorize?${query}`
}
},
2020-01-15 23:42:44 +01:00
head () {
return { title: `${this.settings.title} - Authorize` }
}
}
</script>
2020-01-21 17:33:33 +01:00
<style lang='less'>
h4 img {
max-height: 40px;
border-radius: 20px;
background-color: #333;
border: 1px solid #333;
}
</style>