Add server settings for changing openid button text and auto launching openid

This commit is contained in:
advplyr 2023-11-02 13:55:01 -05:00
parent ab14b561f5
commit 828b96b2d9
4 changed files with 46 additions and 9 deletions

View File

@ -26,6 +26,14 @@
<ui-text-input-with-label ref="openidClientId" v-model="newAuthSettings.authOpenIDClientID" :disabled="savingSettings" :label="'Client ID'" class="mb-2" /> <ui-text-input-with-label ref="openidClientId" v-model="newAuthSettings.authOpenIDClientID" :disabled="savingSettings" :label="'Client ID'" class="mb-2" />
<ui-text-input-with-label ref="openidClientSecret" v-model="newAuthSettings.authOpenIDClientSecret" :disabled="savingSettings" :label="'Client Secret'" class="mb-2" /> <ui-text-input-with-label ref="openidClientSecret" v-model="newAuthSettings.authOpenIDClientSecret" :disabled="savingSettings" :label="'Client Secret'" class="mb-2" />
<ui-text-input-with-label ref="buttonTextInput" v-model="newAuthSettings.authOpenIDButtonText" :disabled="savingSettings" :label="'Button Text'" class="mb-2" />
<div class="flex items-center py-2 px-1">
<ui-toggle-switch labeledBy="auto-redirect-toggle" v-model="newAuthSettings.authOpenIDAutoLaunch" :disabled="savingSettings" />
<p id="auto-redirect-toggle" class="pl-4">Auto Launch</p>
<p class="pl-4 text-sm text-gray-300">Redirect to the auth provider automatically when navigating to the /login page</p>
</div>
</div> </div>
</transition> </transition>
</div> </div>

View File

