Skip to content

Commit 0809cf8

Browse files
authored
Merge pull request #30 from primno/dev
Certificate authentication for OAuthTokenProvider
2 parents 8b63c40 + 0f65d7c commit 0809cf8

File tree

6 files changed

+80
-6
lines changed

6 files changed

+80
-6
lines changed

.github/workflows/npm-publish.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ jobs:
2828
with:
2929
node-version: 18
3030
registry-url: https://registry.npmjs.org/
31+
- run: npm ci
32+
- run: npm run build
3133
- run: npm publish
3234
env:
3335
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,46 @@ interface OAuthConfig {
158158
* OAuth2 credentials
159159
*/
160160
credentials: {
161+
/**
162+
* OAuth flow
163+
*/
161164
grantType: "client_credential" | "password" | "device_code";
165+
/**
166+
* Client ID
167+
*/
162168
clientId: string;
169+
/**
170+
* Client secret for ConfidentialClientApplication.
171+
* If set, clientCertificate is not required.
172+
*/
163173
clientSecret?: string;
174+
/**
175+
* Client certificate for ConfidentialClientApplication.
176+
* If set, clientSecret is not required.
177+
*/
178+
clientCertificate?: {
179+
thumbprint: string;
180+
privateKey: string;
181+
},
182+
/**
183+
* Authority URL (eg: https://login.microsoftonline.com/common/)
184+
*/
164185
authorityUrl: string;
186+
/**
187+
* Username for password and device_code flow.
188+
*/
165189
userName?: string;
190+
/**
191+
* Password for password flow.
192+
*/
166193
password?: string;
194+
/**
195+
* Redirect URI.
196+
*/
167197
redirectUri?: string;
198+
/**
199+
* Scope. Dataverse url suffixed with .default.
200+
*/
168201
scope?: string;
169202
};
170203

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@primno/dataverse-client",
3-
"version": "0.8.0-beta.0",
3+
"version": "0.8.1-beta.0",
44
"description": "Dataverse / Dynamics 365 CE (on-premises) client for Node.JS",
55
"repository": "github:primno/dataverse-client",
66
"main": "dist/index.cjs.js",

src/auth/oauth/msal/token/application.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export async function createApplication(oAuthOptions: OAuthConfig): Promise<Appl
2222
auth: {
2323
clientId: credentials.clientId,
2424
authority: credentials.authorityUrl,
25-
clientSecret: credentials.clientSecret,
2625
knownAuthorities: [credentials.authorityUrl]
2726
},
2827
system: {
@@ -38,10 +37,17 @@ export async function createApplication(oAuthOptions: OAuthConfig): Promise<Appl
3837
cache: persistence.enabled ? await getCacheOptions(persistence) : undefined
3938
};
4039

41-
if (credentials.clientSecret) {
40+
if (credentials.clientSecret || credentials.clientCertificate) {
4241
return {
4342
type: "confidential",
44-
client: new ConfidentialClientApplication(options)
43+
client: new ConfidentialClientApplication({
44+
...options,
45+
auth: {
46+
...options.auth,
47+
clientSecret: credentials.clientSecret,
48+
clientCertificate: credentials.clientCertificate
49+
}
50+
})
4551
};
4652
}
4753
else {

src/auth/oauth/oauth-configuration.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,44 @@
11
export interface OAuthCredentials {
2+
/**
3+
* OAuth flow
4+
*/
25
grantType: "client_credential" | "password" | "device_code";
6+
/**
7+
* Client ID
8+
*/
39
clientId: string;
10+
/**
11+
* Client secret for ConfidentialClientApplication.
12+
* If set, clientCertificate is not required.
13+
*/
414
clientSecret?: string;
15+
/**
16+
* Client certificate for ConfidentialClientApplication.
17+
* If set, clientSecret is not required.
18+
*/
19+
clientCertificate?: {
20+
thumbprint: string;
21+
privateKey: string;
22+
},
23+
/**
24+
* Authority URL (eg: https://login.microsoftonline.com/common/)
25+
*/
526
authorityUrl: string;
27+
/**
28+
* Username for password and device_code flow.
29+
*/
630
userName?: string;
31+
/**
32+
* Password for password flow.
33+
*/
734
password?: string;
35+
/**
36+
* Redirect URI.
37+
*/
838
redirectUri?: string;
39+
/**
40+
* Scope. Dataverse url suffixed with .default.
41+
*/
942
scope?: string;
1043
}
1144

0 commit comments

Comments
 (0)