8000 Certificate authentication for OAuthTokenProvider by xaviermonin · Pull Request #30 · primno/dataverse · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Certificate authentication for OAuthTokenProvider #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
with:
node-version: 18
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm run build
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,46 @@ interface OAuthConfig {
* OAuth2 credentials
*/
credentials: {
/**
* OAuth flow
*/
grantType: "client_credential" | "password" | "device_code";
/**
* Client ID
*/
clientId: string;
/**
* Client secret for ConfidentialClientApplication.
* If set, clientCertificate is not required.
*/
clientSecret?: string;
/**
* Client certificate for ConfidentialClientApplication.
* If set, clientSecret is not required.
*/
clientCertificate?: {
thumbprint: string;
privateKey: string;
},
/**
* Authority URL (eg: https://login.microsoftonline.com/common/)
*/
authorityUrl: string;
/**
* Username for password and device_code flow.
*/
userName?: string;
/**
* Password for password flow.
*/
password?: string;
/**
* Redirect URI.
*/
redirectUri?: string;
/**
* Scope. Dataverse url suffixed with .default.
*/
scope?: string;
};

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@primno/dataverse-client",
"version": "0.8.0-beta.0",
"version": "0.8.1-beta.0",
"description": "Dataverse / Dynamics 365 CE (on-premises) client for Node.JS",
"repository": "github:primno/dataverse-client",
"main": "dist/index.cjs.js",
Expand Down
12 changes: 9 additions & 3 deletions src/auth/oauth/msal/token/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export async function createApplication(oAuthOptions: OAuthConfig): Promise<Appl
auth: {
clientId: credentials.clientId,
authority: credentials.authorityUrl,
clientSecret: credentials.clientSecret,
knownAuthorities: [credentials.authorityUrl]
},
system: {
Expand All @@ -38,10 +37,17 @@ export async function createApplication(oAuthOptions: OAuthConfig): Promise<Appl
cache: persistence.enabled ? await getCacheOptions(persistence) : undefined
};

if (credentials.clientSecret) {
if (credentials.clientSecret || credentials.clientCertificate) {
return {
type: "confidential",
client: new ConfidentialClientApplication(options)
client: new ConfidentialClientApplication({
...options,
auth: {
...options.auth,
clientSecret: credentials.clientSecret,
clientCertificate: credentials.clientCertificate
}
})
};
}
else {
Expand Down
33 changes: 33 additions & 0 deletions src/auth/oauth/oauth-configuration.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
export interface OAuthCredentials {
/**
* OAuth flow
*/
grantType: "client_credential" | "password" | "device_code";
/**
* Client ID
*/
clientId: string;
/**
* Client secret for ConfidentialClientApplication.
* If set, clientCertificate is not required.
*/
clientSecret?: string;
/**
* Client certificate for ConfidentialClientApplication.
* If set, clientSecret is not required.
*/
clientCertificate?: {
thumbprint: string;
privateKey: string;
},
/**
* Authority URL (eg: https://login.microsoftonline.com/common/)
*/
authorityUrl: string;
/**
* Username for password and device_code flow.
*/
userName?: string;
/**
* Password for password flow.
*/
password?: string;
/**
* Redirect URI.
*/
redirectUri?: string;
/**
* Scope. Dataverse url suffixed with .default.
*/
scope?: string;
}

Expand Down
0