@ -48,7 +48,7 @@
<ui-btn color="primary" class="leading-none">Login with Google</ui-btn> <ui-btn color="primary" class="leading-none">Login with Google</ui-btn>
</a> </a>
<a v-show="login_openid" :href="openidAuthUri"> <a v-show="login_openid" :href="openidAuthUri">
<ui-btn color="primary" class="leading-none">Login with OpenId</ui-btn> <ui-btn color="primary" class="leading-none">{{ openIDButtonText }}</ui-btn>
</a> </a>
</div> </div>
</div> </div>
@ -77,7 +77,8 @@ export default {
MetadataPath: '', MetadataPath: '',
login_local: true, login_local: true,
login_google_oauth20: false, login_google_oauth20: false,
login_openid: false login_openid: false,
authFormData: null
} }
}, },
watch: { watch: {
@ -116,6 +117,9 @@ export default {
}, },
openidAuthUri() { openidAuthUri() {
return `${process.env.serverUrl}/auth/openid?callback=${location.toString()}` return `${process.env.serverUrl}/auth/openid?callback=${location.toString()}`
},
openIDButtonText() {
return this.authFormData?.authOpenIDButtonText || 'Login with OpenId'
} }
}, },
methods: { methods: {
@ -221,7 +225,6 @@ export default {
this.$axios this.$axios
.$get('/status') .$get('/status')
.then((data) => { .then((data) => {
this.processing = false
this.isInit = data.isInit this.isInit = data.isInit
this.showInitScreen = !data.isInit this.showInitScreen = !data.isInit
this.$setServerLanguageCode(data.language) this.$setServerLanguageCode(data.language)
@ -229,14 +232,17 @@ export default {
this.ConfigPath = data.ConfigPath || '' this.ConfigPath = data.ConfigPath || ''
this.MetadataPath = data.MetadataPath || '' this.MetadataPath = data.MetadataPath || ''
} else { } else {
this.authFormData = data.authFormData
this.updateLoginVisibility(data.authMethods || []) this.updateLoginVisibility(data.authMethods || [])
} }
}) })
.catch((error) => { .catch((error) => {
console.error('Status check failed', error) console.error('Status check failed', error)
this.processing = false
this.criticalError = 'Status check failed' this.criticalError = 'Status check failed'
}) })
.finally(() => {
this.processing = false
})
}, },
updateLoginVisibility(authMethods) { updateLoginVisibility(authMethods) {
if (authMethods.includes('local') || !authMethods.length) { if (authMethods.includes('local') || !authMethods.length) {
@ -252,6 +258,11 @@ export default {
} }
if (authMethods.includes('openid')) { if (authMethods.includes('openid')) {
// Auto redirect unless query string ?autoLaunch=0
if (this.authFormData?.authOpenIDAutoLaunch && this.$route.query?.autoLaunch !== '0') {
window.location.href = this.openidAuthUri
}
this.login_openid = true this.login_openid = true
} else { } else {
this.login_openid = false this.login_openid = false

View File

@ -230,7 +230,8 @@ class Server {
const payload = { const payload = {
isInit: Database.hasRootUser, isInit: Database.hasRootUser,
language: Database.serverSettings.language, language: Database.serverSettings.language,
authMethods: Database.serverSettings.authActiveAuthMethods authMethods: Database.serverSettings.authActiveAuthMethods,
authFormData: Database.serverSettings.authFormData
} }
if (!payload.isInit) { if (!payload.isInit) {
payload.ConfigPath = global.ConfigPath payload.ConfigPath = global.ConfigPath

View File

@ -70,6 +70,8 @@ class ServerSettings {
this.authOpenIDUserInfoURL = '' this.authOpenIDUserInfoURL = ''
this.authOpenIDClientID = '' this.authOpenIDClientID = ''
this.authOpenIDClientSecret = '' this.authOpenIDClientSecret = ''
this.authOpenIDButtonText = 'Login with OpenId'
this.authOpenIDAutoLaunch = false
if (settings) { if (settings) {
this.construct(settings) this.construct(settings)
@ -122,6 +124,8 @@ class ServerSettings {
this.authOpenIDUserInfoURL = settings.authOpenIDUserInfoURL || '' this.authOpenIDUserInfoURL = settings.authOpenIDUserInfoURL || ''
this.authOpenIDClientID = settings.authOpenIDClientID || '' this.authOpenIDClientID = settings.authOpenIDClientID || ''
this.authOpenIDClientSecret = settings.authOpenIDClientSecret || '' this.authOpenIDClientSecret = settings.authOpenIDClientSecret || ''
this.authOpenIDButtonText = settings.authOpenIDButtonText || 'Login with OpenId'
this.authOpenIDAutoLaunch = !!settings.authOpenIDAutoLaunch
if (!Array.isArray(this.authActiveAuthMethods)) { if (!Array.isArray(this.authActiveAuthMethods)) {
this.authActiveAuthMethods = ['local'] this.authActiveAuthMethods = ['local']
@ -221,7 +225,9 @@ class ServerSettings {
authOpenIDTokenURL: this.authOpenIDTokenURL, authOpenIDTokenURL: this.authOpenIDTokenURL,
authOpenIDUserInfoURL: this.authOpenIDUserInfoURL, authOpenIDUserInfoURL: this.authOpenIDUserInfoURL,
authOpenIDClientID: this.authOpenIDClientID, // Do not return to client authOpenIDClientID: this.authOpenIDClientID, // Do not return to client
authOpenIDClientSecret: this.authOpenIDClientSecret // Do not return to client authOpenIDClientSecret: this.authOpenIDClientSecret, // Do not return to client
authOpenIDButtonText: this.authOpenIDButtonText,
authOpenIDAutoLaunch: this.authOpenIDAutoLaunch
} }
} }
@ -246,10 +252,21 @@ class ServerSettings {
authOpenIDTokenURL: this.authOpenIDTokenURL, authOpenIDTokenURL: this.authOpenIDTokenURL,
authOpenIDUserInfoURL: this.authOpenIDUserInfoURL, authOpenIDUserInfoURL: this.authOpenIDUserInfoURL,
authOpenIDClientID: this.authOpenIDClientID, // Do not return to client authOpenIDClientID: this.authOpenIDClientID, // Do not return to client
authOpenIDClientSecret: this.authOpenIDClientSecret // Do not return to client authOpenIDClientSecret: this.authOpenIDClientSecret, // Do not return to client
authOpenIDButtonText: this.authOpenIDButtonText,
authOpenIDAutoLaunch: this.authOpenIDAutoLaunch
} }
} }
get authFormData() {
const clientFormData = {}
if (this.authActiveAuthMethods.includes('openid')) {
clientFormData.authOpenIDButtonText = this.authOpenIDButtonText
clientFormData.authOpenIDAutoLaunch = this.authOpenIDAutoLaunch
}
return clientFormData
}
/** /**
* Update server settings * Update server settings
* *