adk-typescript
Version:
TypeScript port of Google's Agent Development Kit (ADK)
69 lines (68 loc) • 2.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BasicAuthScheme = exports.BearerAuthScheme = exports.ApiKeyAuthScheme = void 0;
/**
* API key authentication scheme
*/
class ApiKeyAuthScheme {
/**
* Initializes the API key authentication scheme
* @param headerName The name of the header to include the API key in
*/
constructor(headerName = 'X-Api-Key') {
this.type = 'apiKey';
this.headerName = headerName;
}
/**
* Generate authentication headers for HTTP requests
* @param apiKey The API key to include in the headers
* @returns The headers to include in HTTP requests
*/
generateHeaders(apiKey) {
const headers = {};
headers[this.headerName] = apiKey;
return headers;
}
}
exports.ApiKeyAuthScheme = ApiKeyAuthScheme;
/**
* Bearer token authentication scheme
*/
class BearerAuthScheme {
constructor() {
this.type = 'bearer';
}
/**
* Generate authentication headers for HTTP requests
* @param token The bearer token to include in the headers
* @returns The headers to include in HTTP requests
*/
generateHeaders(token) {
return {
'Authorization': `Bearer ${token}`
};
}
}
exports.BearerAuthScheme = BearerAuthScheme;
/**
* Basic authentication scheme
*/
class BasicAuthScheme {
constructor() {
this.type = 'basic';
}
/**
* Generate authentication headers for HTTP requests
* @param credentials The credentials to use for authentication
* @param credentials.username The username for basic authentication
* @param credentials.password The password for basic authentication
* @returns The headers to include in HTTP requests
*/
generateHeaders(credentials) {
const auth = Buffer.from(`${credentials.username}:${credentials.password}`).toString('base64');
return {
'Authorization': `Basic ${auth}`
};
}
}
exports.BasicAuthScheme = BasicAuthScheme;