Skip to main content
Glama

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
NameRequiredDescriptionDefault
expires_inNoToken expiration time in seconds
refresh_tokenNoRefresh token (if available)
tokenYesAuthentication token
token_typeNoToken type (Bearer, JWT, etc.)Bearer

Implementation Reference

  • 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}`, }, ], }; } }
  • 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"), },
  • 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}`, }, ], }; } } );
  • 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(); }
  • TypeScript interface defining the TokenAuthCredentials used by the token_auth handler and helper.
    export interface TokenAuthCredentials { token: string; tokenType?: string; refreshToken?: string; expiresIn?: number; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ricauts/CyberMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server