Commit 1a1c380a authored by Anton's avatar Anton

Switch auth plugin to local mbjs-auth-service module

parent 66e330ca
Pipeline #31437 passed with stage
in 1 minute and 35 seconds
This diff is collapsed.
......@@ -6,29 +6,30 @@
<script>
export default {
props: ['auth'],
mounted () {
const _this = this
this.$auth.handleAuthentication(this.$store).then(({user, first}) => {
console.debug('Auth0 authenticated user', user)
_this.$store.commit('notifications/addMessage', {
body: _this.$t('messages.login_success'),
async mounted () {
try {
const { user, first } = await this.$auth.handleAuthentication(this.$store)
console.debug('Authenticated user', user)
this.$store.commit('notifications/addMessage', {
body: this.$t('messages.login_success'),
type: 'success'
})
const redirect = _this.$store.state.auth.redirectUri
const redirect = this.$store.state.auth.redirectUri
if (redirect && !first) {
_this.$store.commit('auth/clearRedirect')
_this.$router.replace(redirect)
this.$store.commit('auth/clearRedirect')
this.$router.replace(redirect)
}
else if (first) _this.$router.replace({name: 'users.manage', params: {isFirst: true}})
else _this.$router.replace({name: 'site.welcome'})
}).catch(err => {
console.error('Auth0 callback error:', err.error || err.message, err.error_description)
_this.$store.commit('notifications/addMessage', {
else if (first) this.$router.replace({name: 'users.manage', params: {isFirst: true}})
else this.$router.replace({name: 'site.welcome'})
}
catch (err) {
console.error('Auth0 callback error:', err)
this.$store.commit('notifications/addMessage', {
body: err.message,
type: 'error'
})
_this.$router.replace({name: 'site.welcome'})
})
this.$router.replace({name: 'site.welcome'})
}
}
}
</script>
import AuthServiceWeb from 'mbjs-quasar/src/lib/auth-service'
import AuthServiceElectron from 'mbjs-quasar/src/lib/auth-service-electron'
import { AuthServiceAuth0, AuthServiceOauth2 } from 'mbjs-auth-service'
import AuthServiceElectron from 'mbjs-auth-service/src/auth-service-electron'
export default ({ Vue }) => {
let authService
......@@ -7,16 +7,18 @@ export default ({ Vue }) => {
authService = new AuthServiceElectron()
}
else if (process.env.OAUTH_CLIENT_ID) {
authService = new AuthServiceWeb({
authService = new AuthServiceOauth2({
client_id: process.env.OAUTH_CLIENT_ID,
client_secret: process.env.OAUTH_CLIENT_SECRET,
redirectUri: process.env.OAUTH_REDIRECT_URL || `${document.location.origin}/users/callback`,
authorization: process.env.OAUTH_AUTH_URL,
token: process.env.OAUTH_TOKEN_URL
}, 'oauth2')
token: process.env.OAUTH_TOKEN_URL,
profileEndpoint: `${process.env.API_HOST}user_profile/`,
response_type: 'token'
})
}
else if (process.env.AUTH0_CLIENT_ID) {
authService = new AuthServiceWeb({
authService = new AuthServiceAuth0({
domain: process.env.AUTH0_DOMAIN || window.AUTH0_DOMAIN,
clientID: process.env.AUTH0_CLIENT_ID || window.AUTH0_CLIENT_ID,
redirectUri: process.env.AUTH0_REDIRECT_URL || `${document.location.origin}/users/callback`,
......@@ -24,7 +26,7 @@ export default ({ Vue }) => {
scope: 'openid profile read write',
responseType: 'token id_token',
prompt: 'none'
}, 'auth0')
})
}
Vue.prototype.$auth = authService
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment