UNPKG

adk-typescript

Version:

TypeScript port of Google's Agent Development Kit (ADK)

117 lines (116 loc) 3.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BasicCredential = exports.BearerCredential = exports.ApiKeyCredential = exports.AuthCredentialTypes = void 0; /** * Enum for authentication credential types. */ var AuthCredentialTypes; (function (AuthCredentialTypes) { /** * API Key credential * https://swagger.io/docs/specification/v3_0/authentication/api-keys/ */ AuthCredentialTypes["API_KEY"] = "apiKey"; /** * Credentials for HTTP Auth schemes * https://www.iana.org/assignments/http-authschemes/http-authschemes.xhtml */ AuthCredentialTypes["HTTP"] = "http"; /** * OAuth2 credentials * https://swagger.io/docs/specification/v3_0/authentication/oauth2/ */ AuthCredentialTypes["OAUTH2"] = "oauth2"; /** * OpenID Connect credentials * https://swagger.io/docs/specification/v3_0/authentication/openid-connect-discovery/ */ AuthCredentialTypes["OPEN_ID_CONNECT"] = "openIdConnect"; /** * Service Account credentials * https://cloud.google.com/iam/docs/service-account-creds */ AuthCredentialTypes["SERVICE_ACCOUNT"] = "serviceAccount"; })(AuthCredentialTypes || (exports.AuthCredentialTypes = AuthCredentialTypes = {})); /** * API key credential implementation */ class ApiKeyCredential { /** * Initialize the API key credential * @param apiKey The API key value */ constructor(apiKey) { this.auth_type = AuthCredentialTypes.API_KEY; this.apiKey = apiKey; } /** * Convert to AuthCredential interface */ toAuthCredential() { return { auth_type: this.auth_type, api_key: this.apiKey }; } } exports.ApiKeyCredential = ApiKeyCredential; /** * Bearer token credential implementation */ class BearerCredential { /** * Initialize the bearer token credential * @param token The bearer token value */ constructor(token) { this.auth_type = AuthCredentialTypes.HTTP; this.access_token = token; } /** * Convert to AuthCredential interface */ toAuthCredential() { return { auth_type: this.auth_type, http: { scheme: 'bearer', credentials: { token: this.access_token } } }; } } exports.BearerCredential = BearerCredential; /** * Basic auth credential implementation */ class BasicCredential { /** * Initialize the basic auth credential * @param username The username * @param password The password */ constructor(username, password) { this.auth_type = AuthCredentialTypes.HTTP; this.username = username; this.password = password; } /** * Convert to AuthCredential interface */ toAuthCredential() { return { auth_type: this.auth_type, http: { scheme: 'basic', credentials: { username: this.username, password: this.password } } }; } } exports.BasicCredential = BasicCredential;