Options
All
  • Public
  • Public/Protected
  • All
Menu
name

ServiceAccount

classdesc

abstracted class to handle oauth2 service account authentication using jwt (json web token) method, should be passed as authClass to API class

see

oAuth2ServiceAccount

example

    var fs = require("fs");
    const creds = JSON.parse(fs.readFileSync("file", "utf8"));
    const authClass = new ServiceAccount(creds);
    const api = new API(authClass); // authClass is an instance of any Class from IAuthClass set

Hierarchy

  • ServiceAccount

Implements

Index

Constructors

constructor

Properties

Private JWTClient

JWTClient: any

Private googleAuth

googleAuth: any

Private token

token: IJWTToken | null
name

constructor

param

instance of any IAuthClass drived classes in ./auth-client directory

param

google authentication scopes

see

googleapis scopes

throws

errors from wrapped method GoogleAuth.JWT

see

GoogleAuth

Accessors

authClient

  • get authClient(): any
  • name

    authClient

    desc

    getter for the internal authClient class, which is JWTClient in ServiceAccount case

    example
    
        const authClass = new ServiceAccount(creds, google_auth_scopes);
        authClass.authorize((err, res) => {
            if (err)
                throw err;
            console.log(authClass.authClient);
        });
    

    Returns any

    JWTClient - holds the access token and request methods

Methods

authorize

  • authorize(callback?: Callback<any>): void
  • name

    authorize

    desc

    send credintials private key to google server and gets json access token object

    throws

    errors from wrapped method GoogleAuth.JWT.authorize

    see

    GoogleAuth

    example
    
        const authClass = new ServiceAccount(creds, google_auth_scopes);
        authClass.authorize((err, res) => {
            if (err)
                throw err;
            console.log(res);
        });
    

    Parameters

    • Default value callback: Callback<any> = utils.noop

    Returns void

    authClient - JWTClient, holds access token and request methods

ensureValid

  • ensureValid(callback?: Callback<any>): void
  • name

    ensureValid

    desc

    checks if the account authorized, if not it authorizes it and set res variable to this.authClient

    throws

    errors from method this.authorize

    example
    
        const authClass = new ServiceAccount(creds, google_auth_scopes);
        authClass.authorize((err, res) => {
            if (err)
                throw err;
            console.log(res);
        });
    

    Parameters

    • Default value callback: Callback<any> = utils.noop

    Returns void

    authClient - JWTClient, holds access token and request methods

isAuthorized

  • isAuthorized(): boolean
  • name

    isAuthorized

    desc

    checks if jwt (this.token) is set and not expired

    example
    
        const authClass = new ServiceAccount(creds, google_auth_scopes);
        if (!authClass.isAuthorized()) {
            authClass.authorize((err, res) => {
                if (err)
                    throw err;
                console.log(res);
            });
        }
    

    Returns boolean