Commit 66e330ca authored by Anton's avatar Anton

Add OAuth2 support, mbjs-quasar needs to be on 'oauth' branch

parent 33d729a4
Pipeline #31358 passed with stage
in 1 minute and 18 seconds
......@@ -10045,6 +10045,11 @@
"integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==",
"dev": true
},
"jso": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/jso/-/jso-4.1.1.tgz",
"integrity": "sha512-5siCaj9b73l52BRItlW5d7jbNJ2xEyVTskjxt2I/+kggNjqip11FngAG0KqZKWfCmpIeUahVvdVlnx4r7d99Mw=="
},
"json-buffer": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz",
......
......@@ -49,6 +49,7 @@
"bluebird": "3.5.3",
"cote": "^0.20.0",
"ffprobe-static": "^3.0.0",
"jso": "^4.1.1",
"jwt-decode": "^2.2.0",
"keytar": "^4.10.0",
"luxon": "1.8.2",
......
......@@ -85,6 +85,14 @@ module.exports = function (ctx) {
AUTH0_REDIRECT_URL: JSON.stringify(process.env.AUTH0_REDIRECT_URL),
AUTH0_AUDIENCE: JSON.stringify(process.env.AUTH0_AUDIENCE),
//
// General OAuth2
//
OAUTH_CLIENT_ID: JSON.stringify(process.env.OAUTH_CLIENT_ID),
OAUTH_CLIENT_SECRET: JSON.stringify(process.env.OAUTH_CLIENT_SECRET),
OAUTH_REDIRECT_URL: JSON.stringify(process.env.OAUTH_REDIRECT_URL),
OAUTH_AUTH_URL: JSON.stringify(process.env.OAUTH_AUTH_URL),
OAUTH_TOKEN_URL: JSON.stringify(process.env.OAUTH_TOKEN_URL),
//
// API Keys
//
SENTRY_DSN: JSON.stringify(process.env.SENTRY_DSN),
......
......@@ -38,6 +38,7 @@
transformed.title = meta && meta.title ? meta.title : _this.$t('labels.title_unknown')
if (row.target.selector) {
const parsed = row.target.selector.parse()
console.log(parsed)
if (Array.isArray(parsed['date-time:t'])) transformed.date = parsed['date-time:t'][0]
else transformed.date = parsed['date-time:t']
}
......
......@@ -8,7 +8,7 @@
props: ['auth'],
mounted () {
const _this = this
this.$auth.handleAuthentication(this.$store).then(({ user, first }) => {
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'),
......@@ -19,15 +19,15 @@
_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' })
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', {
body: err.message,
type: 'error'
})
_this.$router.replace({ name: 'site.welcome' })
_this.$router.replace({name: 'site.welcome'})
})
}
}
......
import AuthServiceWeb from 'mbjs-api-client/src/auth-service-web'
import AuthServiceWeb from 'mbjs-quasar/src/lib/auth-service'
import AuthServiceElectron from 'mbjs-quasar/src/lib/auth-service-electron'
export default ({ Vue }) => {
......@@ -6,7 +6,16 @@ export default ({ Vue }) => {
if (process.env.IS_ELECTRON) {
authService = new AuthServiceElectron()
}
else {
else if (process.env.OAUTH_CLIENT_ID) {
authService = new AuthServiceWeb({
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')
}
else if (process.env.AUTH0_CLIENT_ID) {
authService = new AuthServiceWeb({
domain: process.env.AUTH0_DOMAIN || window.AUTH0_DOMAIN,
clientID: process.env.AUTH0_CLIENT_ID || window.AUTH0_CLIENT_ID,
......@@ -15,7 +24,7 @@ export default ({ Vue }) => {
scope: 'openid profile read write',
responseType: 'token id_token',
prompt: 'none'
})
}, 'auth0')
}
Vue.prototype.$auth = authService
......
......@@ -46,18 +46,20 @@ if (process.env.USE_NEDB) {
}
else {
/** Instantiate Motion Bank API Client */
apiClient = new WebAuth({
auth: {
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`,
audience: process.env.AUTH0_AUDIENCE || window.AUTH0_AUDIENCE,
scope: 'openid profile read write',
responseType: 'token id_token',
prompt: 'none'
},
host: process.env.API_HOST || window.API_HOST
})
if (!process.env.OAUTH_CLIENT_ID) {
apiClient = new WebAuth({
auth: {
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`,
audience: process.env.AUTH0_AUDIENCE || window.AUTH0_AUDIENCE,
scope: 'openid profile read write',
responseType: 'token id_token',
prompt: 'none'
},
host: process.env.API_HOST || window.API_HOST
})
}
}
/**
......
......@@ -17,8 +17,8 @@ export default {
mutations: {
setUser: (state, user) => {
if (user) {
Assert.isType(user.sub, 'string', 'Auth0 ID missing in user object')
user.uuid = ObjectUtil.uuid5(user.sub)
Assert.isType(user.sub || user.id, 'string', 'ID missing in user object')
user.uuid = user.uuid || ObjectUtil.uuid5(user.sub || user.id)
}
state.user = user
},
......
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