mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-14 16:40:30 +00:00
Merge pull request #3797 from Infisical/ENG-2690
feat: Lower token lifetime to 1 day (refresh 14 days) and fix CLI refresh token functionality
This commit is contained in:
@@ -16,7 +16,7 @@ export interface IsCliLoginSuccessful {
|
||||
loginResponse?: {
|
||||
email: string;
|
||||
privateKey: string;
|
||||
JTWToken: string;
|
||||
JWTToken: string;
|
||||
};
|
||||
success: boolean;
|
||||
}
|
||||
@@ -131,7 +131,7 @@ const attemptLogin = async ({
|
||||
loginResponse: {
|
||||
email,
|
||||
privateKey,
|
||||
JTWToken: token
|
||||
JWTToken: token
|
||||
},
|
||||
success: true
|
||||
});
|
||||
|
||||
@@ -14,7 +14,7 @@ interface IsMfaLoginSuccessful {
|
||||
success: boolean;
|
||||
loginResponse: {
|
||||
privateKey: string;
|
||||
JTWToken: string;
|
||||
JWTToken: string;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ const attemptLoginMfa = async ({
|
||||
success: true,
|
||||
loginResponse: {
|
||||
privateKey,
|
||||
JTWToken: token
|
||||
JWTToken: token
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
|
||||
@@ -73,6 +73,7 @@ export const selectOrganization = async (data: {
|
||||
}) => {
|
||||
const { data: res } = await apiRequest.post<{
|
||||
token: string;
|
||||
refreshToken: string;
|
||||
isMfaEnabled: boolean;
|
||||
mfaMethod?: MfaMethod;
|
||||
}>("/api/v3/auth/select-organization", data);
|
||||
|
||||
@@ -76,7 +76,9 @@ export const PasswordStep = ({
|
||||
// case: organization ID is present from the provider auth token -- select the org and use the new jwt token in the CLI, then navigate to the org
|
||||
if (organizationId) {
|
||||
const finishWithOrgWorkflow = async () => {
|
||||
const { token, isMfaEnabled, mfaMethod } = await selectOrganization({ organizationId });
|
||||
const { token, isMfaEnabled, mfaMethod, refreshToken } = await selectOrganization({
|
||||
organizationId
|
||||
});
|
||||
|
||||
if (isMfaEnabled) {
|
||||
SecurityClient.setMfaToken(token);
|
||||
@@ -94,10 +96,11 @@ export const PasswordStep = ({
|
||||
const payload = {
|
||||
privateKey,
|
||||
email,
|
||||
JTWToken: token
|
||||
JWTToken: token,
|
||||
refreshToken
|
||||
};
|
||||
await instance.post(cliUrl, payload).catch(() => {
|
||||
// if error happens to communicate we set the token with an expiry in sessino storage
|
||||
// if error happens to communicate we set the token with an expiry in session storage
|
||||
// the cli-redirect page has logic to show this to user and ask them to paste it in terminal
|
||||
sessionStorage.setItem(
|
||||
SessionStorageKeys.CLI_TERMINAL_TOKEN,
|
||||
@@ -187,7 +190,7 @@ export const PasswordStep = ({
|
||||
// case: organization ID is present from the provider auth token -- select the org and use the new jwt token in the CLI, then navigate to the org
|
||||
if (organizationId) {
|
||||
const finishWithOrgWorkflow = async () => {
|
||||
const { token, isMfaEnabled, mfaMethod } = await selectOrganization({
|
||||
const { token, isMfaEnabled, mfaMethod, refreshToken } = await selectOrganization({
|
||||
organizationId
|
||||
});
|
||||
|
||||
@@ -206,10 +209,11 @@ export const PasswordStep = ({
|
||||
const instance = axios.create();
|
||||
const payload = {
|
||||
...isCliLoginSuccessful.loginResponse,
|
||||
JTWToken: token
|
||||
JWTToken: token,
|
||||
refreshToken
|
||||
};
|
||||
await instance.post(cliUrl, payload).catch(() => {
|
||||
// if error happens to communicate we set the token with an expiry in sessino storage
|
||||
// if error happens to communicate we set the token with an expiry in session storage
|
||||
// the cli-redirect page has logic to show this to user and ask them to paste it in terminal
|
||||
sessionStorage.setItem(
|
||||
SessionStorageKeys.CLI_TERMINAL_TOKEN,
|
||||
|
||||
@@ -112,7 +112,7 @@ export const SelectOrganizationSection = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
const { token, isMfaEnabled, mfaMethod } = await selectOrg
|
||||
const { token, isMfaEnabled, mfaMethod, refreshToken } = await selectOrg
|
||||
.mutateAsync({
|
||||
organizationId: organization.id,
|
||||
userAgent: callbackPort ? UserAgentType.CLI : undefined
|
||||
@@ -149,15 +149,16 @@ export const SelectOrganizationSection = () => {
|
||||
}
|
||||
|
||||
const payload = {
|
||||
JTWToken: token,
|
||||
JWTToken: token,
|
||||
email: user?.email,
|
||||
privateKey
|
||||
privateKey,
|
||||
refreshToken
|
||||
} as IsCliLoginSuccessful["loginResponse"];
|
||||
|
||||
// send request to server endpoint
|
||||
const instance = axios.create();
|
||||
await instance.post(`http://127.0.0.1:${callbackPort}/`, payload).catch(() => {
|
||||
// if error happens to communicate we set the token with an expiry in sessino storage
|
||||
// if error happens to communicate we set the token with an expiry in session storage
|
||||
// the cli-redirect page has logic to show this to user and ask them to paste it in terminal
|
||||
sessionStorage.setItem(
|
||||
SessionStorageKeys.CLI_TERMINAL_TOKEN,
|
||||
|
||||
Reference in New Issue
Block a user