diff --git a/client/web/admin/src/components/Authclient/CAuthclientEditorInfo.vue b/client/web/admin/src/components/Authclient/CAuthclientEditorInfo.vue index 18215530f3..57478d78f5 100644 --- a/client/web/admin/src/components/Authclient/CAuthclientEditorInfo.vue +++ b/client/web/admin/src/components/Authclient/CAuthclientEditorInfo.vue @@ -66,7 +66,6 @@
- - - + + + + + + @@ -279,108 +297,23 @@ -
- - - - -
- - - - - - - - - -
-
-
-          curl -X POST {{ curlURL }} \
-          -d grant_type=client_credentials \
-          -d scope='profile api' \
-          -u {{ resource.resourceID }}:{{ secret || 'PLACE-YOUR-CLIENT-SECRET-HERE' }}
-                  
- - - -
-
- -
-
- {{ tokenRequest.token || tokenRequest.error }} -
- - - - -
- -
- - {{ $t('testCurl') }} - -
-
-
-
+ + +
+ + + + + + + + + + + + + + + {{ $t('generateAccessToken') }} + + +

+ {{ tokenRequest.error }} +

+
+
'', - }, - success: { type: Boolean, value: false, @@ -549,10 +552,13 @@ export default { data () { return { + requestedSecret: '', + secret: '', + redirectURI: this.resource.redirectURI ? this.resource.redirectURI.split(' ') : [], curlVisible: false, - curlURL: '', + tokenRequest: { token: '', error: '', @@ -601,6 +607,14 @@ export default { saveDisabled () { return !this.editable || [this.nameState, this.handleState].includes(false) }, + + curlURL () { + return this.$auth.cortezaAuthURL + '/oauth2/token' + }, + + exampleCurl () { + return `curl -X POST ${this.curlURL} -d grant_type=${this.resource.validGrant} -d scope='${this.resource.scope}' -u ${this.resource.authClientID}:${this.secret || 'PLACE-YOUR-CLIENT-SECRET-HERE'}` + }, }, watch: { @@ -612,43 +626,27 @@ export default { }, methods: { - onUpdateUser (user) { - this.resource.security.impersonateUser = (user || {}).userID + onUpdateUser (userID) { + this.resource.security.impersonateUser = userID }, - getAccessTokenAPI () { - const params = new URLSearchParams() - params.append('grant_type', 'client_credentials') - params.append('scope', 'profile api') - axios.post( - this.curlURL, - params, - { auth: { username: this.resource.authClientID, password: this.secret } } - ).then(response => { - this.tokenRequest.token = (response.data || {}).access_token - }).catch(error => { - this.tokenRequest.error = error - }) + onGrantChange (grant) { + if (grant === 'client_credentials' && (!this.resource.security.impersonateUser || this.resource.security.impersonateUser === NoID)) { + this.resource.security.impersonateUser = this.$auth.user.userID + } }, - copyToClipboard (name) { - if (name === 'cUrl') { - copy(this.$refs.cUrl.innerHTML) - } else { - copy(this.tokenRequest.token) - } + copyToClipboard (value) { + copy(value) }, toggleCurlSnippet () { - if (!this.curlVisible) { - this.curlURL = this.$auth.cortezaAuthURL + '/oauth2/token' - } this.curlVisible = !this.curlVisible }, submit () { if (!this.isClientCredentialsGrant || !this.resource.security.impersonateUser) { - this.resource.security.impersonateUser = '0' + this.resource.security.impersonateUser = NoID } this.$emit('submit', this.resource) @@ -665,26 +663,56 @@ export default { this.resource.scope = items.join(' ') }, + + requestSecret () { + const clientID = this.resource.authClientID + + return this.$SystemAPI.authClientExposeSecret(({ clientID })).then(secret => { + this.requestedSecret = secret + }) + }, + + async showSecret () { + if (!this.requestedSecret) { + await this.requestSecret() + } + + this.secret = this.requestedSecret + }, + + hideSecret () { + this.secret = '' + }, + + async regenerateSecret () { + const clientID = this.resource.authClientID + + this.$SystemAPI.authClientRegenerateSecret(({ clientID })).then(secret => { + this.requestedSecret = secret + }) + }, + + async getAccessTokenAPI () { + const clientID = this.resource.authClientID + + if (!this.requestedSecret) { + await this.requestSecret() + } + + const params = new URLSearchParams() + + params.append('grant_type', this.resource.validGrant) + params.append('scope', this.resource.scope) + + axios.post(this.curlURL, params, { auth: { username: clientID, password: this.requestedSecret } }).then(response => { + this.tokenRequest.token = (response.data || {}).access_token + this.tokenRequest.error = '' + }).catch(e => { + const { error } = e.response.data || {} + this.tokenRequest.error = error + this.tokenRequest.token = '' + }) + }, }, } - diff --git a/client/web/admin/src/components/Authclient/CSelectUser.vue b/client/web/admin/src/components/Authclient/CSelectUser.vue index 639bcbaf88..e6d061c1b1 100644 --- a/client/web/admin/src/components/Authclient/CSelectUser.vue +++ b/client/web/admin/src/components/Authclient/CSelectUser.vue @@ -1,17 +1,22 @@