const auth = await google.auth.getClient({ scopes: ['https://www.googleapis.com/auth/cloud-platform'], });
const auth = await google.auth.getClient({ scopes: ['https://www.googleapis.com/auth/cloud-platform'], });
const auth = await google.auth.getClient({ scopes: ['https://www.googleapis.com/auth/cloud-platform'], });
/** * Get a valid access token. */ // [START retrieve_access_token] function getAccessToken() { return new Promise(function(resolve, reject) { const key = require('../placeholders/service-account.json'); const jwtClient = new google.auth.JWT( key.client_email, null, key.private_key, SCOPES, null ); jwtClient.authorize(function(err, tokens) { if (err) { reject(err); return; } resolve(tokens.access_token); }); }); }
const getClient = options => { return new google.auth.OAuth2( options.client_id, options.client_secret, options.redirect_url ); }
const genAuthUrl = (options, stateUrl) => { const client = getClient(options); const opts = { access_type: 'offline', scope: AUTH_SCOPES, state: stateUrl, }; if (isV2AuthApi(google.auth.OAuth2.GOOGLE_OAUTH2_AUTH_BASE_URL_)) { opts.prompt = 'consent'; } else { opts.approval_prompt = 'force'; } return client.generateAuthUrl(opts); }
async authorize(credentials) { const {client_secret, client_id, redirect_uris} = credentials.installed const oAuth2Client = new google.auth.OAuth2( client_id, client_secret, redirect_uris[0]) // Check if we have previously stored a token. try { let token = await fs.readFile(this.token_path) oAuth2Client.setCredentials(JSON.parse(token)) } catch (err) { let res = await this.getAccessToken(oAuth2Client) return res } return oAuth2Client }
function getAuthenticationUrl() { var client = new google.auth.OAuth2( config.oauth2.clientId, config.oauth2.clientSecret, config.oauth2.redirectUrl ); // Use 'profile' scope to authorize fetching the user's profile return client.generateAuthUrl({ scope: ['profile'] }); }
const createAuthCredential = async () => { try { let authClient = await google.auth.getApplicationDefault(); authClient = authClient.credential; if (authClient.createScopedRequired && authClient.createScopedRequired()) { authClient = authClient.createScoped([ 'https://www.googleapis.com/auth/jobs', ]); } return google.jobs({ version: 'v3', auth: authClient, }); } catch (e) { return console.error(e); } }
// [END healthcare_patch_hl7v2_message] // Returns an authorized API client by discovering the Healthcare API with // the provided API key. // [START healthcare_get_client] function getClient(apiKey, serviceAccountJson, cb) { const API_VERSION = 'v1alpha'; const DISCOVERY_API = 'https://healthcare.googleapis.com/$discovery/rest'; google.auth .getClient({scopes: ['https://www.googleapis.com/auth/cloud-platform']}) .then(authClient => { const discoveryUrl = `${DISCOVERY_API}?labels=CHC_ALPHA&version=${API_VERSION}&key=${apiKey}`; google.options({auth: authClient}); google .discoverAPI(discoveryUrl) .then(client => { cb(client); }) .catch(err => { console.error(err); }); }); }
function getAccessToken() { return new Promise(function(resolve, reject) { var key = serviceAccount var jwtClient = new google.auth.JWT( key.client_email, null, key.private_key, SCOPES, null ) jwtClient.authorize(function(err, tokens) { if (err) { reject(err) return } resolve(tokens.access_token) }) }) }
// Returns an authorized API client by discovering the Cloud IoT Core API with // the provided API key. const getClient = async () => { const authClient = await google.auth.getClient({ scopes: ['https://www.googleapis.com/auth/cloud-platform'], }); const discoveryUrl = `${DISCOVERY_API}?version=${API_VERSION}`; google.options({ auth: authClient, }); try { return google.discoverAPI(discoveryUrl); } catch (err) { console.log('Error during API discovery.', err); } }
/** * Get a valid access token. */ // [START retrieve_access_token] function getAccessToken() { return new Promise(function(resolve, reject) { const key = require('../placeholders/service-account.json'); const jwtClient = new google.auth.JWT( key.client_email, null, key.private_key, SCOPES, null ); jwtClient.authorize(function(err, tokens) { if (err) { reject(err); return; } resolve(tokens.access_token); }); }); }
// Returns an authorized API client by discovering the Cloud IoT Core API with // the provided API key. const getClient = async serviceAccountJson => { // the getClient method looks for the GCLOUD_PROJECT and GOOGLE_APPLICATION_CREDENTIALS // environment variables if serviceAccountJson is not passed in const authClient = await google.auth.getClient({ keyFilename: serviceAccountJson, scopes: ['https://www.googleapis.com/auth/cloud-platform'], }); const discoveryUrl = `${DISCOVERY_API}?version=${API_VERSION}`; google.options({ auth: authClient, }); try { return google.discoverAPI(discoveryUrl); } catch (err) { console.log('Error during API discovery.', err); } }
// [END healthcare_get_fhir_store_metadata] // Returns an authorized API client by discovering the Healthcare API with // the provided API key. // [START healthcare_get_client] function getClient(apiKey, serviceAccountJson, cb) { const API_VERSION = 'v1alpha'; const DISCOVERY_API = 'https://healthcare.googleapis.com/$discovery/rest'; google.auth .getClient({scopes: ['https://www.googleapis.com/auth/cloud-platform']}) .then(authClient => { const discoveryUrl = `${DISCOVERY_API}?labels=CHC_ALPHA&version=${API_VERSION}&key=${apiKey}`; google.options({auth: authClient}); google .discoverAPI(discoveryUrl) .then(client => { cb(client); }) .catch(err => { console.error(err); }); }); }