Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import {GoogleAuth, JWT} from 'google-auth-library';
// uncomment the line below during development
// import {GoogleAuth} from '../../../../build/src/index';
const jwt = new JWT();
const auth = new GoogleAuth();
async function getToken() {
const token = await jwt.getToken('token');
const projectId = await auth.getProjectId();
const creds = await auth.getApplicationDefault();
return token;
}
getToken();
async function main(
// Full path to the sevice account credential
keyFile = process.env.GOOGLE_APPLICATION_CREDENTIALS
) {
const keys = require(keyFile);
const client = new JWT({
email: keys.client_email,
key: keys.private_key,
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
});
const url = `https://dns.googleapis.com/dns/v1/projects/${keys.project_id}`;
const res = await client.request({url});
console.log('DNS Info:');
console.log(res.data);
// After acquiring an access_token, you may want to check on the audience, expiration,
// or original scopes requested. You can do that with the `getTokenInfo` method.
const tokenInfo = await client.getTokenInfo(client.credentials.access_token);
console.log(tokenInfo);
}
reject(messageFileName+' not found in messages/ - please use the --message parameter to specify a message file in the messages/ directory');
return;
}
if(!isTopicMessage){
message.token = deviceToken;
}
message = {
message: message,
validate_only: false
};
const googleAuth = require('google-auth-library');
_projectId = serviceAccount.project_id;
_jwtClient = new googleAuth.JWT(
serviceAccount.client_email,
null,
serviceAccount.private_key,
['https://www.googleapis.com/auth/firebase.messaging'],
null
);
_jwtClient.authorize(function(error, tokens) {
if (error) {
reject(error);
return;
}
resolve();
});
});
};
async function main() {
const clientId = oauth2Keys.web.client_id;
const client = new JWT({
email: keys.client_email,
key: keys.private_key,
additionalClaims: {target_audience: clientId},
});
const url = `https://iap-demo-dot-el-gato.appspot.com`;
const res = await client.request({url});
console.log(res.data);
}
var authenticate = async function(GoogleConfig) {
const client = new JWT({
email: GoogleConfig.client_email,
key: GoogleConfig.private_key,
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
});
return client;
};
module.exports = async function (serviceAccountCredentials) {
const jwtClient = new JWT({
email:
serviceAccountCredentials.clientEmail ||
serviceAccountCredentials.client_email,
key:
serviceAccountCredentials.privateKey ||
serviceAccountCredentials.private_key,
scopes
})
const authorize = promisify(jwtClient.authorize).bind(jwtClient)
const accessToken = await authorize()
return accessToken.access_token
}
credentials = _context.sent;
_context.next = 7;
break;
case 6:
if (_typeof(config) === 'object') {
credentials = config;
} else if (config === undefined) {
credentials = {
client_email: process.env.GAPI_CLIENT_EMAIL,
private_key: process.env.GAPI_PRIVATE_KEY.replace(/\\n/g, '\n')
};
}
case 7:
this.client = new JWT({
email: credentials['client_email'],
key: credentials['private_key'],
scopes: ['https://www.googleapis.com/auth/drive']
});
_context.next = 10;
return this.client.authorize();
case 10:
return _context.abrupt("return", this);
case 11:
case "end":
return _context.stop();
}
}
}, _callee, this);
}
}
const fileExists = await exists(this.config.credentialsFile);
if (!fileExists) {
if (this.config.requireCredentialsFile === false) {
return;
} else {
throw new Error(`Credentials file doesn't exist in ${this.config.credentialsFile}`);
}
}
const results = await readFile(this.config.credentialsFile);
const keyFileObject = JSON.parse(results.toString());
const jwtClient = new JWT(
keyFileObject.client_email,
undefined,
keyFileObject.private_key,
['https://www.googleapis.com/auth/dialogflow'],
undefined,
);
jwtClient.projectId = keyFileObject.project_id;
return jwtClient;
}
export default async function(config) {
let credentials;
if (typeof config === 'string') {
credentials = await readJSON(config);
} else if (typeof config === 'object') {
credentials = config;
} else if (config === undefined) {
credentials = {
client_email: process.env.GAPI_CLIENT_EMAIL,
private_key: process.env.GAPI_PRIVATE_KEY.replace(/\\n/g, '\n'),
};
}
this.client = new JWT({
email: credentials['client_email'],
key: credentials['private_key'],
scopes: ['https://www.googleapis.com/auth/drive'],
});
await this.client.authorize();
return this;
};
exports.default = async function (config) {
let credentials;
if (typeof config === 'string') {
credentials = await (0, _fsExtra.readJSON)(config);
} else if (typeof config === 'object') {
credentials = config;
} else if (config === undefined) {
credentials = {
client_email: process.env.GAPI_CLIENT_EMAIL,
private_key: process.env.GAPI_PRIVATE_KEY.replace(/\\n/g, '\n')
};
}
this.client = new _googleAuthLibrary.JWT({
email: credentials['client_email'],
key: credentials['private_key'],
scopes: ['https://www.googleapis.com/auth/drive']
});
await this.client.authorize();
return this;
};