feat: omit pazuz-related headers when build target is lamassu
fix: rename headers to get up to standard feat: pazuz user registration links now contain schema identification param
This commit is contained in:
parent
6f285d30c5
commit
eb18440320
5 changed files with 92 additions and 35 deletions
|
|
@ -2,6 +2,7 @@ import { useMutation, useLazyQuery } from '@apollo/react-hooks'
|
|||
import { makeStyles } from '@material-ui/core/styles'
|
||||
import base64 from 'base-64'
|
||||
import gql from 'graphql-tag'
|
||||
import * as R from 'ramda'
|
||||
import React, { useContext, useState } from 'react'
|
||||
import { useHistory } from 'react-router-dom'
|
||||
|
||||
|
|
@ -58,13 +59,18 @@ const Input2FAState = ({ state, dispatch }) => {
|
|||
const [input2FA, { error: mutationError }] = useMutation(INPUT_2FA, {
|
||||
onCompleted: ({ input2FA: success }) => {
|
||||
if (success) {
|
||||
return getUserData({
|
||||
const options = {
|
||||
context: {
|
||||
headers: {
|
||||
pazuz_operatoridentifier: base64.encode(state.clientField)
|
||||
'Pazuz-Operator-Identifier': base64.encode(state.clientField)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
return getUserData(
|
||||
process.env.REACT_APP_BUILD_TARGET === 'LAMASSU'
|
||||
? R.omit(['context'], options)
|
||||
: options
|
||||
)
|
||||
}
|
||||
return setInvalidToken(true)
|
||||
}
|
||||
|
|
@ -86,7 +92,7 @@ const Input2FAState = ({ state, dispatch }) => {
|
|||
return
|
||||
}
|
||||
|
||||
input2FA({
|
||||
const options = {
|
||||
variables: {
|
||||
username: state.clientField,
|
||||
password: state.passwordField,
|
||||
|
|
@ -95,10 +101,16 @@ const Input2FAState = ({ state, dispatch }) => {
|
|||
},
|
||||
context: {
|
||||
headers: {
|
||||
pazuz_operatoridentifier: base64.encode(state.clientField)
|
||||
'Pazuz-Operator-Identifier': base64.encode(state.clientField)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
input2FA(
|
||||
process.env.REACT_APP_BUILD_TARGET === 'LAMASSU'
|
||||
? R.omit(['context'], options)
|
||||
: options
|
||||
)
|
||||
}
|
||||
|
||||
const getErrorMsg = () => {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { makeStyles } from '@material-ui/core/styles'
|
|||
import base64 from 'base-64'
|
||||
import { Field, Form, Formik } from 'formik'
|
||||
import gql from 'graphql-tag'
|
||||
import * as R from 'ramda'
|
||||
import React from 'react'
|
||||
import * as Yup from 'yup'
|
||||
|
||||
|
|
@ -50,17 +51,22 @@ const LoginState = ({ state, dispatch }) => {
|
|||
const [login, { error: mutationError }] = useMutation(LOGIN)
|
||||
|
||||
const submitLogin = async (username, password, rememberMe) => {
|
||||
const { data: loginResponse } = await login({
|
||||
const options = {
|
||||
variables: {
|
||||
username,
|
||||
password
|
||||
},
|
||||
context: {
|
||||
headers: {
|
||||
pazuz_operatoridentifier: base64.encode(username)
|
||||
'Pazuz-Operator-Identifier': base64.encode(username)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
const { data: loginResponse } = await login(
|
||||
process.env.REACT_APP_BUILD_TARGET === 'LAMASSU'
|
||||
? R.omit(['context'], options)
|
||||
: options
|
||||
)
|
||||
|
||||
if (!loginResponse.login) return
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
import { useQuery, useMutation } from '@apollo/react-hooks'
|
||||
import { makeStyles, Grid } from '@material-ui/core'
|
||||
import Paper from '@material-ui/core/Paper'
|
||||
// import base64 from 'base-64'
|
||||
import { Field, Form, Formik } from 'formik'
|
||||
import gql from 'graphql-tag'
|
||||
import * as R from 'ramda'
|
||||
import React, { useReducer } from 'react'
|
||||
import { useLocation, useHistory } from 'react-router-dom'
|
||||
import * as Yup from 'yup'
|
||||
|
|
@ -91,10 +93,16 @@ const Register = () => {
|
|||
const classes = useStyles()
|
||||
const history = useHistory()
|
||||
const token = QueryParams().get('t')
|
||||
const identifier = QueryParams().get('id') ?? null
|
||||
|
||||
const [state, dispatch] = useReducer(reducer, initialState)
|
||||
|
||||
const { error: queryError, loading } = useQuery(VALIDATE_REGISTER_LINK, {
|
||||
const queryOptions = {
|
||||
context: {
|
||||
headers: {
|
||||
'Pazuz-Operator-Identifier': identifier
|
||||
}
|
||||
},
|
||||
variables: { token: token },
|
||||
onCompleted: ({ validateRegisterLink: info }) => {
|
||||
if (!info) {
|
||||
|
|
@ -114,7 +122,14 @@ const Register = () => {
|
|||
dispatch({
|
||||
type: 'failure'
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const { error: queryError, loading } = useQuery(
|
||||
VALIDATE_REGISTER_LINK,
|
||||
process.env.REACT_APP_BUILD_TARGET === 'LAMASSU'
|
||||
? R.omit(['context'], queryOptions)
|
||||
: queryOptions
|
||||
)
|
||||
|
||||
const [register, { error: mutationError }] = useMutation(REGISTER, {
|
||||
onCompleted: ({ register: success }) => {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { makeStyles } from '@material-ui/core/styles'
|
|||
import base64 from 'base-64'
|
||||
import gql from 'graphql-tag'
|
||||
import QRCode from 'qrcode.react'
|
||||
import * as R from 'ramda'
|
||||
import React, { useContext, useState } from 'react'
|
||||
import { useHistory } from 'react-router-dom'
|
||||
|
||||
|
|
@ -68,18 +69,39 @@ const Setup2FAState = ({ state, dispatch }) => {
|
|||
setInvalidToken(false)
|
||||
}
|
||||
|
||||
const { error: queryError } = useQuery(GET_2FA_SECRET, {
|
||||
const queryOptions = {
|
||||
variables: { username: state.clientField, password: state.passwordField },
|
||||
context: {
|
||||
headers: {
|
||||
pazuz_operatoridentifier: base64.encode(state.clientField)
|
||||
'Pazuz-Operator-Identifier': base64.encode(state.clientField)
|
||||
}
|
||||
},
|
||||
onCompleted: ({ get2FASecret }) => {
|
||||
setSecret(get2FASecret.secret)
|
||||
setOtpauth(get2FASecret.otpauth)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const mutationOptions = {
|
||||
variables: {
|
||||
username: state.clientField,
|
||||
password: state.passwordField,
|
||||
rememberMe: state.rememberMeField,
|
||||
codeConfirmation: twoFAConfirmation
|
||||
},
|
||||
context: {
|
||||
headers: {
|
||||
'Pazuz-Operator-Identifier': base64.encode(state.clientField)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const { error: queryError } = useQuery(
|
||||
GET_2FA_SECRET,
|
||||
process.env.REACT_APP_BUILD_TARGET === 'LAMASSU'
|
||||
? R.omit(['context'], queryOptions)
|
||||
: queryOptions
|
||||
)
|
||||
|
||||
const [getUserData] = useLazyQuery(GET_USER_DATA, {
|
||||
onCompleted: ({ userData }) => {
|
||||
|
|
@ -90,14 +112,19 @@ const Setup2FAState = ({ state, dispatch }) => {
|
|||
|
||||
const [setup2FA, { error: mutationError }] = useMutation(SETUP_2FA, {
|
||||
onCompleted: ({ setup2FA: success }) => {
|
||||
success
|
||||
? getUserData({
|
||||
const options = {
|
||||
context: {
|
||||
headers: {
|
||||
pazuz_operatoridentifier: base64.encode(state.clientField)
|
||||
'Pazuz-Operator-Identifier': base64.encode(state.clientField)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
success
|
||||
? getUserData(
|
||||
process.env.REACT_APP_BUILD_TARGET === 'LAMASSU'
|
||||
? R.omit(['context'], options)
|
||||
: options
|
||||
)
|
||||
: setInvalidToken(true)
|
||||
}
|
||||
})
|
||||
|
|
@ -163,19 +190,11 @@ const Setup2FAState = ({ state, dispatch }) => {
|
|||
setInvalidToken(true)
|
||||
return
|
||||
}
|
||||
setup2FA({
|
||||
variables: {
|
||||
username: state.clientField,
|
||||
password: state.passwordField,
|
||||
rememberMe: state.rememberMeField,
|
||||
codeConfirmation: twoFAConfirmation
|
||||
},
|
||||
context: {
|
||||
headers: {
|
||||
pazuz_operatoridentifier: base64.encode(state.clientField)
|
||||
}
|
||||
}
|
||||
})
|
||||
setup2FA(
|
||||
process.env.REACT_APP_BUILD_TARGET === 'LAMASSU'
|
||||
? R.omit(['context'], mutationOptions)
|
||||
: mutationOptions
|
||||
)
|
||||
}}
|
||||
buttonClassName={classes.loginButton}>
|
||||
Done
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { useMutation } from '@apollo/react-hooks'
|
||||
import { makeStyles } from '@material-ui/core/styles'
|
||||
import base64 from 'base-64'
|
||||
import classnames from 'classnames'
|
||||
import { Field, Form, Formik } from 'formik'
|
||||
import gql from 'graphql-tag'
|
||||
|
|
@ -74,7 +75,11 @@ const CreateUserModal = ({ state, dispatch }) => {
|
|||
|
||||
const [createUser, { error }] = useMutation(CREATE_USER, {
|
||||
onCompleted: ({ createRegisterToken: token }) => {
|
||||
setCreateUserURL(urlResolver(`/register?t=${token.token}`))
|
||||
const queryParams =
|
||||
process.env.REACT_APP_BUILD_TARGET === 'LAMASSU'
|
||||
? `t=${token.token}`
|
||||
: `t=${token.token}&id=${base64.encode(usernameField)}`
|
||||
setCreateUserURL(urlResolver(`/register?${queryParams}`))
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue