token_auth
Validate and manage authentication tokens for secure API access on CyberMCP. Ensure token integrity, type, and expiration for enhanced security testing.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expires_in | No | Token expiration time in seconds | |
| refresh_token | No | Refresh token (if available) | |
| token | Yes | Authentication token | |
| token_type | No | Token type (Bearer, JWT, etc.) | Bearer |
Implementation Reference
- src/tools/authentication.ts:52-80 (handler)The handler function that executes the token_auth tool logic. It retrieves AuthManager instance, calls setTokenAuth with provided credentials, and returns success or error message.async ({ token, token_type, refresh_token, expires_in }) => { try { const authManager = AuthManager.getInstance(); const authState = await authManager.setTokenAuth({ token, tokenType: token_type, refreshToken: refresh_token, expiresIn: expires_in, }); return { content: [ { type: "text", text: `Successfully set Token authentication\nAuthentication type: ${authState.type}\nToken type: ${token_type}\nHeader: Authorization: ${token_type} ***\n${authState.tokenExpiry ? `Token expires: ${authState.tokenExpiry.toISOString()}` : ''}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error setting Token authentication: ${(error as Error).message}`, }, ], }; } }
- src/tools/authentication.ts:46-51 (schema)Zod schema defining the input parameters for the token_auth tool.{ token: z.string().describe("Authentication token"), token_type: z.string().default("Bearer").describe("Token type (Bearer, JWT, etc.)"), refresh_token: z.string().optional().describe("Refresh token (if available)"), expires_in: z.number().optional().describe("Token expiration time in seconds"), },
- src/tools/authentication.ts:44-81 (registration)The server.tool call that registers the token_auth tool with its schema and handler function.server.tool( "token_auth", { token: z.string().describe("Authentication token"), token_type: z.string().default("Bearer").describe("Token type (Bearer, JWT, etc.)"), refresh_token: z.string().optional().describe("Refresh token (if available)"), expires_in: z.number().optional().describe("Token expiration time in seconds"), }, async ({ token, token_type, refresh_token, expires_in }) => { try { const authManager = AuthManager.getInstance(); const authState = await authManager.setTokenAuth({ token, tokenType: token_type, refreshToken: refresh_token, expiresIn: expires_in, }); return { content: [ { type: "text", text: `Successfully set Token authentication\nAuthentication type: ${authState.type}\nToken type: ${token_type}\nHeader: Authorization: ${token_type} ***\n${authState.tokenExpiry ? `Token expires: ${authState.tokenExpiry.toISOString()}` : ''}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error setting Token authentication: ${(error as Error).message}`, }, ], }; } } );
- src/utils/authManager.ts:88-109 (helper)Helper method in AuthManager class that sets the token authentication state, calculates expiry, and prepares authorization headers.public async setTokenAuth(credentials: TokenAuthCredentials): Promise<AuthState> { const { token, tokenType = 'Bearer', refreshToken, expiresIn } = credentials; // Calculate token expiry if expiresIn is provided let tokenExpiry: Date | undefined; if (expiresIn) { tokenExpiry = new Date(); tokenExpiry.setSeconds(tokenExpiry.getSeconds() + expiresIn); } this.authState = { type: 'token', token, refreshToken, tokenExpiry, headers: { 'Authorization': `${tokenType} ${token}` } }; return this.getAuthState(); }
- src/utils/authManager.ts:28-33 (schema)TypeScript interface defining the TokenAuthCredentials used by the token_auth handler and helper.export interface TokenAuthCredentials { token: string; tokenType?: string; refreshToken?: string; expiresIn?: number; }