feat(core): Add Cargo and Composer registries with storage, auth and helpers
This commit is contained in:
@@ -270,6 +270,53 @@ export class AuthManager {
|
||||
this.tokenStore.delete(token);
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// COMPOSER TOKEN MANAGEMENT
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* Create a Composer token
|
||||
* @param userId - User ID
|
||||
* @param readonly - Whether the token is readonly
|
||||
* @returns Composer UUID token
|
||||
*/
|
||||
public async createComposerToken(userId: string, readonly: boolean = false): Promise<string> {
|
||||
const scopes = readonly ? ['composer:*:*:read'] : ['composer:*:*:*'];
|
||||
return this.createUuidToken(userId, 'composer', scopes, readonly);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a Composer token
|
||||
* @param token - Composer UUID token
|
||||
* @returns Auth token object or null
|
||||
*/
|
||||
public async validateComposerToken(token: string): Promise<IAuthToken | null> {
|
||||
if (!this.isValidUuid(token)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const authToken = this.tokenStore.get(token);
|
||||
if (!authToken || authToken.type !== 'composer') {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check expiration if set
|
||||
if (authToken.expiresAt && authToken.expiresAt < new Date()) {
|
||||
this.tokenStore.delete(token);
|
||||
return null;
|
||||
}
|
||||
|
||||
return authToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Revoke a Composer token
|
||||
* @param token - Composer UUID token
|
||||
*/
|
||||
public async revokeComposerToken(token: string): Promise<void> {
|
||||
this.tokenStore.delete(token);
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// UNIFIED AUTHENTICATION
|
||||
// ========================================================================
|
||||
@@ -284,7 +331,7 @@ export class AuthManager {
|
||||
tokenString: string,
|
||||
protocol?: TRegistryProtocol
|
||||
): Promise<IAuthToken | null> {
|
||||
// Try UUID-based tokens (NPM, Maven)
|
||||
// Try UUID-based tokens (NPM, Maven, Composer)
|
||||
if (this.isValidUuid(tokenString)) {
|
||||
// Try NPM token
|
||||
const npmToken = await this.validateNpmToken(tokenString);
|
||||
@@ -297,6 +344,12 @@ export class AuthManager {
|
||||
if (mavenToken && (!protocol || protocol === 'maven')) {
|
||||
return mavenToken;
|
||||
}
|
||||
|
||||
// Try Composer token
|
||||
const composerToken = await this.validateComposerToken(tokenString);
|
||||
if (composerToken && (!protocol || protocol === 'composer')) {
|
||||
return composerToken;
|
||||
}
|
||||
}
|
||||
|
||||
// Try OCI JWT
|
||||
|
||||
Reference in New Issue
Block a user