From 9af204b293a9c1b15e472423a4badff505fd662a Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Fri, 26 Oct 2018 15:16:23 +0200 Subject: Move login to oauth. --- src/modules/oauth.js | 18 ++++++++++++++++++ src/modules/users.js | 10 ++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 src/modules/oauth.js (limited to 'src/modules') diff --git a/src/modules/oauth.js b/src/modules/oauth.js new file mode 100644 index 00000000..144ff830 --- /dev/null +++ b/src/modules/oauth.js @@ -0,0 +1,18 @@ +const oauth = { + state: { + client_id: false, + client_secret: false, + token: false + }, + mutations: { + setClientData (state, data) { + state.client_id = data.client_id + state.client_secret = data.client_secret + }, + setToken (state, token) { + state.token = token + } + } +} + +export default oauth diff --git a/src/modules/users.js b/src/modules/users.js index e90d6bb9..8630ee0d 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -82,24 +82,26 @@ const users = { }, logout (store) { store.commit('clearCurrentUser') + store.commit('setToken', false) store.dispatch('stopFetching', 'friends') store.commit('setBackendInteractor', backendInteractorService()) }, - loginUser (store, userCredentials) { + loginUser (store, accessToken) { return new Promise((resolve, reject) => { const commit = store.commit commit('beginLogin') - store.rootState.api.backendInteractor.verifyCredentials(userCredentials) + store.rootState.api.backendInteractor.verifyCredentials(accessToken) .then((response) => { if (response.ok) { response.json() .then((user) => { - user.credentials = userCredentials + // user.credentials = userCredentials + user.credentials = accessToken commit('setCurrentUser', user) commit('addNewUsers', [user]) // Set our new backend interactor - commit('setBackendInteractor', backendInteractorService(userCredentials)) + commit('setBackendInteractor', backendInteractorService(accessToken)) if (user.token) { store.dispatch('initializeSocket', user.token) -- cgit v1.2.3-70-g09d2 From 50264410f541c8f9f3416bd0027fc199cb96e424 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Wed, 7 Nov 2018 16:56:12 +0100 Subject: Add login form back in. --- README.md | 6 ++++++ src/boot/after_store.js | 2 ++ src/components/login_form/login_form.js | 26 ++++++++++++++++++-------- src/components/login_form/login_form.vue | 19 ++++++++++++++++++- src/modules/instance.js | 1 + static/config.json | 3 ++- 6 files changed, 47 insertions(+), 10 deletions(-) (limited to 'src/modules') diff --git a/README.md b/README.md index 5a3e2a4b..b6e5a586 100644 --- a/README.md +++ b/README.md @@ -32,3 +32,9 @@ npm run unit # Configuration Edit config.json for configuration. scopeOptionsEnabled gives you input fields for CWs and the scope settings. + +## Options + +### Login methods + +```loginMethod``` can be set to either ```password``` (the default) or ```token```, which will use the full oauth redirection flow, which is useful for SSO situations. diff --git a/src/boot/after_store.js b/src/boot/after_store.js index 65d1ea02..6b8aef7f 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -53,6 +53,7 @@ const afterStoreSetup = ({store, i18n}) => { var scopeOptionsEnabled = (config.scopeOptionsEnabled) var formattingOptionsEnabled = (config.formattingOptionsEnabled) var collapseMessageWithSubject = (config.collapseMessageWithSubject) + var loginMethod = (config.loginMethod) store.dispatch('setInstanceOption', { name: 'theme', value: theme }) store.dispatch('setInstanceOption', { name: 'background', value: background }) @@ -67,6 +68,7 @@ const afterStoreSetup = ({store, i18n}) => { store.dispatch('setInstanceOption', { name: 'scopeOptionsEnabled', value: scopeOptionsEnabled }) store.dispatch('setInstanceOption', { name: 'formattingOptionsEnabled', value: formattingOptionsEnabled }) store.dispatch('setInstanceOption', { name: 'collapseMessageWithSubject', value: collapseMessageWithSubject }) + store.dispatch('setInstanceOption', { name: 'loginMethod', value: loginMethod }) if (chatDisabled) { store.dispatch('disableChat') } diff --git a/src/components/login_form/login_form.js b/src/components/login_form/login_form.js index ffdd5504..49868aed 100644 --- a/src/components/login_form/login_form.js +++ b/src/components/login_form/login_form.js @@ -5,6 +5,7 @@ const LoginForm = { authError: false }), computed: { + loginMethod () { return this.$store.state.instance.loginMethod }, loggingIn () { return this.$store.state.users.loggingIn }, registrationOpen () { return this.$store.state.instance.registrationOpen } }, @@ -17,14 +18,23 @@ const LoginForm = { }) }, submit () { - this.$store.dispatch('loginUser', this.user).then( - () => {}, - (error) => { - this.authError = error - this.user.username = '' - this.user.password = '' - } - ) + const data = { + oauth: this.$store.state.oauth, + instance: this.$store.state.instance.server + } + oauthApi.getOrCreateApp(data).then((app) => { + oauthApi.getTokenWithCredentials( + { + app, + instance: data.instance, + username: this.user.username, + password: this.user.password}) + .then((result) => { + this.$store.commit('setToken', result.access_token) + this.$store.dispatch('loginUser', result.access_token) + this.$router.push('/main/friends') + }) + }) } } } diff --git a/src/components/login_form/login_form.vue b/src/components/login_form/login_form.vue index db389716..8a5174d7 100644 --- a/src/components/login_form/login_form.vue +++ b/src/components/login_form/login_form.vue @@ -5,7 +5,24 @@ {{$t('login.login')}}
- + +