8 changed files with 204 additions and 37 deletions
@ -1,3 +1,7 @@ |
|||||||
<i class="fa fa-rocket"></i> |
<i class="fa fa-rocket"></i> |
||||||
|
|
||||||
The dashboard!! |
The dashboard!! |
||||||
|
|
||||||
|
<button (click)="gsuite()">G Suite</button> |
||||||
|
<button (click)="ldap()">LDAP</button> |
||||||
|
<button (click)="azuread()">Azure AD</button> |
||||||
|
|||||||
@ -1,12 +1,74 @@ |
|||||||
import * as graph from '@microsoft/microsoft-graph-client'; |
import * as graph from '@microsoft/microsoft-graph-client'; |
||||||
|
import * as https from 'https'; |
||||||
|
import * as querystring from 'querystring'; |
||||||
|
|
||||||
import { DirectoryService } from 'src/services/directory.service'; |
import { DirectoryService } from 'src/services/directory.service'; |
||||||
|
|
||||||
|
const Key = ''; |
||||||
|
const ApplicationId = ''; |
||||||
|
const Tenant = ''; |
||||||
|
|
||||||
export class AzureDirectoryService implements DirectoryService { |
export class AzureDirectoryService implements DirectoryService { |
||||||
getEntries(force = false) { |
private client: graph.Client; |
||||||
|
|
||||||
|
async getEntries(force = false) { |
||||||
|
this.client = graph.Client.init({ |
||||||
|
authProvider: (done) => { |
||||||
|
const data = querystring.stringify({ |
||||||
|
client_id: ApplicationId, |
||||||
|
client_secret: Key, |
||||||
|
grant_type: 'client_credentials', |
||||||
|
scope: 'https://graph.microsoft.com/.default', |
||||||
|
}); |
||||||
|
|
||||||
|
const req = https.request({ |
||||||
|
host: 'login.microsoftonline.com', |
||||||
|
path: '/' + Tenant + '/oauth2/v2.0/token', |
||||||
|
method: 'POST', |
||||||
|
headers: { |
||||||
|
'Content-Type': 'application/x-www-form-urlencoded', |
||||||
|
'Content-Length': Buffer.byteLength(data), |
||||||
|
}, |
||||||
|
}, (res) => { |
||||||
|
res.setEncoding('utf8'); |
||||||
|
res.on('data', (chunk: string) => { |
||||||
|
const d = JSON.parse(chunk); |
||||||
|
if (res.statusCode === 200 && d.access_token != null) { |
||||||
|
done(null, d.access_token); |
||||||
|
} else if (d.error != null && d.error_description != null) { |
||||||
|
done(d.error + ' (' + res.statusCode + '): ' + d.error_description, null); |
||||||
|
} else { |
||||||
|
done('Unknown error (' + res.statusCode + ').', null); |
||||||
|
} |
||||||
|
}); |
||||||
|
}).on('error', (err) => { |
||||||
|
done(err, null); |
||||||
|
}); |
||||||
|
|
||||||
|
req.write(data); |
||||||
|
req.end(); |
||||||
|
}, |
||||||
|
}); |
||||||
|
|
||||||
|
await this.getUsers(); |
||||||
|
await this.getGroups(); |
||||||
|
} |
||||||
|
|
||||||
|
private async getUsers() { |
||||||
|
const request = this.client.api('/users/delta'); |
||||||
|
const users = await request.get(); |
||||||
|
console.log(users); |
||||||
} |
} |
||||||
|
|
||||||
private getUsers() { |
private async getGroups() { |
||||||
|
const request = this.client.api('/groups/delta'); |
||||||
|
const groups = await request.get(); |
||||||
|
console.log(groups); |
||||||
|
|
||||||
|
groups.value.forEach(async (g: any) => { |
||||||
|
const membersRequest = this.client.api('/groups/' + g.id + '/members'); |
||||||
|
const members = await membersRequest.get(); |
||||||
|
console.log(members); |
||||||
|
}); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|||||||
@ -1,14 +1,69 @@ |
|||||||
|
import { JWT } from 'google-auth-library'; |
||||||
import { google, GoogleApis } from 'googleapis'; |
import { google, GoogleApis } from 'googleapis'; |
||||||
import { Admin } from 'googleapis/build/src/apis/admin/directory_v1'; |
import { Admin } from 'googleapis/build/src/apis/admin/directory_v1'; |
||||||
|
|
||||||
import { DirectoryService } from 'src/services/directory.service'; |
import { DirectoryService } from 'src/services/directory.service'; |
||||||
|
|
||||||
|
const PrivateKey = ''; |
||||||
|
const ClientEmail = ''; |
||||||
|
const AdminEmail = ''; |
||||||
|
const Domain = ''; |
||||||
|
|
||||||
export class GSuiteDirectoryService implements DirectoryService { |
export class GSuiteDirectoryService implements DirectoryService { |
||||||
getEntries(force = false) { |
private client: JWT; |
||||||
|
private service: Admin; |
||||||
|
private authParams: any; |
||||||
|
|
||||||
|
constructor() { |
||||||
|
this.service = google.admin<Admin>('directory_v1'); |
||||||
|
} |
||||||
|
|
||||||
|
async getEntries(force = false) { |
||||||
|
await this.auth(); |
||||||
|
await this.getUsers(); |
||||||
|
await this.getGroups(); |
||||||
} |
} |
||||||
|
|
||||||
private async getUsers() { |
private async getUsers() { |
||||||
const service = google.admin<Admin>('directory_v1'); |
const response = await this.service.users.list(this.authParams); |
||||||
const groups = await service.groups.list(); |
console.log(response); |
||||||
|
} |
||||||
|
|
||||||
|
private async getGroups() { |
||||||
|
const response = await this.service.groups.list(this.authParams); |
||||||
|
console.log(response); |
||||||
|
|
||||||
|
if (response.data.groups.length === 0) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
response.data.groups.forEach(async (g) => { |
||||||
|
const params: any = Object.assign({ |
||||||
|
groupKey: g.id, |
||||||
|
}, this.authParams); |
||||||
|
const members = await this.service.members.list(params); |
||||||
|
console.log(members); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
private async auth() { |
||||||
|
this.client = new google.auth.JWT({ |
||||||
|
email: ClientEmail, |
||||||
|
key: PrivateKey, |
||||||
|
subject: AdminEmail, |
||||||
|
scopes: [ |
||||||
|
'https://www.googleapis.com/auth/admin.directory.user.readonly', |
||||||
|
'https://www.googleapis.com/auth/admin.directory.group.readonly', |
||||||
|
'https://www.googleapis.com/auth/admin.directory.group.member.readonly', |
||||||
|
], |
||||||
|
}); |
||||||
|
|
||||||
|
await this.client.authorize(); |
||||||
|
this.authParams = { |
||||||
|
auth: this.client, |
||||||
|
domain: Domain, |
||||||
|
}; |
||||||
|
|
||||||
|
// TODO: add customer?
|
||||||
} |
} |
||||||
} |
} |
||||||
|
|||||||
Loading…
Reference in new issue