UNPKG

google-authenticator-util

Version:

Google authenticator tool for backend development / automation

97 lines (96 loc) 4.09 kB
import { gmail_v1 } from 'googleapis'; import { OAuth2Client } from 'googleapis-common'; import { BasicAuthentication, NewTokenAuthentication, TokenFileAuthentication, DebugOptions, Token } from './types'; export declare class GoogleAuthenticator { private clientId; private clientSecret; private isTokenGenerated; private authServer; private debugOptions; oAuth2Client: OAuth2Client; api: gmail_v1.Gmail; /** * Initializing the Google Authenticator object * @param authenticationOptions The parameters to configure the authentication to Google * @param authenticationOptions.clientId The authentication client ID * @param authenticationOptions.clientSecret The authentication client secret * @param debugOptions Optional. The parameters to configure the debug logging * @param debugOptions.debug Is debug enabled * @param debugOptions.debugger The debugger of the debug printing */ constructor(authenticationOptions: BasicAuthentication, debugOptions?: DebugOptions); /** * Authorizing a google account with a new token * @param options The new token authentication parameters * @param options.username Required. The gmail username * @param options.password Required. The gmail password * @param options.scope Required. The authentication scope * @param options.redirectURI Optional. The configuration of the redirect URI * @param options.tokenName Optional. The name of the token * @param options.tokenDirectory Optional. The directory of the token */ authorizeWithNewToken(options: NewTokenAuthentication): Promise<OAuth2Client>; /** * Authorizing a google account with an existing token file * @param options The token file authentication parameters * @param options.name The name of the token * @param options.directory The directory of the token */ authorizeWithTokenFile(options: TokenFileAuthentication): Promise<OAuth2Client>; /** * Authorizing using a token * @param token The token */ authorizeWithToken(token: Token): Promise<OAuth2Client>; /** * Generating a new oAuth2 token * @param options The generate token parameters * @param options.username The email address username * @param options.password The email address password * @param options.scope The authorization scope * @param options.tokenName The name of the token * @param options.tokenDirectory The directory of the token * @param options.redirectURI The full redirectURI * @param options.redirectURIOptions The redirectURI options */ private generateToken; /** * Authenticating the first token using the google UI * @param authUrl The authentication URL * @param username The email address username * @param password The email address password */ private authenticateToken; /** * Configurating the Google Authenticator class properties * @param options Required. The configuration options * @param username Required. The gmail username * @param password Required. The gmail password * @param scope Required. The authentication scope * @param redirectURI Optional. The configuration of the redirect URI * @param tokenName Optional. The name of the token * @param tokenDirectory Optional. The directory of the token */ private configure; /** * Retrieving a token * @param code The code of the authentication * @param options The options of token generation */ private retrieveToken; /** * Printing a message based on configured logger * @param message The printed message */ private debug; /** * Creating the token's directory * @param directory The directory to verify */ private createDirectory; /** * Sleeping for X seconds in the code * @param seconds The sleep seconds */ private sleep; }