mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-04 05:26:11 +00:00
Rename API token mentions to access token
This commit is contained in:
@@ -108,7 +108,7 @@ export const getAzureDevopsConnection = async (
|
|||||||
if (!("accessToken" in credentials)) {
|
if (!("accessToken" in credentials)) {
|
||||||
throw new BadRequestError({ message: "Invalid API token credentials" });
|
throw new BadRequestError({ message: "Invalid API token credentials" });
|
||||||
}
|
}
|
||||||
// For API token, return the basic auth token directly
|
// For access token, return the basic auth token directly
|
||||||
return credentials.accessToken;
|
return credentials.accessToken;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -189,16 +189,16 @@ export const validateAzureDevOpsConnectionCredentials = async (config: TAzureDev
|
|||||||
};
|
};
|
||||||
|
|
||||||
case AzureDevOpsConnectionMethod.AccessToken:
|
case AzureDevOpsConnectionMethod.AccessToken:
|
||||||
const apiTokenCredentials = inputCredentials as { accessToken: string; orgName?: string };
|
const accessTokenCredentials = inputCredentials as { accessToken: string; orgName?: string };
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (apiTokenCredentials.orgName) {
|
if (accessTokenCredentials.orgName) {
|
||||||
// Validate against specific organization
|
// Validate against specific organization
|
||||||
const response = await request.get(
|
const response = await request.get(
|
||||||
`${IntegrationUrls.AZURE_DEVOPS_API_URL}/${encodeURIComponent(apiTokenCredentials.orgName)}/_apis/projects?api-version=7.2-preview.2&$top=1`,
|
`${IntegrationUrls.AZURE_DEVOPS_API_URL}/${encodeURIComponent(accessTokenCredentials.orgName)}/_apis/projects?api-version=7.2-preview.2&$top=1`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Basic ${Buffer.from(`:${apiTokenCredentials.accessToken}`).toString("base64")}`
|
Authorization: `Basic ${Buffer.from(`:${accessTokenCredentials.accessToken}`).toString("base64")}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -210,8 +210,8 @@ export const validateAzureDevOpsConnectionCredentials = async (config: TAzureDev
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
accessToken: apiTokenCredentials.accessToken,
|
accessToken: accessTokenCredentials.accessToken,
|
||||||
orgName: apiTokenCredentials.orgName
|
orgName: accessTokenCredentials.orgName
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// Validate via profile and discover organizations
|
// Validate via profile and discover organizations
|
||||||
@@ -219,7 +219,7 @@ export const validateAzureDevOpsConnectionCredentials = async (config: TAzureDev
|
|||||||
`https://app.vssps.visualstudio.com/_apis/profile/profiles/me?api-version=7.1`,
|
`https://app.vssps.visualstudio.com/_apis/profile/profiles/me?api-version=7.1`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Basic ${Buffer.from(`:${apiTokenCredentials.accessToken}`).toString("base64")}`
|
Authorization: `Basic ${Buffer.from(`:${accessTokenCredentials.accessToken}`).toString("base64")}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -230,7 +230,7 @@ export const validateAzureDevOpsConnectionCredentials = async (config: TAzureDev
|
|||||||
value: Array<{ accountId: string; accountName: string; accountUri: string }>;
|
value: Array<{ accountId: string; accountName: string; accountUri: string }>;
|
||||||
}>(`https://app.vssps.visualstudio.com/_apis/accounts?api-version=7.1`, {
|
}>(`https://app.vssps.visualstudio.com/_apis/accounts?api-version=7.1`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Basic ${Buffer.from(`:${apiTokenCredentials.accessToken}`).toString("base64")}`
|
Authorization: `Basic ${Buffer.from(`:${accessTokenCredentials.accessToken}`).toString("base64")}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
organizations = orgsResponse.data.value || [];
|
organizations = orgsResponse.data.value || [];
|
||||||
@@ -239,7 +239,7 @@ export const validateAzureDevOpsConnectionCredentials = async (config: TAzureDev
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
accessToken: apiTokenCredentials.accessToken,
|
accessToken: accessTokenCredentials.accessToken,
|
||||||
userDisplayName: profileResponse.data.displayName,
|
userDisplayName: profileResponse.data.displayName,
|
||||||
organizations: organizations.map((org) => ({
|
organizations: organizations.map((org) => ({
|
||||||
accountId: org.accountId,
|
accountId: org.accountId,
|
||||||
@@ -249,9 +249,9 @@ export const validateAzureDevOpsConnectionCredentials = async (config: TAzureDev
|
|||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof AxiosError) {
|
if (error instanceof AxiosError) {
|
||||||
const errorMessage = apiTokenCredentials.orgName
|
const errorMessage = accessTokenCredentials.orgName
|
||||||
? // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
? // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||||
`Failed to validate API token for organization '${apiTokenCredentials.orgName}': ${error.response?.data?.message || error.message}`
|
`Failed to validate access token for organization '${accessTokenCredentials.orgName}': ${error.response?.data?.message || error.message}`
|
||||||
: `Invalid Azure DevOps Personal Access Token: ${error.response?.status === 401 ? "Token is invalid or expired" : error.message}`;
|
: `Invalid Azure DevOps Personal Access Token: ${error.response?.status === 401 ? "Token is invalid or expired" : error.message}`;
|
||||||
|
|
||||||
throw new BadRequestError({ message: errorMessage });
|
throw new BadRequestError({ message: errorMessage });
|
||||||
|
|||||||
@@ -28,12 +28,12 @@ export const AzureDevOpsConnectionOAuthOutputCredentialsSchema = z.object({
|
|||||||
expiresAt: z.number()
|
expiresAt: z.number()
|
||||||
});
|
});
|
||||||
|
|
||||||
export const AzureDevOpsConnectionApiTokenInputCredentialsSchema = z.object({
|
export const AzureDevOpsConnectionAccessTokenInputCredentialsSchema = z.object({
|
||||||
accessToken: z.string().trim().min(1, "Access Token required"),
|
accessToken: z.string().trim().min(1, "Access Token required"),
|
||||||
orgName: z.string().trim().min(1, "Organization name required")
|
orgName: z.string().trim().min(1, "Organization name required")
|
||||||
});
|
});
|
||||||
|
|
||||||
export const AzureDevOpsConnectionApiTokenOutputCredentialsSchema = z.object({
|
export const AzureDevOpsConnectionAccessTokenOutputCredentialsSchema = z.object({
|
||||||
accessToken: z.string(),
|
accessToken: z.string(),
|
||||||
orgName: z.string()
|
orgName: z.string()
|
||||||
});
|
});
|
||||||
@@ -51,7 +51,7 @@ export const ValidateAzureDevOpsConnectionCredentialsSchema = z.discriminatedUni
|
|||||||
method: z
|
method: z
|
||||||
.literal(AzureDevOpsConnectionMethod.AccessToken)
|
.literal(AzureDevOpsConnectionMethod.AccessToken)
|
||||||
.describe(AppConnections.CREATE(AppConnection.AzureDevOps).method),
|
.describe(AppConnections.CREATE(AppConnection.AzureDevOps).method),
|
||||||
credentials: AzureDevOpsConnectionApiTokenInputCredentialsSchema.describe(
|
credentials: AzureDevOpsConnectionAccessTokenInputCredentialsSchema.describe(
|
||||||
AppConnections.CREATE(AppConnection.AzureDevOps).credentials
|
AppConnections.CREATE(AppConnection.AzureDevOps).credentials
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -64,7 +64,7 @@ export const CreateAzureDevOpsConnectionSchema = ValidateAzureDevOpsConnectionCr
|
|||||||
export const UpdateAzureDevOpsConnectionSchema = z
|
export const UpdateAzureDevOpsConnectionSchema = z
|
||||||
.object({
|
.object({
|
||||||
credentials: z
|
credentials: z
|
||||||
.union([AzureDevOpsConnectionOAuthInputCredentialsSchema, AzureDevOpsConnectionApiTokenInputCredentialsSchema])
|
.union([AzureDevOpsConnectionOAuthInputCredentialsSchema, AzureDevOpsConnectionAccessTokenInputCredentialsSchema])
|
||||||
.optional()
|
.optional()
|
||||||
.describe(AppConnections.UPDATE(AppConnection.AzureDevOps).credentials)
|
.describe(AppConnections.UPDATE(AppConnection.AzureDevOps).credentials)
|
||||||
})
|
})
|
||||||
@@ -83,7 +83,7 @@ export const AzureDevOpsConnectionSchema = z.intersection(
|
|||||||
}),
|
}),
|
||||||
z.object({
|
z.object({
|
||||||
method: z.literal(AzureDevOpsConnectionMethod.AccessToken),
|
method: z.literal(AzureDevOpsConnectionMethod.AccessToken),
|
||||||
credentials: AzureDevOpsConnectionApiTokenOutputCredentialsSchema
|
credentials: AzureDevOpsConnectionAccessTokenOutputCredentialsSchema
|
||||||
})
|
})
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
@@ -98,7 +98,7 @@ export const SanitizedAzureDevOpsConnectionSchema = z.discriminatedUnion("method
|
|||||||
}),
|
}),
|
||||||
BaseAzureDevOpsConnectionSchema.extend({
|
BaseAzureDevOpsConnectionSchema.extend({
|
||||||
method: z.literal(AzureDevOpsConnectionMethod.AccessToken),
|
method: z.literal(AzureDevOpsConnectionMethod.AccessToken),
|
||||||
credentials: AzureDevOpsConnectionApiTokenOutputCredentialsSchema.pick({
|
credentials: AzureDevOpsConnectionAccessTokenOutputCredentialsSchema.pick({
|
||||||
orgName: true
|
orgName: true
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ const getAuthHeaders = (appConnection: TAzureDevOpsConnection, accessToken: stri
|
|||||||
Accept: "application/json"
|
Accept: "application/json"
|
||||||
};
|
};
|
||||||
case AzureDevOpsConnectionMethod.AccessToken:
|
case AzureDevOpsConnectionMethod.AccessToken:
|
||||||
// For API token, create Basic auth header
|
// For access token, create Basic auth header
|
||||||
const basicAuthToken = Buffer.from(`user:${accessToken}`).toString("base64");
|
const basicAuthToken = Buffer.from(`user:${accessToken}`).toString("base64");
|
||||||
return {
|
return {
|
||||||
Authorization: `Basic ${basicAuthToken}`,
|
Authorization: `Basic ${basicAuthToken}`,
|
||||||
@@ -64,7 +64,7 @@ const listAzureDevOpsProjects = async (
|
|||||||
): Promise<TAzureDevOpsProject[]> => {
|
): Promise<TAzureDevOpsProject[]> => {
|
||||||
const accessToken = await getAzureDevopsConnection(appConnection.id, appConnectionDAL, kmsService);
|
const accessToken = await getAzureDevopsConnection(appConnection.id, appConnectionDAL, kmsService);
|
||||||
|
|
||||||
// Both OAuth and API Token methods use organization name from credentials
|
// Both OAuth and access Token methods use organization name from credentials
|
||||||
const credentials = appConnection.credentials as { orgName: string };
|
const credentials = appConnection.credentials as { orgName: string };
|
||||||
const { orgName } = credentials;
|
const { orgName } = credentials;
|
||||||
|
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ import {
|
|||||||
} from "@app/hooks/api/auth/queries";
|
} from "@app/hooks/api/auth/queries";
|
||||||
import { MfaMethod } from "@app/hooks/api/auth/types";
|
import { MfaMethod } from "@app/hooks/api/auth/types";
|
||||||
import { fetchOrganizations } from "@app/hooks/api/organization/queries";
|
import { fetchOrganizations } from "@app/hooks/api/organization/queries";
|
||||||
import { ProjectType } from "@app/hooks/api/workspace/types";
|
|
||||||
import { isLoggedIn } from "@app/hooks/api/reactQuery";
|
import { isLoggedIn } from "@app/hooks/api/reactQuery";
|
||||||
|
import { ProjectType } from "@app/hooks/api/workspace/types";
|
||||||
|
|
||||||
// eslint-disable-next-line new-cap
|
// eslint-disable-next-line new-cap
|
||||||
const client = new jsrp.client();
|
const client = new jsrp.client();
|
||||||
|
|||||||
+5
-5
@@ -21,11 +21,11 @@ import {
|
|||||||
GenericAppConnectionsFields
|
GenericAppConnectionsFields
|
||||||
} from "./GenericAppConnectionFields";
|
} from "./GenericAppConnectionFields";
|
||||||
|
|
||||||
type ApiTokenForm = z.infer<typeof apiTokenSchema>;
|
type AccessTokenForm = z.infer<typeof accessTokenSchema>;
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
appConnection?: TAzureDevOpsConnection;
|
appConnection?: TAzureDevOpsConnection;
|
||||||
onSubmit: (formData: ApiTokenForm) => Promise<void>;
|
onSubmit: (formData: AccessTokenForm) => Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Base schema with common fields
|
// Base schema with common fields
|
||||||
@@ -41,7 +41,7 @@ const oauthSchema = baseSchema.extend({
|
|||||||
orgName: z.string().trim().min(1, "Organization name is required")
|
orgName: z.string().trim().min(1, "Organization name is required")
|
||||||
});
|
});
|
||||||
|
|
||||||
const apiTokenSchema = baseSchema.extend({
|
const accessTokenSchema = baseSchema.extend({
|
||||||
method: z.literal(AzureDevOpsConnectionMethod.AccessToken),
|
method: z.literal(AzureDevOpsConnectionMethod.AccessToken),
|
||||||
credentials: z.object({
|
credentials: z.object({
|
||||||
accessToken: z.string().trim().min(1, "Access Token is required"),
|
accessToken: z.string().trim().min(1, "Access Token is required"),
|
||||||
@@ -50,7 +50,7 @@ const apiTokenSchema = baseSchema.extend({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Union schema
|
// Union schema
|
||||||
const formSchema = z.discriminatedUnion("method", [oauthSchema, apiTokenSchema]);
|
const formSchema = z.discriminatedUnion("method", [oauthSchema, accessTokenSchema]);
|
||||||
|
|
||||||
type FormData = z.infer<typeof formSchema>;
|
type FormData = z.infer<typeof formSchema>;
|
||||||
|
|
||||||
@@ -230,7 +230,7 @@ export const AzureDevOpsConnectionForm = ({ appConnection, onSubmit }: Props) =>
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* API Token-specific fields */}
|
{/* Access Token-specific fields */}
|
||||||
{selectedMethod === AzureDevOpsConnectionMethod.AccessToken && (
|
{selectedMethod === AzureDevOpsConnectionMethod.AccessToken && (
|
||||||
<>
|
<>
|
||||||
<Controller
|
<Controller
|
||||||
|
|||||||
+3
-3
@@ -48,14 +48,14 @@ type OAuthCredentials = Extract<
|
|||||||
TAzureDevOpsConnection,
|
TAzureDevOpsConnection,
|
||||||
{ method: AzureDevOpsConnectionMethod.OAuth }
|
{ method: AzureDevOpsConnectionMethod.OAuth }
|
||||||
>["credentials"];
|
>["credentials"];
|
||||||
type ApiTokenCredentials = Extract<
|
type AccessTokenCredentials = Extract<
|
||||||
TAzureDevOpsConnection,
|
TAzureDevOpsConnection,
|
||||||
{ method: AzureDevOpsConnectionMethod.AccessToken }
|
{ method: AzureDevOpsConnectionMethod.AccessToken }
|
||||||
>["credentials"];
|
>["credentials"];
|
||||||
|
|
||||||
type AzureDevOpsFormData = BaseFormData &
|
type AzureDevOpsFormData = BaseFormData &
|
||||||
Pick<TAzureDevOpsConnection, "name" | "method" | "description"> &
|
Pick<TAzureDevOpsConnection, "name" | "method" | "description"> &
|
||||||
(Pick<OAuthCredentials, "tenantId" | "orgName"> | Pick<ApiTokenCredentials, "orgName">);
|
(Pick<OAuthCredentials, "tenantId" | "orgName"> | Pick<AccessTokenCredentials, "orgName">);
|
||||||
|
|
||||||
type FormDataMap = {
|
type FormDataMap = {
|
||||||
[AppConnection.GitHub]: GithubFormData & { app: AppConnection.GitHub };
|
[AppConnection.GitHub]: GithubFormData & { app: AppConnection.GitHub };
|
||||||
@@ -287,7 +287,7 @@ export const OAuthCallbackPage = () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (!("tenantId" in formData)) {
|
if (!("tenantId" in formData)) {
|
||||||
throw new Error("Expected OAuth form data but got API token data");
|
throw new Error("Expected OAuth form data but got access token data");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connectionId) {
|
if (connectionId) {
|
||||||
|
|||||||
Reference in New Issue
Block a user