Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function runSample() {
// acquire an authentication client using a service account
const auth = await google.auth.getClient({
keyFile: path.join(__dirname, '../jwt.keys.json'),
scopes: [
'https://www.googleapis.com/auth/admin.directory.group',
'https://www.googleapis.com/auth/admin.directory.group.member',
],
});
// obtain the admin client
const admin = google.admin({
version: 'directory_v1',
auth,
});
// Insert group
const res = await admin.groups.insert({
requestBody: {
email: 'some_group@example.com',
},
});
console.log(res.data);
}
async function runSample() {
// acquire an authentication client using a service account
const auth = await google.auth.getClient({
keyFile: path.join(__dirname, '../jwt.keys.json'),
scopes: [
'https://www.googleapis.com/auth/admin.directory.group',
'https://www.googleapis.com/auth/admin.directory.group.member',
],
});
// obtain the admin client
const admin = google.admin({
version: 'directory_v1',
auth,
});
// delete the group key
const res = await admin.groups.delete({
groupKey: 'some_group@example.com',
});
console.log(res.data);
}
async function runSample() {
// acquire an authentication client using a service account
const auth = await google.auth.getClient({
keyFile: path.join(__dirname, '../jwt.keys.json'),
scopes: [
'https://www.googleapis.com/auth/admin.directory.group',
'https://www.googleapis.com/auth/admin.directory.group.member',
],
});
// obtain the admin client
const admin = google.admin({
version: 'directory_v1',
auth,
});
// Delete member from Google group
const res = await admin.members.delete({
groupKey: 'my_group@example.com',
memberKey: 'me@example.com',
});
console.log(res.data);
}
async function runSample() {
// acquire an authentication client using a service account
const auth = await google.auth.getClient({
keyFile: path.join(__dirname, '../jwt.keys.json'),
scopes: [
'https://www.googleapis.com/auth/admin.directory.group',
'https://www.googleapis.com/auth/admin.directory.group.member',
],
});
// obtain the admin client
const admin = google.admin({
version: 'directory_v1',
auth,
});
// Insert member in Google group
const res = await admin.members.insert({
groupKey: 'my_group@example.com',
requestBody: {
email: 'me@example.com',
},
});
console.log(res.data);
}
function listUsers(auth) {
const service = google.admin({version: 'directory_v1', auth});
service.users.list({
customer: 'my_customer',
maxResults: 10,
orderBy: 'email',
}, (err, res) => {
if (err) return console.error('The API returned an error:', err.message);
const users = res.data.users;
if (users.length) {
console.log('Users:');
users.forEach((user) => {
console.log(`${user.primaryEmail} (${user.name.fullName})`);
});
} else {
console.log('No users found.');
}
function listLoginEvents(auth) {
const service = google.admin({version: 'reports_v1', auth});
service.activities.list({
userKey: 'all',
applicationName: 'login',
maxResults: 10,
}, (err, res) => {
if (err) return console.error('The API returned an error:', err.message);
const activities = res.data.items;
if (activities.length) {
console.log('Logins:');
activities.forEach((activity) => {
console.log(`${activity.id.time}: ${activity.actor.email} (${activity.events[0].name})`);
});
} else {
console.log('No logins found.');
}
constructor(private configurationService: ConfigurationService, private logService: LogService,
private i18nService: I18nService) {
super();
this.service = google.admin('directory_v1');
}