Commit 4b559e3d authored by A. Koch's avatar A. Koch

updated metapak, auth0 updates, fixes, patch version bump

parent 6de80a2f
......@@ -66,7 +66,3 @@ _book
*.pdf
.idea
# configuration
auth0.json
{
"domain": "yourdomain.auth0.com",
"clientID": "YOUR_CLIENT_ID",
"audience": "https://yourdomain.com/userinfo",
"redirectUri": "http://localhost:8080/users/callback"
}
......@@ -9,6 +9,7 @@ var
ProgressBarPlugin = require('progress-bar-webpack-plugin'),
appConfig = require('../package.json').appConfig,
apiHost = process.env.API_HOST || appConfig.apiHost,
frontendHost = process.env.FRONTEND_HOST || appConfig.frontendHost,
streamerHost = process.env.STREAMER_HOST || appConfig.streamerHost,
useAuth0 = (process.env.USE_AUTH0) || (appConfig.useAuth0),
useWebSockets = (process.env.USE_WEBSOCKETS) || (appConfig.useWebSockets),
......@@ -20,12 +21,22 @@ function resolve (dir) {
return path.join(__dirname, '..', dir)
}
process.stdout.write(` idField: ${appConfig.idField}\n`)
process.stdout.write(` Router mode: ${env.routerMode}\n\n`)
process.stdout.write(` API_HOST: ${apiHost}\n`)
process.stdout.write(` FRONTEND_HOST: ${frontendHost}\n`)
process.stdout.write(` STREAMER_HOST: ${streamerHost}\n\n`)
process.stdout.write(` USE_AUTH0: ${useAuth0}\n`)
process.stdout.write(` USE_WEBSOCKETS: ${useWebSockets}\n\n`)
process.stdout.write(` idField: ${appConfig.idField}\n`)
process.stdout.write(` Router mode: ${env.routerMode}\n\n`)
const
conf = JSON.stringify(
useAuth0 ? config.auth.auth0 : config.auth.local,
null,
' '
).replace(/"/g, '')
process.stdout.write(` Auth config (${useAuth0 ? 'Auth0' : 'Local'}):\n`)
process.stdout.write(`${conf.substr(2, conf.length - 4)}\n\n`)
module.exports = {
entry: {
......
var path = require('path')
const
path = require('path'),
pkg = require('../package.json')
module.exports = {
// Webpack aliases
......@@ -17,6 +19,26 @@ module.exports = {
// Default theme to build with ('ios' or 'mat')
defaultTheme: 'mat',
appConfig: {
apiHost: 'https://motionbank-api.herokuapp.com',
streamerHost: 'http://localhost:8888',
frontendHost: 'http://localhost:8080',
idField: 'uuid',
useAuth0: false,
useWebSockets: false
},
auth: {
common: {},
auth0: {
domain: process.env.AUTH0_DOMAIN || 'motionbank.eu.auth0.com',
clientID: process.env.AUTH0_CLIENT_ID || 'lyVRrHYxUCOosFip40Ws5BRJyfHWSWTi',
audience: process.env.AUTH0_AUDIENCE || 'https://motionbank.eu.auth0.com/userinfo',
redirectUri: (process.env.FRONTEND_HOST || pkg.appConfig.frontendHost) + '/users/callback'
},
local: {}
},
build: {
env: require('./prod.env'),
publicPath: '',
......
{
"name": "motionbank-systems-frontend",
"version": "0.2.0",
"version": "0.2.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
......@@ -6971,9 +6971,9 @@
}
},
"metapak-motionbank": {
"version": "1.7.5",
"resolved": "https://registry.npmjs.org/metapak-motionbank/-/metapak-motionbank-1.7.5.tgz",
"integrity": "sha512-DvcvnpXCpCmwvpa13QOfZnMhPiJtgZwgnYdCA/JFeAvVUSN2xCxsBRzY2NnKMN5Qq8eFyTAJKp7esxC+jdxH3g==",
"version": "1.7.7",
"resolved": "https://registry.npmjs.org/metapak-motionbank/-/metapak-motionbank-1.7.7.tgz",
"integrity": "sha512-BSIOb5EiqK7R/QCtELa4KardURmqsiWoEqWpeT5gMP91IiCCzuciwcWxhzvPLsSZ7xSBl2tee8MjIFUDFVWevw==",
"dev": true,
"requires": {
"bluebird": "3.5.1",
......
{
"name": "motionbank-systems-frontend",
"productName": "Motion Bank Systems Frontend",
"version": "0.2.0",
"version": "0.2.1",
"private": true,
"description": "Combined frontend project for Motion Bank web services",
"metapak": {
......@@ -105,7 +105,7 @@
"json-loader": "^0.5.4",
"material-design-icons": "^3.0.1",
"metapak": "^1.0.2",
"metapak-motionbank": "^1.7.5",
"metapak-motionbank": "^1.7.7",
"mkdirp": "^0.5.1",
"mocha": "^4.0.1",
"opn": "^5.0.0",
......@@ -137,6 +137,7 @@
"appConfig": {
"apiHost": "https://motionbank-api.herokuapp.com",
"streamerHost": "http://localhost:8888",
"frontendHost": "http://localhost:8080",
"idField": "uuid",
"useAuth0": false,
"useWebSockets": false
......
......@@ -11,15 +11,13 @@
*/
import UserNav from './components/shared/partials/UserNav'
import { EVENT_AUTH_CHANGE } from './lib/services/auth'
import {
QLayout
} from 'quasar-framework'
import { QLayout } from 'quasar-framework'
export default {
data () {
const
_this = this,
{ auth, authenticated } = _this.$authService()
{ auth, authenticated } = this.$authService()
this.$authService().on(EVENT_AUTH_CHANGE, authState => {
_this.authenticated = authState.authenticated
......@@ -30,6 +28,7 @@ export default {
}).catch(err => {
console.debug('No session:',
err.error || err.message, err.error_description)
if (err.stack) console.debug(err.stack)
})
return {
......
<template lang="pug">
p Logging in...
.row.fullscreen.vertical-middle.justify-center.items-center
q-spinner-tail(color="primary", :size="72")
</template>
<script>
import {
QSpinnerTail
} from 'quasar-framework'
export default {
components: {
QSpinnerTail
},
props: ['auth'],
mounted () {
const _this = this
this.auth.handleAuthentication().then(res => {
console.log(res)
_this.$router.replace({ name: 'users.edit', params: { id: 'me' } })
this.$authService().handleAuthentication().then(() => {
_this.$store.commit('notifications/addMessage', {
body: _this.$t('messages.login_success'),
type: 'success'
})
_this.$router.replace({ name: 'users.edit', params: { id: 'me' } })
}).catch(err => {
_this.$router.replace({ name: 'site.welcome' })
console.debug('Auth0 callback error:', err)
_this.$store.commit('notifications/addMessage', {
body: err.message,
type: 'error'
})
_this.$router.replace({ name: 'site.welcome' })
})
}
}
......
import auth0 from 'auth0-js'
import auth from '@feathersjs/authentication-client'
import router from '../../../router'
import assignDeep from 'assign-deep'
......@@ -11,7 +12,16 @@ class Auth0 extends BaseAuth {
scope: 'openid profile email'
}, opts), env)
this._auth = new auth0.WebAuth(this.config)
const config = this.config
this._auth = auth({ storage: window.localStorage })
this._webAuth = new auth0.WebAuth(config)
this._authDefaults = {
audience: config.audience,
scope: config.scope,
responseType: config.responseType,
redirectUri: config.redirectUri
}
if (this._Vue && localStorage.getItem('access_token')) {
const _this = this
......@@ -20,68 +30,64 @@ class Auth0 extends BaseAuth {
common: _this.getAuthHeader(localStorage.getItem('access_token'))
}
})
console.debug(this._Vue.http)
}
}
login () {
const config = this.config
this.auth.authorize({
audience: config.audience,
scope: config.scope,
responseType: config.responseType,
redirectUri: config.redirectUri
})
this.webAuth.authorize(this._authDefaults)
}
logout () {
localStorage.removeItem('access_token')
localStorage.removeItem('id_token')
localStorage.removeItem('expires_at')
localStorage.removeItem('user')
super.logout()
router.replace('site.welcome')
router.replace({ name: 'site.welcome' })
}
handleAuthentication () {
const _this = this
return new Promise((resolve, reject) => {
_this.auth.parseHash({ hash: window.location.hash }, (err, authResult) => {
_this.webAuth.parseHash({ hash: window.location.hash }, (err, authResult) => {
if (authResult && authResult.accessToken && authResult.idToken) {
_this.setSession(authResult)
console.debug('Auth0 Access Token:', authResult.accessToken)
console.debug('Auth0 ID Token:', authResult.idToken)
_this.auth.client.userInfo(authResult.accessToken, (err, user) => {
_this.setSession(authResult)
_this.webAuth.client.userInfo(authResult.accessToken, (err, user) => {
if (err) return reject(err)
_this._user = user
resolve({ authResult, user })
localStorage.setItem('user', user)
_this.emit(BaseAuth.EVENT_AUTH_CHANGE, { authenticated: true })
resolve()
})
}
else if (err) {
console.error('Auth0:', err.error || err.message, err.error_description)
reject(err)
}
else {
reject(new Error('Auth0: Handle auth result null or invalid'))
}
})
})
}
setSession (authResult) {
setSession (authResult, silent = false) {
let expiresAt = JSON.stringify(authResult.expiresIn * 1000 + new Date().getTime())
localStorage.setItem('access_token', authResult.accessToken)
localStorage.setItem('id_token', authResult.idToken)
localStorage.setItem('expires_at', expiresAt)
super.setSession(authResult)
super.setSession(authResult, silent)
}
checkSession () {
const
_this = this,
config = this.config
const _this = this
return new Promise((resolve, reject) => {
_this.auth.checkSession({
audience: config.audience,
scope: config.scope,
responseType: config.responseType
}, (err, res) => {
if (err) return reject(err)
_this.webAuth.checkSession(_this._authDefaults, (err, res) => {
if (err) {
return reject(err)
}
_this.emit(BaseAuth.EVENT_AUTH_CHANGE, { authenticated: true })
resolve(res)
})
......@@ -92,6 +98,18 @@ class Auth0 extends BaseAuth {
const expiresAt = JSON.parse(localStorage.getItem('expires_at'))
return new Date().getTime() < expiresAt && (localStorage.getItem('id_token'))
}
getAuthHeader () {
return super.getAuthHeader(localStorage.getItem('id_token'))
}
get webAuth () {
return this._webAuth
}
get user () {
return localStorage.getItem('user')
}
}
export default Auth0
......@@ -30,12 +30,12 @@ class BaseAuth extends TinyEmitter {
/* noop */
}
setSession (authResult = undefined) {
this.emit(BaseAuth.EVENT_AUTH_CHANGE, { authenticated: true })
setSession (authResult = undefined, silent = false) {
if (!silent) this.emit(BaseAuth.EVENT_AUTH_CHANGE, { authenticated: true })
}
checkSession () {
/* noop */
return Promise.resolve(false)
}
isAuthenticated () {
......
......@@ -5,20 +5,21 @@ import BaseAuth from './base'
import Auth0 from './auth0'
import Local from './local'
const authConfig = require('../../../../config').auth
class AuthService {
static install (Vue) {
let
provider,
client = auth({
client = auth(Object.assign({
storage: window.localStorage
})
}, authConfig.common))
if (buildVars().useAuth0) {
const auth0Config = require('../../../../auth0.json')
provider = new Auth0(auth0Config, { client, Vue })
provider = new Auth0(authConfig.auth0, { client, Vue })
}
else {
provider = new Local({}, { client, Vue })
provider = new Local(authConfig.local, { client, Vue })
}
Vue.prototype.$authService = function () {
......
......@@ -8,9 +8,9 @@ class Local extends BaseAuth {
constructor (opts = {}, env = {}) {
super(opts, env)
this._auth = auth({
this._auth = auth(Object.assign({
storage: window.localStorage
})
}, opts))
}
login () {
......
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