Skip to content

Commit

Permalink
fix: remove init and switch to constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
santese committed Dec 13, 2021
1 parent 54b13c3 commit d71ea93
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Initialize with Client ID and Client Secret Auth:


```javascript
const intune = Intune.init({
const intune = new Intune({
authentication: {
clientId: '',
clientSecret: ''
Expand Down
2 changes: 1 addition & 1 deletion src/lib/intune.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Users } from './users/users'

describe('Intune', () => {
it('creates component instances', () => {
const intune = Intune.init({
const intune = new Intune({
tenantId: 'tenantId',
authentication: { clientId: 'clientId', clientSecret: 'clientSecret' },
})
Expand Down
23 changes: 10 additions & 13 deletions src/lib/intune.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,16 @@ export class Intune {

readonly customRequest: CustomRequest

private constructor(private readonly authProvider: TokenCredentialAuthenticationProvider) {
constructor(private readonly config: Config) {
const credential = new ClientSecretCredential(
this.config.tenantId,
this.config.authentication.clientId,
this.config.authentication.clientSecret,
)
const authProvider = new TokenCredentialAuthenticationProvider(credential, {
scopes: ['.default'],
})

this.graphclient = Client.initWithMiddleware({
authProvider,
defaultVersion: 'beta',
Expand All @@ -50,16 +59,4 @@ export class Intune {
this.customRequest = new CustomRequest(this.graphclient)
this.autopilot = new Autopilot(this.graphclient)
}

static init(config: Config) {
const credential = new ClientSecretCredential(
config.tenantId,
config.authentication.clientId,
config.authentication.clientSecret,
)
const authProvider = new TokenCredentialAuthenticationProvider(credential, {
scopes: ['.default'],
})
return new Intune(authProvider)
}
}

0 comments on commit d71ea93

Please sign in to comment.