move mfa.js to the rest of the API
This commit is contained in:
parent
61f93ad955
commit
7a02ae396e
4 changed files with 64 additions and 72 deletions
46
src/api/mfa.js
Normal file
46
src/api/mfa.js
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
import { promisedRequest } from './helpers.js'
|
||||||
|
|
||||||
|
export const verifyOTPCode = ({
|
||||||
|
clientId,
|
||||||
|
clientSecret,
|
||||||
|
instance,
|
||||||
|
mfaToken,
|
||||||
|
code,
|
||||||
|
}) => {
|
||||||
|
const formData = new window.FormData()
|
||||||
|
|
||||||
|
formData.append('client_id', clientId)
|
||||||
|
formData.append('client_secret', clientSecret)
|
||||||
|
formData.append('mfa_token', mfaToken)
|
||||||
|
formData.append('code', code)
|
||||||
|
formData.append('challenge_type', 'totp')
|
||||||
|
|
||||||
|
return promisedRequest({
|
||||||
|
url: '/oauth/mfa/challenge'
|
||||||
|
method: 'POST',
|
||||||
|
formData,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const verifyRecoveryCode = ({
|
||||||
|
clientId,
|
||||||
|
clientSecret,
|
||||||
|
instance,
|
||||||
|
mfaToken,
|
||||||
|
code,
|
||||||
|
}) => {
|
||||||
|
const url = `${instance}`
|
||||||
|
const formData = new window.FormData()
|
||||||
|
|
||||||
|
formData.append('client_id', clientId)
|
||||||
|
formData.append('client_secret', clientSecret)
|
||||||
|
formData.append('mfa_token', mfaToken)
|
||||||
|
formData.append('code', code)
|
||||||
|
formData.append('challenge_type', 'recovery')
|
||||||
|
|
||||||
|
return promisedRequest({
|
||||||
|
url: '/oauth/mfa/challenge'
|
||||||
|
method: 'POST',
|
||||||
|
formData,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { mapActions, mapState, mapStores } from 'pinia'
|
import { mapActions, mapState, mapStores } from 'pinia'
|
||||||
|
|
||||||
import mfaApi from '../../services/new_api/mfa.js'
|
import { verifyRecoveryCode } from 'src/api/mfa.js'
|
||||||
|
|
||||||
import { useAuthFlowStore } from 'src/stores/auth_flow.js'
|
import { useAuthFlowStore } from 'src/stores/auth_flow.js'
|
||||||
import { useInstanceStore } from 'src/stores/instance.js'
|
import { useInstanceStore } from 'src/stores/instance.js'
|
||||||
|
|
@ -43,18 +43,18 @@ export default {
|
||||||
code: this.code,
|
code: this.code,
|
||||||
}
|
}
|
||||||
|
|
||||||
mfaApi.verifyRecoveryCode(data).then((result) => {
|
verifyRecoveryCode(data)
|
||||||
if (result.error) {
|
.then((result) => {
|
||||||
this.error = result.error
|
this.login(result).then(() => {
|
||||||
|
this.$router.push({ name: 'friends' })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
this.error = error
|
||||||
this.code = null
|
this.code = null
|
||||||
this.focusOnCodeInput()
|
this.focusOnCodeInput()
|
||||||
return
|
return
|
||||||
}
|
|
||||||
|
|
||||||
this.login(result).then(() => {
|
|
||||||
this.$router.push({ name: 'friends' })
|
|
||||||
})
|
})
|
||||||
})
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { mapActions, mapState, mapStores } from 'pinia'
|
import { mapActions, mapState, mapStores } from 'pinia'
|
||||||
|
|
||||||
import mfaApi from '../../services/new_api/mfa.js'
|
import { verifyOTPCode } from 'src/api/mfa.js'
|
||||||
|
|
||||||
import { useAuthFlowStore } from 'src/stores/auth_flow.js'
|
import { useAuthFlowStore } from 'src/stores/auth_flow.js'
|
||||||
import { useInstanceStore } from 'src/stores/instance.js'
|
import { useInstanceStore } from 'src/stores/instance.js'
|
||||||
|
|
@ -46,18 +46,18 @@ export default {
|
||||||
code: this.code,
|
code: this.code,
|
||||||
}
|
}
|
||||||
|
|
||||||
mfaApi.verifyOTPCode(data).then((result) => {
|
verifyOTPCode(data)
|
||||||
if (result.error) {
|
.then(({ data: result }) => {
|
||||||
this.error = result.error
|
this.login(result).then(() => {
|
||||||
|
this.$router.push({ name: 'friends' })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
this.error = error
|
||||||
this.code = null
|
this.code = null
|
||||||
this.focusOnCodeInput()
|
this.focusOnCodeInput()
|
||||||
return
|
return
|
||||||
}
|
|
||||||
|
|
||||||
this.login(result).then(() => {
|
|
||||||
this.$router.push({ name: 'friends' })
|
|
||||||
})
|
})
|
||||||
})
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,54 +0,0 @@
|
||||||
const verifyOTPCode = ({
|
|
||||||
clientId,
|
|
||||||
clientSecret,
|
|
||||||
instance,
|
|
||||||
mfaToken,
|
|
||||||
code,
|
|
||||||
}) => {
|
|
||||||
const url = `${instance}/oauth/mfa/challenge`
|
|
||||||
const form = new window.FormData()
|
|
||||||
|
|
||||||
form.append('client_id', clientId)
|
|
||||||
form.append('client_secret', clientSecret)
|
|
||||||
form.append('mfa_token', mfaToken)
|
|
||||||
form.append('code', code)
|
|
||||||
form.append('challenge_type', 'totp')
|
|
||||||
|
|
||||||
return window
|
|
||||||
.fetch(url, {
|
|
||||||
method: 'POST',
|
|
||||||
body: form,
|
|
||||||
})
|
|
||||||
.then((data) => data.json())
|
|
||||||
}
|
|
||||||
|
|
||||||
const verifyRecoveryCode = ({
|
|
||||||
clientId,
|
|
||||||
clientSecret,
|
|
||||||
instance,
|
|
||||||
mfaToken,
|
|
||||||
code,
|
|
||||||
}) => {
|
|
||||||
const url = `${instance}/oauth/mfa/challenge`
|
|
||||||
const form = new window.FormData()
|
|
||||||
|
|
||||||
form.append('client_id', clientId)
|
|
||||||
form.append('client_secret', clientSecret)
|
|
||||||
form.append('mfa_token', mfaToken)
|
|
||||||
form.append('code', code)
|
|
||||||
form.append('challenge_type', 'recovery')
|
|
||||||
|
|
||||||
return window
|
|
||||||
.fetch(url, {
|
|
||||||
method: 'POST',
|
|
||||||
body: form,
|
|
||||||
})
|
|
||||||
.then((data) => data.json())
|
|
||||||
}
|
|
||||||
|
|
||||||
const mfa = {
|
|
||||||
verifyOTPCode,
|
|
||||||
verifyRecoveryCode,
|
|
||||||
}
|
|
||||||
|
|
||||||
export default mfa
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue