const healthcare = google.healthcare('v1'); const fs = require('fs'); const auth = await google.auth.getClient({ scopes: ['https://www.googleapis.com/auth/cloud-platform'], }); google.options({auth, headers: {'Content-Type': 'application/fhir+json'}});
const healthcare = google.healthcare('v1'); const auth = await google.auth.getClient({ scopes: ['https://www.googleapis.com/auth/cloud-platform'], }); google.options({auth, headers: {'Content-Type': 'application/json-patch+json'}});
const healthcare = google.healthcare('v1'); const auth = await google.auth.getClient({ scopes: ['https://www.googleapis.com/auth/cloud-platform'], }); }; google.options({auth, headers: {'Content-Type': 'application/fhir+json'}});
/** * 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); }); }); }
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'] }); }
constructor (config) { this.api = google.youtube({ version: 'v3', auth: config.youtube_api_key }) }
const fetchSingleSpamMessage = (auth, id) => { return new Promise((resolve, reject) => { const gmail = google.gmail({ version: "v1", auth }); gmail.users.messages.get({ userId: "me", id }, (err, res) => { if (err) reject(err); else resolve(res.data); }); }); }
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 }
getOauth2Client(function (oauth2Client) { oauth2Client.credentials = token; var gmail = google.gmail('v1'); gmail.users.getProfile({ auth: oauth2Client, userId: 'me' }, function(err, res) { if (err) { console.log(err); } else { callback(res.data); } }); });
/** * @return {Promise} Credentials set globally */ const _setAuthCredential = async () => { const res = await auth.getApplicationDefault(); let client = res.credential; if (client.hasScopes && !client.hasScopes()) { client = client.createScoped([ 'https://www.googleapis.com/auth/cloud-billing', 'https://www.googleapis.com/auth/cloud-platform', ]); } // Set credential globally for all requests google.options({ auth: client, }); }
const getClient = options => { return new google.auth.OAuth2( options.client_id, options.client_secret, options.redirect_url ); }
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); } }
// 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); }); }); }