-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
AuthProvider.vue
172 lines (157 loc) · 5.04 KB
/
AuthProvider.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<template>
<div
v-if="workingConfigs"
class="md:grid md:grid-cols-3 md:gap-4 border-divider border-b"
>
<div class="pb-8 px-8 md:col-span-1">
<h3 class="heading">{{ t('configs.auth_providers.title') }}</h3>
<p class="my-1 text-secondaryLight">
{{ t('configs.auth_providers.description') }}
</p>
</div>
<div class="space-y-8 p-8 md:col-span-2">
<section>
<h4 class="font-semibold text-secondaryDark">
{{ t('configs.auth_providers.title') }}
</h4>
<div
v-for="provider in workingConfigs.providers"
class="space-y-4 py-4"
>
<div class="flex items-center">
<HoppSmartToggle
:on="provider.enabled"
@change="provider.enabled = !provider.enabled"
>
{{ capitalize(provider.name) }}
</HoppSmartToggle>
</div>
<div v-if="provider.enabled" class="ml-12">
<div
v-for="field in providerConfigFields"
:key="field.key"
class="mt-5"
>
<div v-if="field.key !== 'tenant'">
<label>{{ field.name }}</label>
<span class="flex max-w-lg">
<HoppSmartInput
v-model="provider.fields[field.key]"
:type="
isMasked(provider.name, field.key) ? 'password' : 'text'
"
:disabled="isMasked(provider.name, field.key)"
:autofocus="false"
class="!my-2 !bg-primaryLight flex-1"
/>
<HoppButtonSecondary
:icon="
isMasked(provider.name, field.key) ? IconEye : IconEyeOff
"
class="bg-primaryLight h-9 mt-2"
@click="toggleMask(provider.name, field.key)"
/>
</span>
</div>
<!-- Microsoft Configs has an extra tenant field -->
<div v-else-if="provider.name === 'microsoft'">
<label>{{ field.name }}</label>
<span class="flex max-w-lg">
<HoppSmartInput
v-model="provider.fields[field.key as keyof typeof provider['fields']]"
:type="
isMasked(provider.name, field.key) ? 'password' : 'text'
"
:disabled="isMasked(provider.name, field.key)"
:autofocus="false"
class="!my-2 !bg-primaryLight flex-1"
/>
<HoppButtonSecondary
:icon="
isMasked(provider.name, field.key) ? IconEye : IconEyeOff
"
class="bg-primaryLight h-9 mt-2"
@click="toggleMask(provider.name, field.key)"
/>
</span>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
</template>
<script setup lang="ts">
import { useVModel } from '@vueuse/core';
import { reactive } from 'vue';
import { useI18n } from '~/composables/i18n';
import { Config, SsoAuthProviders } from '~/composables/useConfigHandler';
import IconEye from '~icons/lucide/eye';
import IconEyeOff from '~icons/lucide/eye-off';
const t = useI18n();
const props = defineProps<{
config: Config;
}>();
const emit = defineEmits<{
(e: 'update:config', v: Config): void;
}>();
const workingConfigs = useVModel(props, 'config', emit);
// Capitalize first letter of a string
const capitalize = (text: string) =>
text.charAt(0).toUpperCase() + text.slice(1);
// Union type for all possible field keys
type FieldKey =
| 'client_id'
| 'client_secret'
| 'callback_url'
| 'scope'
| 'tenant';
type Field = {
name: string;
key: FieldKey;
};
const providerConfigFields = reactive<Field[]>([
{
name: t('configs.auth_providers.client_id'),
key: 'client_id',
},
{
name: t('configs.auth_providers.client_secret'),
key: 'client_secret',
},
{
name: t('configs.auth_providers.callback_url'),
key: 'callback_url',
},
{ name: t('configs.auth_providers.scope'), key: 'scope' },
{ name: t('configs.auth_providers.tenant'), key: 'tenant' },
]);
const maskState = reactive({
google: {
client_id: true,
client_secret: true,
callback_url: true,
scope: true,
},
github: {
client_id: true,
client_secret: true,
callback_url: true,
scope: true,
},
microsoft: {
client_id: true,
client_secret: true,
callback_url: true,
scope: true,
tenant: true,
},
});
const toggleMask = (provider: SsoAuthProviders, fieldKey: FieldKey) => {
maskState[provider][fieldKey as keyof (typeof maskState)[typeof provider]] =
!maskState[provider][fieldKey as keyof (typeof maskState)[typeof provider]];
};
const isMasked = (provider: SsoAuthProviders, fieldKey: FieldKey) =>
maskState[provider][fieldKey as keyof (typeof maskState)[typeof provider]];
</script>