Authentication with OpenID Connect providers (#305)
Fix setting auth config from api in state Verify auth state before authenticating Add showing openid providers on login Parse auth config from /info Add authentication through openid Add openid auth component Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/305 Co-Authored-By: konrad <konrad@kola-entertainments.de> Co-Committed-By: konrad <konrad@kola-entertainments.de>
This commit is contained in:
@ -98,6 +98,40 @@ export default {
|
||||
ctx.commit(LOADING, false, {root: true})
|
||||
})
|
||||
},
|
||||
openIdAuth(ctx, {provider, code}) {
|
||||
const HTTP = HTTPFactory()
|
||||
ctx.commit(LOADING, true, {root: true})
|
||||
|
||||
const data = {
|
||||
code: code,
|
||||
}
|
||||
|
||||
// Delete an eventually preexisting old token
|
||||
localStorage.removeItem('token')
|
||||
return HTTP.post(`/auth/openid/${provider}/callback`, data)
|
||||
.then(response => {
|
||||
// Save the token to local storage for later use
|
||||
localStorage.setItem('token', response.data.token)
|
||||
|
||||
// Tell others the user is autheticated
|
||||
ctx.commit('isLinkShareAuth', false)
|
||||
ctx.dispatch('checkAuth')
|
||||
return Promise.resolve()
|
||||
})
|
||||
.catch(e => {
|
||||
if (e.response) {
|
||||
let errorMsg = e.response.data.message
|
||||
if (e.response.status === 401) {
|
||||
errorMsg = 'Wrong username or password.'
|
||||
}
|
||||
ctx.commit(ERROR_MESSAGE, errorMsg, {root: true})
|
||||
}
|
||||
return Promise.reject()
|
||||
})
|
||||
.finally(() => {
|
||||
ctx.commit(LOADING, false, {root: true})
|
||||
})
|
||||
},
|
||||
|
||||
linkShareAuth(ctx, hash) {
|
||||
const HTTP = HTTPFactory()
|
||||
|
@ -1,5 +1,8 @@
|
||||
import Vue from 'vue'
|
||||
|
||||
import {CONFIG} from '../mutation-types'
|
||||
import {HTTPFactory} from '@/http-common'
|
||||
import {objectToCamelCase} from '@/helpers/case'
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
@ -20,6 +23,16 @@ export default {
|
||||
privacyPolicyUrl: '',
|
||||
},
|
||||
caldavEnabled: false,
|
||||
auth: {
|
||||
local: {
|
||||
enabled: true,
|
||||
},
|
||||
openidConnect: {
|
||||
enabled: false,
|
||||
redirectUrl: '',
|
||||
providers: [],
|
||||
},
|
||||
},
|
||||
}),
|
||||
mutations: {
|
||||
[CONFIG](state, config) {
|
||||
@ -36,6 +49,11 @@ export default {
|
||||
state.legal.imprintUrl = config.legal.imprint_url
|
||||
state.legal.privacyPolicyUrl = config.legal.privacy_policy_url
|
||||
state.caldavEnabled = config.caldav_enabled
|
||||
const auth = objectToCamelCase(config.auth)
|
||||
state.auth.local.enabled = auth.local.enabled
|
||||
state.auth.openidConnect.enabled = auth.openidConnect.enabled
|
||||
state.auth.openidConnect.redirectUrl = auth.openidConnect.redirectUrl
|
||||
Vue.set(state.auth.openidConnect, 'providers', auth.openidConnect.providers)
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
|
Reference in New Issue
Block a user