Merge branch 'mfa/login_form' into 'develop'

mfa: fix login and recovery form

See merge request pleroma/pleroma-fe!1031
This commit is contained in:
HJ 2019-12-13 10:18:50 +00:00
commit 9789123b1c
5 changed files with 24 additions and 20 deletions

View file

@ -58,7 +58,7 @@ const LoginForm = {
).then((result) => { ).then((result) => {
if (result.error) { if (result.error) {
if (result.error === 'mfa_required') { if (result.error === 'mfa_required') {
this.requireMFA({ app: app, settings: result }) this.requireMFA({ settings: result })
} else if (result.identifier === 'password_reset_required') { } else if (result.identifier === 'password_reset_required') {
this.$router.push({ name: 'password-reset', params: { passwordResetRequested: true } }) this.$router.push({ name: 'password-reset', params: { passwordResetRequested: true } })
} else { } else {

View file

@ -8,18 +8,23 @@ export default {
}), }),
computed: { computed: {
...mapGetters({ ...mapGetters({
authApp: 'authFlow/app',
authSettings: 'authFlow/settings' authSettings: 'authFlow/settings'
}), }),
...mapState({ instance: 'instance' }) ...mapState({
instance: 'instance',
oauth: 'oauth'
})
}, },
methods: { methods: {
...mapMutations('authFlow', ['requireTOTP', 'abortMFA']), ...mapMutations('authFlow', ['requireTOTP', 'abortMFA']),
...mapActions({ login: 'authFlow/login' }), ...mapActions({ login: 'authFlow/login' }),
clearError () { this.error = false }, clearError () { this.error = false },
submit () { submit () {
const { clientId, clientSecret } = this.oauth
const data = { const data = {
app: this.authApp, clientId,
clientSecret,
instance: this.instance.server, instance: this.instance.server,
mfaToken: this.authSettings.mfa_token, mfaToken: this.authSettings.mfa_token,
code: this.code code: this.code

View file

@ -7,18 +7,23 @@ export default {
}), }),
computed: { computed: {
...mapGetters({ ...mapGetters({
authApp: 'authFlow/app',
authSettings: 'authFlow/settings' authSettings: 'authFlow/settings'
}), }),
...mapState({ instance: 'instance' }) ...mapState({
instance: 'instance',
oauth: 'oauth'
})
}, },
methods: { methods: {
...mapMutations('authFlow', ['requireRecovery', 'abortMFA']), ...mapMutations('authFlow', ['requireRecovery', 'abortMFA']),
...mapActions({ login: 'authFlow/login' }), ...mapActions({ login: 'authFlow/login' }),
clearError () { this.error = false }, clearError () { this.error = false },
submit () { submit () {
const { clientId, clientSecret } = this.oauth
const data = { const data = {
app: this.authApp, clientId,
clientSecret,
instance: this.instance.server, instance: this.instance.server,
mfaToken: this.authSettings.mfa_token, mfaToken: this.authSettings.mfa_token,
code: this.code code: this.code

View file

@ -7,7 +7,6 @@ const RECOVERY_STRATEGY = 'recovery'
// initial state // initial state
const state = { const state = {
app: null,
settings: {}, settings: {},
strategy: PASSWORD_STRATEGY, strategy: PASSWORD_STRATEGY,
initStrategy: PASSWORD_STRATEGY // default strategy from config initStrategy: PASSWORD_STRATEGY // default strategy from config
@ -16,14 +15,10 @@ const state = {
const resetState = (state) => { const resetState = (state) => {
state.strategy = state.initStrategy state.strategy = state.initStrategy
state.settings = {} state.settings = {}
state.app = null
} }
// getters // getters
const getters = { const getters = {
app: (state, getters) => {
return state.app
},
settings: (state, getters) => { settings: (state, getters) => {
return state.settings return state.settings
}, },
@ -55,9 +50,8 @@ const mutations = {
requireToken (state) { requireToken (state) {
state.strategy = TOKEN_STRATEGY state.strategy = TOKEN_STRATEGY
}, },
requireMFA (state, { app, settings }) { requireMFA (state, { settings }) {
state.settings = settings state.settings = settings
state.app = app
state.strategy = TOTP_STRATEGY // default strategy of MFA state.strategy = TOTP_STRATEGY // default strategy of MFA
}, },
requireRecovery (state) { requireRecovery (state) {

View file

@ -1,9 +1,9 @@
const verifyOTPCode = ({ app, instance, mfaToken, code }) => { const verifyOTPCode = ({ clientId, clientSecret, instance, mfaToken, code }) => {
const url = `${instance}/oauth/mfa/challenge` const url = `${instance}/oauth/mfa/challenge`
const form = new window.FormData() const form = new window.FormData()
form.append('client_id', app.client_id) form.append('client_id', clientId)
form.append('client_secret', app.client_secret) form.append('client_secret', clientSecret)
form.append('mfa_token', mfaToken) form.append('mfa_token', mfaToken)
form.append('code', code) form.append('code', code)
form.append('challenge_type', 'totp') form.append('challenge_type', 'totp')
@ -14,12 +14,12 @@ const verifyOTPCode = ({ app, instance, mfaToken, code }) => {
}).then((data) => data.json()) }).then((data) => data.json())
} }
const verifyRecoveryCode = ({ app, instance, mfaToken, code }) => { const verifyRecoveryCode = ({ clientId, clientSecret, instance, mfaToken, code }) => {
const url = `${instance}/oauth/mfa/challenge` const url = `${instance}/oauth/mfa/challenge`
const form = new window.FormData() const form = new window.FormData()
form.append('client_id', app.client_id) form.append('client_id', clientId)
form.append('client_secret', app.client_secret) form.append('client_secret', clientSecret)
form.append('mfa_token', mfaToken) form.append('mfa_token', mfaToken)
form.append('code', code) form.append('code', code)
form.append('challenge_type', 'recovery') form.append('challenge_type', 'recovery')