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 { makeStyles } from '@material-ui/core/styles'
|
||||||
import base64 from 'base-64'
|
import base64 from 'base-64'
|
||||||
import gql from 'graphql-tag'
|
import gql from 'graphql-tag'
|
||||||
|
import * as R from 'ramda'
|
||||||
import React, { useContext, useState } from 'react'
|
import React, { useContext, useState } from 'react'
|
||||||
import { useHistory } from 'react-router-dom'
|
import { useHistory } from 'react-router-dom'
|
||||||
|
|
||||||
|
|
@ -58,13 +59,18 @@ const Input2FAState = ({ state, dispatch }) => {
|
||||||
const [input2FA, { error: mutationError }] = useMutation(INPUT_2FA, {
|
const [input2FA, { error: mutationError }] = useMutation(INPUT_2FA, {
|
||||||
onCompleted: ({ input2FA: success }) => {
|
onCompleted: ({ input2FA: success }) => {
|
||||||
if (success) {
|
if (success) {
|
||||||
return getUserData({
|
const options = {
|
||||||
context: {
|
context: {
|
||||||
headers: {
|
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)
|
return setInvalidToken(true)
|
||||||
}
|
}
|
||||||
|
|
@ -86,7 +92,7 @@ const Input2FAState = ({ state, dispatch }) => {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
input2FA({
|
const options = {
|
||||||
variables: {
|
variables: {
|
||||||
username: state.clientField,
|
username: state.clientField,
|
||||||
password: state.passwordField,
|
password: state.passwordField,
|
||||||
|
|
@ -95,10 +101,16 @@ const Input2FAState = ({ state, dispatch }) => {
|
||||||
},
|
},
|
||||||
context: {
|
context: {
|
||||||
headers: {
|
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 = () => {
|
const getErrorMsg = () => {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import { makeStyles } from '@material-ui/core/styles'
|
||||||
import base64 from 'base-64'
|
import base64 from 'base-64'
|
||||||
import { Field, Form, Formik } from 'formik'
|
import { Field, Form, Formik } from 'formik'
|
||||||
import gql from 'graphql-tag'
|
import gql from 'graphql-tag'
|
||||||
|
import * as R from 'ramda'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import * as Yup from 'yup'
|
import * as Yup from 'yup'
|
||||||
|
|
||||||
|
|
@ -50,17 +51,22 @@ const LoginState = ({ state, dispatch }) => {
|
||||||
const [login, { error: mutationError }] = useMutation(LOGIN)
|
const [login, { error: mutationError }] = useMutation(LOGIN)
|
||||||
|
|
||||||
const submitLogin = async (username, password, rememberMe) => {
|
const submitLogin = async (username, password, rememberMe) => {
|
||||||
const { data: loginResponse } = await login({
|
const options = {
|
||||||
variables: {
|
variables: {
|
||||||
username,
|
username,
|
||||||
password
|
password
|
||||||
},
|
},
|
||||||
context: {
|
context: {
|
||||||
headers: {
|
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
|
if (!loginResponse.login) return
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
import { useQuery, useMutation } from '@apollo/react-hooks'
|
import { useQuery, useMutation } from '@apollo/react-hooks'
|
||||||
import { makeStyles, Grid } from '@material-ui/core'
|
import { makeStyles, Grid } from '@material-ui/core'
|
||||||
import Paper from '@material-ui/core/Paper'
|
import Paper from '@material-ui/core/Paper'
|
||||||
|
// import base64 from 'base-64'
|
||||||
import { Field, Form, Formik } from 'formik'
|
import { Field, Form, Formik } from 'formik'
|
||||||
import gql from 'graphql-tag'
|
import gql from 'graphql-tag'
|
||||||
|
import * as R from 'ramda'
|
||||||
import React, { useReducer } from 'react'
|
import React, { useReducer } from 'react'
|
||||||
import { useLocation, useHistory } from 'react-router-dom'
|
import { useLocation, useHistory } from 'react-router-dom'
|
||||||
import * as Yup from 'yup'
|
import * as Yup from 'yup'
|
||||||
|
|
@ -91,10 +93,16 @@ const Register = () => {
|
||||||
const classes = useStyles()
|
const classes = useStyles()
|
||||||
const history = useHistory()
|
const history = useHistory()
|
||||||
const token = QueryParams().get('t')
|
const token = QueryParams().get('t')
|
||||||
|
const identifier = QueryParams().get('id') ?? null
|
||||||
|
|
||||||
const [state, dispatch] = useReducer(reducer, initialState)
|
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 },
|
variables: { token: token },
|
||||||
onCompleted: ({ validateRegisterLink: info }) => {
|
onCompleted: ({ validateRegisterLink: info }) => {
|
||||||
if (!info) {
|
if (!info) {
|
||||||
|
|
@ -114,7 +122,14 @@ const Register = () => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'failure'
|
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, {
|
const [register, { error: mutationError }] = useMutation(REGISTER, {
|
||||||
onCompleted: ({ register: success }) => {
|
onCompleted: ({ register: success }) => {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import { makeStyles } from '@material-ui/core/styles'
|
||||||
import base64 from 'base-64'
|
import base64 from 'base-64'
|
||||||
import gql from 'graphql-tag'
|
import gql from 'graphql-tag'
|
||||||
import QRCode from 'qrcode.react'
|
import QRCode from 'qrcode.react'
|
||||||
|
import * as R from 'ramda'
|
||||||
import React, { useContext, useState } from 'react'
|
import React, { useContext, useState } from 'react'
|
||||||
import { useHistory } from 'react-router-dom'
|
import { useHistory } from 'react-router-dom'
|
||||||
|
|
||||||
|
|
@ -68,18 +69,39 @@ const Setup2FAState = ({ state, dispatch }) => {
|
||||||
setInvalidToken(false)
|
setInvalidToken(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
const { error: queryError } = useQuery(GET_2FA_SECRET, {
|
const queryOptions = {
|
||||||
variables: { username: state.clientField, password: state.passwordField },
|
variables: { username: state.clientField, password: state.passwordField },
|
||||||
context: {
|
context: {
|
||||||
headers: {
|
headers: {
|
||||||
pazuz_operatoridentifier: base64.encode(state.clientField)
|
'Pazuz-Operator-Identifier': base64.encode(state.clientField)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onCompleted: ({ get2FASecret }) => {
|
onCompleted: ({ get2FASecret }) => {
|
||||||
setSecret(get2FASecret.secret)
|
setSecret(get2FASecret.secret)
|
||||||
setOtpauth(get2FASecret.otpauth)
|
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, {
|
const [getUserData] = useLazyQuery(GET_USER_DATA, {
|
||||||
onCompleted: ({ userData }) => {
|
onCompleted: ({ userData }) => {
|
||||||
|
|
@ -90,14 +112,19 @@ const Setup2FAState = ({ state, dispatch }) => {
|
||||||
|
|
||||||
const [setup2FA, { error: mutationError }] = useMutation(SETUP_2FA, {
|
const [setup2FA, { error: mutationError }] = useMutation(SETUP_2FA, {
|
||||||
onCompleted: ({ setup2FA: success }) => {
|
onCompleted: ({ setup2FA: success }) => {
|
||||||
|
const options = {
|
||||||
|
context: {
|
||||||
|
headers: {
|
||||||
|
'Pazuz-Operator-Identifier': base64.encode(state.clientField)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
success
|
success
|
||||||
? getUserData({
|
? getUserData(
|
||||||
context: {
|
process.env.REACT_APP_BUILD_TARGET === 'LAMASSU'
|
||||||
headers: {
|
? R.omit(['context'], options)
|
||||||
pazuz_operatoridentifier: base64.encode(state.clientField)
|
: options
|
||||||
}
|
)
|
||||||
}
|
|
||||||
})
|
|
||||||
: setInvalidToken(true)
|
: setInvalidToken(true)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -163,19 +190,11 @@ const Setup2FAState = ({ state, dispatch }) => {
|
||||||
setInvalidToken(true)
|
setInvalidToken(true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
setup2FA({
|
setup2FA(
|
||||||
variables: {
|
process.env.REACT_APP_BUILD_TARGET === 'LAMASSU'
|
||||||
username: state.clientField,
|
? R.omit(['context'], mutationOptions)
|
||||||
password: state.passwordField,
|
: mutationOptions
|
||||||
rememberMe: state.rememberMeField,
|
)
|
||||||
codeConfirmation: twoFAConfirmation
|
|
||||||
},
|
|
||||||
context: {
|
|
||||||
headers: {
|
|
||||||
pazuz_operatoridentifier: base64.encode(state.clientField)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}}
|
}}
|
||||||
buttonClassName={classes.loginButton}>
|
buttonClassName={classes.loginButton}>
|
||||||
Done
|
Done
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { useMutation } from '@apollo/react-hooks'
|
import { useMutation } from '@apollo/react-hooks'
|
||||||
import { makeStyles } from '@material-ui/core/styles'
|
import { makeStyles } from '@material-ui/core/styles'
|
||||||
|
import base64 from 'base-64'
|
||||||
import classnames from 'classnames'
|
import classnames from 'classnames'
|
||||||
import { Field, Form, Formik } from 'formik'
|
import { Field, Form, Formik } from 'formik'
|
||||||
import gql from 'graphql-tag'
|
import gql from 'graphql-tag'
|
||||||
|
|
@ -74,7 +75,11 @@ const CreateUserModal = ({ state, dispatch }) => {
|
||||||
|
|
||||||
const [createUser, { error }] = useMutation(CREATE_USER, {
|
const [createUser, { error }] = useMutation(CREATE_USER, {
|
||||||
onCompleted: ({ createRegisterToken: token }) => {
|
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