Identities and Access Control
Manage identity-based permissions for Git repositories.
Identities and Access Control
Freestyle uses identity-based access control for Git repositories. Create identities for your application users to grant them access to their repositories, or create separate identities for different purposes like CI/CD systems and team members.
Creating an Identity
sandboxes.createGitIdentity().then((identity) => {
console.log(identity.id);
});Managing Access Tokens
Each identity can have multiple access tokens for authentication.
Create a Token
sandboxes
.createGitAccessToken({
identityId: "identity-id",
})
.then((token) => {
console.log(token.value); // Store this securely
});List Tokens
sandboxes
.listGitAccessTokens({
identityId: "identity-id",
})
.then((tokens) => {
console.log(tokens);
});Revoke a Token
sandboxes
.revokeGitAccessToken({
identityId: "identity-id",
tokenId: "token-id",
})
.then(() => {
console.log("Token revoked");
});Managing Permissions
Grant identities different levels of access to repositories.
Grant Read Access
sandboxes
.grantGitPermission({
identityId: "identity-id",
repoId: "repo-id",
permission: "read",
})
.then(() => {
console.log("Read access granted");
});Grant Write Access
sandboxes
.grantGitPermission({
identityId: "identity-id",
repoId: "repo-id",
permission: "write",
})
.then(() => {
console.log("Write access granted");
});List Permissions
sandboxes
.listGitPermissions({
identityId: "identity-id",
})
.then((permissions) => {
console.log(permissions);
});Revoke Access
sandboxes
.revokeGitPermission({
identityId: "identity-id",
repoId: "repo-id",
})
.then(() => {
console.log("Access revoked");
});Example: Provisioning for Users
When a new user signs up, create an identity and grant them access to their repositories:
// Create identity for new user
const identity = await sandboxes.createGitIdentity();
// Create repository for the user
const repo = await sandboxes.createGitRepository({
name: `${username}-repo`,
});
// Grant write access to their repository
await sandboxes.grantGitPermission({
identityId: identity.id,
repoId: repo.repoId,
permission: "write",
});
// Create access token for the user
const token = await sandboxes.createGitAccessToken({
identityId: identity.id,
});
// Provide token to user for Git operations
return { identityId: identity.id, token: token.value };You can also create identities for CI/CD systems or other services that need repository access.