ServiceAccount
abstracted class to handle oauth2 service account authentication using jwt (json web token) method, should be passed as authClass to API class
oAuth2ServiceAccount
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
constructor
instance of any IAuthClass drived classes in ./auth-client directory
google authentication scopes
googleapis scopes
errors from wrapped method GoogleAuth.JWT
GoogleAuth
authClient
getter for the internal authClient class, which is JWTClient in ServiceAccount case
const authClass = new ServiceAccount(creds, google_auth_scopes); authClass.authorize((err, res) => { if (err) throw err; console.log(authClass.authClient); });
JWTClient - holds the access token and request methods
authorize
send credintials private key to google server and gets json access token object
errors from wrapped method GoogleAuth.JWT.authorize
const authClass = new ServiceAccount(creds, google_auth_scopes); authClass.authorize((err, res) => { if (err) throw err; console.log(res); });
authClient - JWTClient, holds access token and request methods
ensureValid
checks if the account authorized, if not it authorizes it and set res variable to this.authClient
errors from method this.authorize
isAuthorized
checks if jwt (this.token) is set and not expired
const authClass = new ServiceAccount(creds, google_auth_scopes); if (!authClass.isAuthorized()) { authClass.authorize((err, res) => { if (err) throw err; console.log(res); }); }
ServiceAccount
abstracted class to handle oauth2 service account authentication using jwt (json web token) method, should be passed as authClass to API class
oAuth2ServiceAccount