-
Notifications
You must be signed in to change notification settings - Fork 19
/
OAuthConnectButton.vue
49 lines (46 loc) · 1.07 KB
/
OAuthConnectButton.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<template>
<button
class="openproject-oauth"
@click="onOAuthClick">
<span class="icon icon-external" />
{{ t('integration_openproject', 'Connect to OpenProject') }}
</button>
</template>
<script>
import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
import { showError } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
export default {
name: 'OAuthConnectButton',
props: {
requestUrl: {
type: String,
required: true,
},
},
methods: {
onOAuthClick() {
const oauthState = Math.random().toString(36).substring(3)
const requestUrl = this.requestUrl
+ '&state=' + encodeURIComponent(oauthState)
const req = {
values: {
oauth_state: oauthState,
},
}
const url = generateUrl('/apps/integration_openproject/config')
axios.put(url, req)
.then(() => {
window.location.replace(requestUrl)
})
.catch((error) => {
showError(
t('integration_openproject', 'Failed to save OpenProject OAuth state')
+ ': ' + error.message
)
})
},
},
}
</script>