mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-03 14:26:02 +00:00
added signup v3 endpoints and developed initial new signup flow
This commit is contained in:
@@ -12,7 +12,6 @@ import { getTranslatedStaticProps } from '@app/components/utilities/withTranslat
|
||||
import SecurityClient from '../utilities/SecurityClient';
|
||||
|
||||
export default function PasswordInputStep({
|
||||
userId,
|
||||
email,
|
||||
password,
|
||||
setPassword,
|
||||
@@ -20,7 +19,6 @@ export default function PasswordInputStep({
|
||||
setStep
|
||||
}: {
|
||||
email: string;
|
||||
userId: string;
|
||||
password: string;
|
||||
setPassword: (password: string) => void;
|
||||
setProviderAuthToken: (value: string) => void;
|
||||
@@ -34,13 +32,8 @@ export default function PasswordInputStep({
|
||||
|
||||
const handleLogin = async () => {
|
||||
try {
|
||||
if (!userId || !password) {
|
||||
return;
|
||||
}
|
||||
|
||||
setIsLoading(true);
|
||||
const isLoginSuccessful = await attemptLogin({
|
||||
userId,
|
||||
email,
|
||||
password
|
||||
});
|
||||
|
||||
@@ -32,6 +32,7 @@ interface UserInfoStepProps {
|
||||
setFirstName: (value: string) => void;
|
||||
lastName: string;
|
||||
setLastName: (value: string) => void;
|
||||
providerAuthToken?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,7 +56,8 @@ export default function UserInfoStep({
|
||||
firstName,
|
||||
setFirstName,
|
||||
lastName,
|
||||
setLastName
|
||||
setLastName,
|
||||
providerAuthToken,
|
||||
}: UserInfoStepProps): JSX.Element {
|
||||
const [firstNameError, setFirstNameError] = useState(false);
|
||||
const [lastNameError, setLastNameError] = useState(false);
|
||||
@@ -118,11 +120,11 @@ export default function UserInfoStep({
|
||||
parallelism: 1,
|
||||
hashLen: 32
|
||||
});
|
||||
|
||||
|
||||
if (!derivedKey) throw new Error('Failed to derive key from password');
|
||||
|
||||
const key = crypto.randomBytes(32);
|
||||
|
||||
|
||||
// create encrypted private key by encrypting the private
|
||||
// key with the symmetric key [key]
|
||||
const {
|
||||
@@ -133,7 +135,7 @@ export default function UserInfoStep({
|
||||
text: privateKey,
|
||||
secret: key
|
||||
});
|
||||
|
||||
|
||||
// create the protected key by encrypting the symmetric key
|
||||
// [key] with the derived key
|
||||
const {
|
||||
@@ -144,7 +146,7 @@ export default function UserInfoStep({
|
||||
text: key.toString('hex'),
|
||||
secret: Buffer.from(derivedKey.hash)
|
||||
});
|
||||
|
||||
|
||||
const response = await completeAccountInformationSignup({
|
||||
email,
|
||||
firstName,
|
||||
@@ -156,11 +158,12 @@ export default function UserInfoStep({
|
||||
encryptedPrivateKey,
|
||||
encryptedPrivateKeyIV,
|
||||
encryptedPrivateKeyTag,
|
||||
providerAuthToken,
|
||||
salt: result.salt,
|
||||
verifier: result.verifier,
|
||||
organizationName: `${firstName}'s organization`
|
||||
organizationName: `${firstName}'s organization`,
|
||||
});
|
||||
|
||||
|
||||
// unset signup JWT token and set JWT token
|
||||
SecurityClient.setSignupToken('');
|
||||
SecurityClient.setToken(response.token);
|
||||
|
||||
@@ -29,20 +29,17 @@ const attemptLogin = async (
|
||||
{
|
||||
email,
|
||||
password,
|
||||
userId,
|
||||
}: {
|
||||
email: string;
|
||||
userId?: string;
|
||||
password: string;
|
||||
}
|
||||
): Promise<IsLoginSuccessful> => {
|
||||
|
||||
const username = userId ?? email;
|
||||
const telemetry = new Telemetry().getInstance();
|
||||
return new Promise((resolve, reject) => {
|
||||
client.init(
|
||||
{
|
||||
username,
|
||||
username: email,
|
||||
password
|
||||
},
|
||||
async () => {
|
||||
@@ -51,7 +48,6 @@ const attemptLogin = async (
|
||||
const { serverPublicKey, salt } = await login1({
|
||||
email,
|
||||
clientPublicKey,
|
||||
userId,
|
||||
});
|
||||
|
||||
client.setSalt(salt);
|
||||
@@ -72,7 +68,6 @@ const attemptLogin = async (
|
||||
} = await login2(
|
||||
{
|
||||
email,
|
||||
userId,
|
||||
clientProof,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -31,10 +31,16 @@ export const useProviderAuth = () => {
|
||||
|
||||
window.addEventListener('storage', handleStorageChange);
|
||||
|
||||
if (providerAuthToken) {
|
||||
const { userId: resultUserId, email: resultEmail } = jwt_decode(providerAuthToken) as any;
|
||||
setEmail(resultEmail);
|
||||
setUserId(resultUserId);
|
||||
}
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('storage', handleStorageChange);
|
||||
};
|
||||
});
|
||||
}, []);
|
||||
|
||||
return {
|
||||
email,
|
||||
|
||||
@@ -8,6 +8,7 @@ interface Props {
|
||||
protectedKey: string;
|
||||
protectedKeyIV: string;
|
||||
protectedKeyTag: string;
|
||||
providerAuthToken?: string;
|
||||
publicKey: string;
|
||||
encryptedPrivateKey: string;
|
||||
encryptedPrivateKeyIV: string;
|
||||
@@ -49,9 +50,10 @@ const completeAccountInformationSignup = async ({
|
||||
encryptedPrivateKeyTag,
|
||||
salt,
|
||||
verifier,
|
||||
organizationName
|
||||
organizationName,
|
||||
providerAuthToken,
|
||||
}: Props) => {
|
||||
const { data } = await apiRequest.post('/api/v2/signup/complete-account/signup', {
|
||||
const { data } = await apiRequest.post('/api/v3/signup/complete-account/signup', {
|
||||
email,
|
||||
firstName,
|
||||
lastName,
|
||||
@@ -64,7 +66,8 @@ const completeAccountInformationSignup = async ({
|
||||
encryptedPrivateKeyTag,
|
||||
salt,
|
||||
verifier,
|
||||
organizationName
|
||||
organizationName,
|
||||
providerAuthToken,
|
||||
});
|
||||
|
||||
return data;
|
||||
|
||||
@@ -12,7 +12,6 @@ interface Login1 {
|
||||
const login1 = async (loginDetails: {
|
||||
email: string;
|
||||
clientPublicKey: string;
|
||||
userId?: string;
|
||||
}) => {
|
||||
const response = await fetch("/api/v2/auth/login1", {
|
||||
method: "POST",
|
||||
|
||||
@@ -20,7 +20,6 @@ interface Login2Response {
|
||||
const login2 = async (loginDetails: {
|
||||
email: string;
|
||||
clientProof: string;
|
||||
userId?: string;
|
||||
}) => {
|
||||
const response = await fetch('/api/v2/auth/login2', {
|
||||
method: 'POST',
|
||||
|
||||
@@ -25,7 +25,6 @@ export default function Login() {
|
||||
const [isLoginWithEmail, setIsLoginWithEmail] = useState(false);
|
||||
const {
|
||||
providerAuthToken,
|
||||
userId,
|
||||
email: providerEmail,
|
||||
setProviderAuthToken
|
||||
} = useProviderAuth();
|
||||
@@ -57,7 +56,6 @@ export default function Login() {
|
||||
if (providerAuthToken && step === 1) {
|
||||
return (
|
||||
<PasswordInputStep
|
||||
userId={userId}
|
||||
email={providerEmail}
|
||||
password={password}
|
||||
setPassword={setPassword}
|
||||
|
||||
@@ -35,7 +35,7 @@ export default function SignUp() {
|
||||
const { data: serverDetails } = useFetchServerStatus();
|
||||
const [isSignupWithEmail, setIsSignupWithEmail] = useState(false);
|
||||
const { t } = useTranslation();
|
||||
const { providerAuthToken } = useProviderAuth();
|
||||
const { email: providerEmail, providerAuthToken } = useProviderAuth();
|
||||
|
||||
if (providerAuthToken && step < 3) {
|
||||
setStep(3);
|
||||
@@ -99,7 +99,7 @@ export default function SignUp() {
|
||||
return (
|
||||
<>
|
||||
<button type='button' className='text-white' onClick={() => {
|
||||
window.open('/api/v1/auth/login/google')
|
||||
window.open('/api/v1/oauth/redirect/google')
|
||||
}}>
|
||||
Continue with Google
|
||||
</button>
|
||||
@@ -127,13 +127,14 @@ export default function SignUp() {
|
||||
return (
|
||||
<UserInfoStep
|
||||
incrementStep={incrementStep}
|
||||
email={email}
|
||||
email={email || providerEmail}
|
||||
password={password}
|
||||
setPassword={setPassword}
|
||||
firstName={firstName}
|
||||
setFirstName={setFirstName}
|
||||
lastName={lastName}
|
||||
setLastName={setLastName}
|
||||
providerAuthToken={providerAuthToken}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -142,7 +143,7 @@ export default function SignUp() {
|
||||
return (
|
||||
<DownloadBackupPDF
|
||||
incrementStep={incrementStep}
|
||||
email={email}
|
||||
email={email || providerEmail}
|
||||
password={password}
|
||||
name={`${firstName} ${lastName}`}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user