mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +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)) {
|
||||
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;
|
||||
|
||||
default:
|
||||
@@ -189,16 +189,16 @@ export const validateAzureDevOpsConnectionCredentials = async (config: TAzureDev
|
||||
};
|
||||
|
||||
case AzureDevOpsConnectionMethod.AccessToken:
|
||||
const apiTokenCredentials = inputCredentials as { accessToken: string; orgName?: string };
|
||||
const accessTokenCredentials = inputCredentials as { accessToken: string; orgName?: string };
|
||||
|
||||
try {
|
||||
if (apiTokenCredentials.orgName) {
|
||||
if (accessTokenCredentials.orgName) {
|
||||
// Validate against specific organization
|
||||
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: {
|
||||
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 {
|
||||
accessToken: apiTokenCredentials.accessToken,
|
||||
orgName: apiTokenCredentials.orgName
|
||||
accessToken: accessTokenCredentials.accessToken,
|
||||
orgName: accessTokenCredentials.orgName
|
||||
};
|
||||
}
|
||||
// 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`,
|
||||
{
|
||||
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 }>;
|
||||
}>(`https://app.vssps.visualstudio.com/_apis/accounts?api-version=7.1`, {
|
||||
headers: {
|
||||
Authorization: `Basic ${Buffer.from(`:${apiTokenCredentials.accessToken}`).toString("base64")}`
|
||||
Authorization: `Basic ${Buffer.from(`:${accessTokenCredentials.accessToken}`).toString("base64")}`
|
||||
}
|
||||
});
|
||||
organizations = orgsResponse.data.value || [];
|
||||
@@ -239,7 +239,7 @@ export const validateAzureDevOpsConnectionCredentials = async (config: TAzureDev
|
||||
}
|
||||
|
||||
return {
|
||||
accessToken: apiTokenCredentials.accessToken,
|
||||
accessToken: accessTokenCredentials.accessToken,
|
||||
userDisplayName: profileResponse.data.displayName,
|
||||
organizations: organizations.map((org) => ({
|
||||
accountId: org.accountId,
|
||||
@@ -249,9 +249,9 @@ export const validateAzureDevOpsConnectionCredentials = async (config: TAzureDev
|
||||
};
|
||||
} catch (error) {
|
||||
if (error instanceof AxiosError) {
|
||||
const errorMessage = apiTokenCredentials.orgName
|
||||
const errorMessage = accessTokenCredentials.orgName
|
||||
? // 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}`;
|
||||
|
||||
throw new BadRequestError({ message: errorMessage });
|
||||
|
||||
@@ -28,12 +28,12 @@ export const AzureDevOpsConnectionOAuthOutputCredentialsSchema = z.object({
|
||||
expiresAt: z.number()
|
||||
});
|
||||
|
||||
export const AzureDevOpsConnectionApiTokenInputCredentialsSchema = z.object({
|
||||
export const AzureDevOpsConnectionAccessTokenInputCredentialsSchema = z.object({
|
||||
accessToken: z.string().trim().min(1, "Access Token required"),
|
||||
orgName: z.string().trim().min(1, "Organization name required")
|
||||
});
|
||||
|
||||
export const AzureDevOpsConnectionApiTokenOutputCredentialsSchema = z.object({
|
||||
export const AzureDevOpsConnectionAccessTokenOutputCredentialsSchema = z.object({
|
||||
accessToken: z.string(),
|
||||
orgName: z.string()
|
||||
});
|
||||
@@ -51,7 +51,7 @@ export const ValidateAzureDevOpsConnectionCredentialsSchema = z.discriminatedUni
|
||||
method: z
|
||||
.literal(AzureDevOpsConnectionMethod.AccessToken)
|
||||
.describe(AppConnections.CREATE(AppConnection.AzureDevOps).method),
|
||||
credentials: AzureDevOpsConnectionApiTokenInputCredentialsSchema.describe(
|
||||
credentials: AzureDevOpsConnectionAccessTokenInputCredentialsSchema.describe(
|
||||
AppConnections.CREATE(AppConnection.AzureDevOps).credentials
|
||||
)
|
||||
})
|
||||
@@ -64,7 +64,7 @@ export const CreateAzureDevOpsConnectionSchema = ValidateAzureDevOpsConnectionCr
|
||||
export const UpdateAzureDevOpsConnectionSchema = z
|
||||
.object({
|
||||
credentials: z
|
||||
.union([AzureDevOpsConnectionOAuthInputCredentialsSchema, AzureDevOpsConnectionApiTokenInputCredentialsSchema])
|
||||
.union([AzureDevOpsConnectionOAuthInputCredentialsSchema, AzureDevOpsConnectionAccessTokenInputCredentialsSchema])
|
||||
.optional()
|
||||
.describe(AppConnections.UPDATE(AppConnection.AzureDevOps).credentials)
|
||||
})
|
||||
@@ -83,7 +83,7 @@ export const AzureDevOpsConnectionSchema = z.intersection(
|
||||
}),
|
||||
z.object({
|
||||
method: z.literal(AzureDevOpsConnectionMethod.AccessToken),
|
||||
credentials: AzureDevOpsConnectionApiTokenOutputCredentialsSchema
|
||||
credentials: AzureDevOpsConnectionAccessTokenOutputCredentialsSchema
|
||||
})
|
||||
])
|
||||
);
|
||||
@@ -98,7 +98,7 @@ export const SanitizedAzureDevOpsConnectionSchema = z.discriminatedUnion("method
|
||||
}),
|
||||
BaseAzureDevOpsConnectionSchema.extend({
|
||||
method: z.literal(AzureDevOpsConnectionMethod.AccessToken),
|
||||
credentials: AzureDevOpsConnectionApiTokenOutputCredentialsSchema.pick({
|
||||
credentials: AzureDevOpsConnectionAccessTokenOutputCredentialsSchema.pick({
|
||||
orgName: true
|
||||
})
|
||||
})
|
||||
|
||||
@@ -46,7 +46,7 @@ const getAuthHeaders = (appConnection: TAzureDevOpsConnection, accessToken: stri
|
||||
Accept: "application/json"
|
||||
};
|
||||
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");
|
||||
return {
|
||||
Authorization: `Basic ${basicAuthToken}`,
|
||||
@@ -64,7 +64,7 @@ const listAzureDevOpsProjects = async (
|
||||
): Promise<TAzureDevOpsProject[]> => {
|
||||
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 { orgName } = credentials;
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@ import {
|
||||
} from "@app/hooks/api/auth/queries";
|
||||
import { MfaMethod } from "@app/hooks/api/auth/types";
|
||||
import { fetchOrganizations } from "@app/hooks/api/organization/queries";
|
||||
import { ProjectType } from "@app/hooks/api/workspace/types";
|
||||
import { isLoggedIn } from "@app/hooks/api/reactQuery";
|
||||
import { ProjectType } from "@app/hooks/api/workspace/types";
|
||||
|
||||
// eslint-disable-next-line new-cap
|
||||
const client = new jsrp.client();
|
||||
|
||||
@@ -21,11 +21,11 @@ import {
|
||||
GenericAppConnectionsFields
|
||||
} from "./GenericAppConnectionFields";
|
||||
|
||||
type ApiTokenForm = z.infer<typeof apiTokenSchema>;
|
||||
type AccessTokenForm = z.infer<typeof accessTokenSchema>;
|
||||
|
||||
type Props = {
|
||||
appConnection?: TAzureDevOpsConnection;
|
||||
onSubmit: (formData: ApiTokenForm) => Promise<void>;
|
||||
onSubmit: (formData: AccessTokenForm) => Promise<void>;
|
||||
};
|
||||
|
||||
// Base schema with common fields
|
||||
@@ -41,7 +41,7 @@ const oauthSchema = baseSchema.extend({
|
||||
orgName: z.string().trim().min(1, "Organization name is required")
|
||||
});
|
||||
|
||||
const apiTokenSchema = baseSchema.extend({
|
||||
const accessTokenSchema = baseSchema.extend({
|
||||
method: z.literal(AzureDevOpsConnectionMethod.AccessToken),
|
||||
credentials: z.object({
|
||||
accessToken: z.string().trim().min(1, "Access Token is required"),
|
||||
@@ -50,7 +50,7 @@ const apiTokenSchema = baseSchema.extend({
|
||||
});
|
||||
|
||||
// Union schema
|
||||
const formSchema = z.discriminatedUnion("method", [oauthSchema, apiTokenSchema]);
|
||||
const formSchema = z.discriminatedUnion("method", [oauthSchema, accessTokenSchema]);
|
||||
|
||||
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 && (
|
||||
<>
|
||||
<Controller
|
||||
|
||||
@@ -48,14 +48,14 @@ type OAuthCredentials = Extract<
|
||||
TAzureDevOpsConnection,
|
||||
{ method: AzureDevOpsConnectionMethod.OAuth }
|
||||
>["credentials"];
|
||||
type ApiTokenCredentials = Extract<
|
||||
type AccessTokenCredentials = Extract<
|
||||
TAzureDevOpsConnection,
|
||||
{ method: AzureDevOpsConnectionMethod.AccessToken }
|
||||
>["credentials"];
|
||||
|
||||
type AzureDevOpsFormData = BaseFormData &
|
||||
Pick<TAzureDevOpsConnection, "name" | "method" | "description"> &
|
||||
(Pick<OAuthCredentials, "tenantId" | "orgName"> | Pick<ApiTokenCredentials, "orgName">);
|
||||
(Pick<OAuthCredentials, "tenantId" | "orgName"> | Pick<AccessTokenCredentials, "orgName">);
|
||||
|
||||
type FormDataMap = {
|
||||
[AppConnection.GitHub]: GithubFormData & { app: AppConnection.GitHub };
|
||||
@@ -287,7 +287,7 @@ export const OAuthCallbackPage = () => {
|
||||
|
||||
try {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user