@databricks/sdk-auth 0.1.0-dev.3 → 0.1.0-dev.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/credentials/default/chain.d.ts +21 -5
- package/dist/credentials/default/chain.d.ts.map +1 -1
- package/dist/credentials/default/chain.js +52 -23
- package/dist/credentials/default/chain.js.map +1 -1
- package/dist/credentials/default/errors.d.ts +1 -1
- package/dist/credentials/default/errors.d.ts.map +1 -1
- package/dist/credentials/default/errors.js.map +1 -1
- package/dist/credentials/default/u2m-strategy.d.ts.map +1 -1
- package/dist/credentials/default/u2m-strategy.js +14 -11
- package/dist/credentials/default/u2m-strategy.js.map +1 -1
- package/dist/credentials/errors.d.ts +11 -0
- package/dist/credentials/errors.d.ts.map +1 -1
- package/dist/credentials/errors.js +13 -0
- package/dist/credentials/errors.js.map +1 -1
- package/dist/credentials/index.browser.d.ts +2 -2
- package/dist/credentials/index.browser.d.ts.map +1 -1
- package/dist/credentials/index.browser.js +1 -1
- package/dist/credentials/index.browser.js.map +1 -1
- package/dist/credentials/index.d.ts +2 -2
- package/dist/credentials/index.d.ts.map +1 -1
- package/dist/credentials/index.js +1 -1
- package/dist/credentials/index.js.map +1 -1
- package/dist/credentials/pat.d.ts +2 -1
- package/dist/credentials/pat.d.ts.map +1 -1
- package/dist/credentials/pat.js +12 -13
- package/dist/credentials/pat.js.map +1 -1
- package/package.json +12 -8
- package/src/auth.ts +0 -117
- package/src/credentials/default/chain.ts +0 -75
- package/src/credentials/default/default-credentials.ts +0 -40
- package/src/credentials/default/errors.ts +0 -18
- package/src/credentials/default/u2m-strategy.ts +0 -20
- package/src/credentials/errors.ts +0 -51
- package/src/credentials/host-metadata.ts +0 -166
- package/src/credentials/index.browser.ts +0 -11
- package/src/credentials/index.ts +0 -14
- package/src/credentials/m2m.ts +0 -156
- package/src/credentials/pat.ts +0 -44
- package/src/credentials/u2m.ts +0 -212
- package/src/index.ts +0 -19
- package/src/oidc/env.ts +0 -21
- package/src/oidc/file.ts +0 -29
- package/src/oidc/index.browser.ts +0 -16
- package/src/oidc/index.ts +0 -17
- package/src/oidc/oidc.ts +0 -26
- package/src/oidc/tokensource.ts +0 -133
|
@@ -1,22 +1,38 @@
|
|
|
1
1
|
import type { Profile } from '@databricks/sdk-core/profiles';
|
|
2
2
|
import type { Credentials, Header } from '../../auth';
|
|
3
3
|
/**
|
|
4
|
-
* A strategy inspects a profile and either returns configured
|
|
5
|
-
* or `undefined` if it is not applicable.
|
|
4
|
+
* A named strategy that inspects a profile and either returns configured
|
|
5
|
+
* credentials or `undefined` if it is not applicable. The `name` matches the
|
|
6
|
+
* `name()` of the credentials it produces, so it can be selected by a
|
|
7
|
+
* profile's `authType`.
|
|
6
8
|
*/
|
|
7
|
-
export
|
|
9
|
+
export interface Strategy {
|
|
10
|
+
/** Short identifier, e.g. `pat`, `oauth-m2m`, or `databricks-cli`. */
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly configure: (profile: Profile) => Credentials | undefined;
|
|
13
|
+
}
|
|
8
14
|
/**
|
|
9
|
-
* Lazy {@link Credentials} that resolves to
|
|
10
|
-
*
|
|
15
|
+
* Lazy {@link Credentials} that resolves to a configured strategy on the
|
|
16
|
+
* first `authHeaders()` call.
|
|
17
|
+
*
|
|
18
|
+
* If the profile sets `authType`, the strategy whose name matches it is
|
|
19
|
+
* selected. Otherwise the strategies are tried in order and the first
|
|
20
|
+
* configured one wins.
|
|
11
21
|
*/
|
|
12
22
|
export declare class DefaultCredentials implements Credentials {
|
|
13
23
|
private readonly strategies;
|
|
14
24
|
private readonly loadProfile;
|
|
15
25
|
private resolved;
|
|
16
26
|
constructor(strategies: readonly Strategy[], loadProfile: () => Promise<Profile>);
|
|
27
|
+
/**
|
|
28
|
+
* Returns `default` until a strategy has been resolved, then delegates to
|
|
29
|
+
* the resolved strategy so callers (logging, telemetry) can tell which
|
|
30
|
+
* authentication method won.
|
|
31
|
+
*/
|
|
17
32
|
name(): string;
|
|
18
33
|
authHeaders(): Promise<Header[]>;
|
|
19
34
|
private resolveChain;
|
|
35
|
+
private resolveByAuthType;
|
|
20
36
|
}
|
|
21
37
|
/** PAT strategy: configured when `token` is set in the profile. */
|
|
22
38
|
export declare const patStrategy: Strategy;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../../../src/credentials/default/chain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,+BAA+B,CAAC;AAE3D,OAAO,KAAK,EAAC,WAAW,EAAE,MAAM,EAAC,MAAM,YAAY,CAAC;AAMpD
|
|
1
|
+
{"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../../../src/credentials/default/chain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,+BAA+B,CAAC;AAE3D,OAAO,KAAK,EAAC,WAAW,EAAE,MAAM,EAAC,MAAM,YAAY,CAAC;AAMpD;;;;;GAKG;AACH,MAAM,WAAW,QAAQ;IACvB,sEAAsE;IACtE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,WAAW,GAAG,SAAS,CAAC;CACnE;AAKD;;;;;;;GAOG;AACH,qBAAa,kBAAmB,YAAW,WAAW;IAIlD,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,WAAW;IAJ9B,OAAO,CAAC,QAAQ,CAA0B;gBAGvB,UAAU,EAAE,SAAS,QAAQ,EAAE,EAC/B,WAAW,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC;IAGtD;;;;OAIG;IACH,IAAI,IAAI,MAAM;IAIR,WAAW,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YAKxB,YAAY;IAiB1B,OAAO,CAAC,iBAAiB;CAiB1B;AAED,mEAAmE;AACnE,eAAO,MAAM,WAAW,EAAE,QAOzB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,WAAW,EAAE,QAazB,CAAC"}
|
|
@@ -4,8 +4,12 @@ import { DefaultCredentialsError } from './errors';
|
|
|
4
4
|
const AUTH_DOC_URL = 'https://docs.databricks.com/aws/en/dev-tools/auth/index';
|
|
5
5
|
const NO_AUTH_CONFIGURED_MESSAGE = `cannot configure default credentials, please check ${AUTH_DOC_URL} to configure credentials for your preferred authentication method`;
|
|
6
6
|
/**
|
|
7
|
-
* Lazy {@link Credentials} that resolves to
|
|
8
|
-
*
|
|
7
|
+
* Lazy {@link Credentials} that resolves to a configured strategy on the
|
|
8
|
+
* first `authHeaders()` call.
|
|
9
|
+
*
|
|
10
|
+
* If the profile sets `authType`, the strategy whose name matches it is
|
|
11
|
+
* selected. Otherwise the strategies are tried in order and the first
|
|
12
|
+
* configured one wins.
|
|
9
13
|
*/
|
|
10
14
|
export class DefaultCredentials {
|
|
11
15
|
strategies;
|
|
@@ -15,8 +19,13 @@ export class DefaultCredentials {
|
|
|
15
19
|
this.strategies = strategies;
|
|
16
20
|
this.loadProfile = loadProfile;
|
|
17
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Returns `default` until a strategy has been resolved, then delegates to
|
|
24
|
+
* the resolved strategy so callers (logging, telemetry) can tell which
|
|
25
|
+
* authentication method won.
|
|
26
|
+
*/
|
|
18
27
|
name() {
|
|
19
|
-
return 'default';
|
|
28
|
+
return this.resolved?.name() ?? 'default';
|
|
20
29
|
}
|
|
21
30
|
async authHeaders() {
|
|
22
31
|
this.resolved ??= await this.resolveChain();
|
|
@@ -24,39 +33,59 @@ export class DefaultCredentials {
|
|
|
24
33
|
}
|
|
25
34
|
async resolveChain() {
|
|
26
35
|
const profile = await this.loadProfile();
|
|
36
|
+
if (profile.authType !== undefined) {
|
|
37
|
+
return this.resolveByAuthType(profile, profile.authType);
|
|
38
|
+
}
|
|
27
39
|
for (const strategy of this.strategies) {
|
|
28
|
-
const built = strategy(profile);
|
|
40
|
+
const built = strategy.configure(profile);
|
|
29
41
|
if (built !== undefined) {
|
|
30
42
|
return built;
|
|
31
43
|
}
|
|
32
44
|
}
|
|
33
45
|
throw new DefaultCredentialsError('NO_AUTH_CONFIGURED', NO_AUTH_CONFIGURED_MESSAGE);
|
|
34
46
|
}
|
|
47
|
+
resolveByAuthType(profile, authType) {
|
|
48
|
+
const strategy = this.strategies.find(s => s.name === authType);
|
|
49
|
+
if (strategy === undefined) {
|
|
50
|
+
throw new DefaultCredentialsError('AUTH_TYPE_NOT_FOUND', `auth type "${authType}" not found, please check ${AUTH_DOC_URL} for a list of supported auth types`);
|
|
51
|
+
}
|
|
52
|
+
const built = strategy.configure(profile);
|
|
53
|
+
if (built === undefined) {
|
|
54
|
+
throw new DefaultCredentialsError('NO_AUTH_CONFIGURED', NO_AUTH_CONFIGURED_MESSAGE);
|
|
55
|
+
}
|
|
56
|
+
return built;
|
|
57
|
+
}
|
|
35
58
|
}
|
|
36
59
|
/** PAT strategy: configured when `token` is set in the profile. */
|
|
37
|
-
export const patStrategy =
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
60
|
+
export const patStrategy = {
|
|
61
|
+
name: 'pat',
|
|
62
|
+
configure: profile => {
|
|
63
|
+
if (profile.host === undefined)
|
|
64
|
+
return undefined;
|
|
65
|
+
if (profile.token === undefined)
|
|
66
|
+
return undefined;
|
|
67
|
+
return newPatCredentials(profile.token.value);
|
|
68
|
+
},
|
|
43
69
|
};
|
|
44
70
|
/**
|
|
45
71
|
* OAuth M2M strategy: configured when `clientId` and `clientSecret` are
|
|
46
72
|
* both set in the profile.
|
|
47
73
|
*/
|
|
48
|
-
export const m2mStrategy =
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
74
|
+
export const m2mStrategy = {
|
|
75
|
+
name: 'oauth-m2m',
|
|
76
|
+
configure: profile => {
|
|
77
|
+
if (profile.host === undefined)
|
|
78
|
+
return undefined;
|
|
79
|
+
if (profile.clientId === undefined)
|
|
80
|
+
return undefined;
|
|
81
|
+
if (profile.clientSecret === undefined)
|
|
82
|
+
return undefined;
|
|
83
|
+
return newM2mCredentials({
|
|
84
|
+
host: profile.host,
|
|
85
|
+
clientId: profile.clientId,
|
|
86
|
+
clientSecret: profile.clientSecret.value,
|
|
87
|
+
...(profile.accountId !== undefined && { accountId: profile.accountId }),
|
|
88
|
+
});
|
|
89
|
+
},
|
|
61
90
|
};
|
|
62
91
|
//# sourceMappingURL=chain.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chain.js","sourceRoot":"","sources":["../../../src/credentials/default/chain.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,iBAAiB,EAAC,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAC,iBAAiB,EAAC,MAAM,QAAQ,CAAC;AAEzC,OAAO,EAAC,uBAAuB,EAAC,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"chain.js","sourceRoot":"","sources":["../../../src/credentials/default/chain.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Discriminant codes for {@link DefaultCredentialsError}. */
|
|
2
|
-
export type DefaultCredentialsErrorCode = 'NO_AUTH_CONFIGURED';
|
|
2
|
+
export type DefaultCredentialsErrorCode = 'NO_AUTH_CONFIGURED' | 'AUTH_TYPE_NOT_FOUND';
|
|
3
3
|
/**
|
|
4
4
|
* Error thrown when the default credentials chain cannot resolve a
|
|
5
5
|
* strategy to authenticate with.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/credentials/default/errors.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,MAAM,MAAM,2BAA2B,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/credentials/default/errors.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,MAAM,MAAM,2BAA2B,GACnC,oBAAoB,GACpB,qBAAqB,CAAC;AAE1B;;;;;GAKG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,QAAQ,CAAC,IAAI,EAAE,2BAA2B,CAAC;gBAE/B,IAAI,EAAE,2BAA2B,EAAE,OAAO,EAAE,MAAM;CAK/D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/credentials/default/errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/credentials/default/errors.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IACvC,IAAI,CAA8B;IAE3C,YAAY,IAAiC,EAAE,OAAe;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;QACtC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"u2m-strategy.d.ts","sourceRoot":"","sources":["../../../src/credentials/default/u2m-strategy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,SAAS,CAAC;AAEtC;;;;;GAKG;AACH,eAAO,MAAM,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"u2m-strategy.d.ts","sourceRoot":"","sources":["../../../src/credentials/default/u2m-strategy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,SAAS,CAAC;AAEtC;;;;;GAKG;AACH,eAAO,MAAM,WAAW,EAAE,QAYzB,CAAC"}
|
|
@@ -5,16 +5,19 @@ import { newU2mCredentials } from '../u2m';
|
|
|
5
5
|
* The CLI must have been logged in ahead of time via `databricks auth
|
|
6
6
|
* login`.
|
|
7
7
|
*/
|
|
8
|
-
export const u2mStrategy =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
export const u2mStrategy = {
|
|
9
|
+
name: 'databricks-cli',
|
|
10
|
+
configure: profile => {
|
|
11
|
+
if (profile.host === undefined)
|
|
12
|
+
return undefined;
|
|
13
|
+
if (profile.name === undefined)
|
|
14
|
+
return undefined;
|
|
15
|
+
return newU2mCredentials({
|
|
16
|
+
profile: profile.name,
|
|
17
|
+
...(profile.databricksCliPath !== undefined && {
|
|
18
|
+
cliPath: profile.databricksCliPath,
|
|
19
|
+
}),
|
|
20
|
+
});
|
|
21
|
+
},
|
|
19
22
|
};
|
|
20
23
|
//# sourceMappingURL=u2m-strategy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"u2m-strategy.js","sourceRoot":"","sources":["../../../src/credentials/default/u2m-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAC,MAAM,QAAQ,CAAC;AAIzC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAa,OAAO,CAAC,EAAE;
|
|
1
|
+
{"version":3,"file":"u2m-strategy.js","sourceRoot":"","sources":["../../../src/credentials/default/u2m-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAC,MAAM,QAAQ,CAAC;AAIzC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAa;IACnC,IAAI,EAAE,gBAAgB;IACtB,SAAS,EAAE,OAAO,CAAC,EAAE;QACnB,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QACjD,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QACjD,OAAO,iBAAiB,CAAC;YACvB,OAAO,EAAE,OAAO,CAAC,IAAI;YACrB,GAAG,CAAC,OAAO,CAAC,iBAAiB,KAAK,SAAS,IAAI;gBAC7C,OAAO,EAAE,OAAO,CAAC,iBAAiB;aACnC,CAAC;SACH,CAAC,CAAC;IACL,CAAC;CACF,CAAC"}
|
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
+
/** Discriminant codes for {@link PatCredentialsError}. */
|
|
7
|
+
export type PatCredentialsErrorCode = 'TOKEN_REQUIRED' | 'TOKEN_MALFORMED';
|
|
8
|
+
/**
|
|
9
|
+
* Error thrown by personal access token (PAT) credential operations.
|
|
10
|
+
*
|
|
11
|
+
* Use the `code` field to distinguish between error causes.
|
|
12
|
+
*/
|
|
13
|
+
export declare class PatCredentialsError extends Error {
|
|
14
|
+
readonly code: PatCredentialsErrorCode;
|
|
15
|
+
constructor(code: PatCredentialsErrorCode, message: string);
|
|
16
|
+
}
|
|
6
17
|
/** Discriminant codes for {@link M2mCredentialsError}. */
|
|
7
18
|
export type M2mCredentialsErrorCode = 'CLIENT_ID_REQUIRED' | 'CLIENT_SECRET_REQUIRED' | 'HOST_REQUIRED' | 'DISCOVERY_FAILED' | 'TOKEN_REQUEST_FAILED';
|
|
8
19
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/credentials/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,0DAA0D;AAC1D,MAAM,MAAM,uBAAuB,GAC/B,oBAAoB,GACpB,wBAAwB,GACxB,eAAe,GACf,kBAAkB,GAClB,sBAAsB,CAAC;AAE3B;;;;GAIG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAC;gBAE3B,IAAI,EAAE,uBAAuB,EAAE,OAAO,EAAE,MAAM;CAK3D;AAED,0DAA0D;AAC1D,MAAM,MAAM,uBAAuB,GAC/B,kBAAkB,GAClB,eAAe,GACf,qBAAqB,GACrB,oBAAoB,GACpB,kBAAkB,CAAC;AAEvB;;;;GAIG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAC;gBAE3B,IAAI,EAAE,uBAAuB,EAAE,OAAO,EAAE,MAAM;CAK3D"}
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/credentials/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,0DAA0D;AAC1D,MAAM,MAAM,uBAAuB,GAAG,gBAAgB,GAAG,iBAAiB,CAAC;AAE3E;;;;GAIG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAC;gBAE3B,IAAI,EAAE,uBAAuB,EAAE,OAAO,EAAE,MAAM;CAK3D;AAED,0DAA0D;AAC1D,MAAM,MAAM,uBAAuB,GAC/B,oBAAoB,GACpB,wBAAwB,GACxB,eAAe,GACf,kBAAkB,GAClB,sBAAsB,CAAC;AAE3B;;;;GAIG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAC;gBAE3B,IAAI,EAAE,uBAAuB,EAAE,OAAO,EAAE,MAAM;CAK3D;AAED,0DAA0D;AAC1D,MAAM,MAAM,uBAAuB,GAC/B,kBAAkB,GAClB,eAAe,GACf,qBAAqB,GACrB,oBAAoB,GACpB,kBAAkB,CAAC;AAEvB;;;;GAIG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAC;gBAE3B,IAAI,EAAE,uBAAuB,EAAE,OAAO,EAAE,MAAM;CAK3D"}
|
|
@@ -3,6 +3,19 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
+
/**
|
|
7
|
+
* Error thrown by personal access token (PAT) credential operations.
|
|
8
|
+
*
|
|
9
|
+
* Use the `code` field to distinguish between error causes.
|
|
10
|
+
*/
|
|
11
|
+
export class PatCredentialsError extends Error {
|
|
12
|
+
code;
|
|
13
|
+
constructor(code, message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = 'PatCredentialsError';
|
|
16
|
+
this.code = code;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
6
19
|
/**
|
|
7
20
|
* Error thrown by M2M credential operations.
|
|
8
21
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/credentials/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/credentials/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH;;;;GAIG;AACH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IACnC,IAAI,CAA0B;IAEvC,YAAY,IAA6B,EAAE,OAAe;QACxD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAUD;;;;GAIG;AACH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IACnC,IAAI,CAA0B;IAEvC,YAAY,IAA6B,EAAE,OAAe;QACxD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAUD;;;;GAIG;AACH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IACnC,IAAI,CAA0B;IAEvC,YAAY,IAA6B,EAAE,OAAe;QACxD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF"}
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* that depend on Node.js-only APIs (e.g. `databricks-cli` auth which spawns
|
|
4
4
|
* the CLI binary).
|
|
5
5
|
*/
|
|
6
|
-
export { M2mCredentialsError } from './errors';
|
|
7
|
-
export type { M2mCredentialsErrorCode } from './errors';
|
|
6
|
+
export { M2mCredentialsError, PatCredentialsError } from './errors';
|
|
7
|
+
export type { M2mCredentialsErrorCode, PatCredentialsErrorCode } from './errors';
|
|
8
8
|
export { newM2mCredentials } from './m2m';
|
|
9
9
|
export type { M2mCredentialsOptions } from './m2m';
|
|
10
10
|
export { newPatCredentials } from './pat';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.browser.d.ts","sourceRoot":"","sources":["../../src/credentials/index.browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,mBAAmB,EAAC,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.browser.d.ts","sourceRoot":"","sources":["../../src/credentials/index.browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,mBAAmB,EAAE,mBAAmB,EAAC,MAAM,UAAU,CAAC;AAClE,YAAY,EAAC,uBAAuB,EAAE,uBAAuB,EAAC,MAAM,UAAU,CAAC;AAC/E,OAAO,EAAC,iBAAiB,EAAC,MAAM,OAAO,CAAC;AACxC,YAAY,EAAC,qBAAqB,EAAC,MAAM,OAAO,CAAC;AACjD,OAAO,EAAC,iBAAiB,EAAC,MAAM,OAAO,CAAC"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* that depend on Node.js-only APIs (e.g. `databricks-cli` auth which spawns
|
|
4
4
|
* the CLI binary).
|
|
5
5
|
*/
|
|
6
|
-
export { M2mCredentialsError } from './errors';
|
|
6
|
+
export { M2mCredentialsError, PatCredentialsError } from './errors';
|
|
7
7
|
export { newM2mCredentials } from './m2m';
|
|
8
8
|
export { newPatCredentials } from './pat';
|
|
9
9
|
//# sourceMappingURL=index.browser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../../src/credentials/index.browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,mBAAmB,EAAC,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../../src/credentials/index.browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,mBAAmB,EAAE,mBAAmB,EAAC,MAAM,UAAU,CAAC;AAElE,OAAO,EAAC,iBAAiB,EAAC,MAAM,OAAO,CAAC;AAExC,OAAO,EAAC,iBAAiB,EAAC,MAAM,OAAO,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Credential implementations for the Databricks SDK.
|
|
3
3
|
*/
|
|
4
|
-
export { M2mCredentialsError, U2mCredentialsError } from './errors';
|
|
5
|
-
export type { M2mCredentialsErrorCode, U2mCredentialsErrorCode } from './errors';
|
|
4
|
+
export { M2mCredentialsError, PatCredentialsError, U2mCredentialsError, } from './errors';
|
|
5
|
+
export type { M2mCredentialsErrorCode, PatCredentialsErrorCode, U2mCredentialsErrorCode, } from './errors';
|
|
6
6
|
export { newM2mCredentials } from './m2m';
|
|
7
7
|
export type { M2mCredentialsOptions } from './m2m';
|
|
8
8
|
export { newPatCredentials } from './pat';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/credentials/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/credentials/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAC,iBAAiB,EAAC,MAAM,OAAO,CAAC;AACxC,YAAY,EAAC,qBAAqB,EAAC,MAAM,OAAO,CAAC;AACjD,OAAO,EAAC,iBAAiB,EAAC,MAAM,OAAO,CAAC;AACxC,OAAO,EAAC,iBAAiB,EAAC,MAAM,OAAO,CAAC;AACxC,YAAY,EAAC,qBAAqB,EAAC,MAAM,OAAO,CAAC;AACjD,OAAO,EAAC,kBAAkB,EAAC,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAC,uBAAuB,EAAC,MAAM,kBAAkB,CAAC;AACzD,YAAY,EAAC,2BAA2B,EAAC,MAAM,kBAAkB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Credential implementations for the Databricks SDK.
|
|
3
3
|
*/
|
|
4
|
-
export { M2mCredentialsError, U2mCredentialsError } from './errors';
|
|
4
|
+
export { M2mCredentialsError, PatCredentialsError, U2mCredentialsError, } from './errors';
|
|
5
5
|
export { newM2mCredentials } from './m2m';
|
|
6
6
|
export { newPatCredentials } from './pat';
|
|
7
7
|
export { newU2mCredentials } from './u2m';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/credentials/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/credentials/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,UAAU,CAAC;AAMlB,OAAO,EAAC,iBAAiB,EAAC,MAAM,OAAO,CAAC;AAExC,OAAO,EAAC,iBAAiB,EAAC,MAAM,OAAO,CAAC;AACxC,OAAO,EAAC,iBAAiB,EAAC,MAAM,OAAO,CAAC;AAExC,OAAO,EAAC,kBAAkB,EAAC,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAC,uBAAuB,EAAC,MAAM,kBAAkB,CAAC"}
|
|
@@ -8,7 +8,8 @@ import type { Credentials } from '../auth';
|
|
|
8
8
|
*
|
|
9
9
|
* @param token - The personal access token.
|
|
10
10
|
* @returns Credentials for PAT authentication.
|
|
11
|
-
* @throws
|
|
11
|
+
* @throws PatCredentialsError with code `TOKEN_REQUIRED` if the token is empty
|
|
12
|
+
* after trimming, or `TOKEN_MALFORMED` if it contains internal whitespace.
|
|
12
13
|
*/
|
|
13
14
|
export declare function newPatCredentials(token: string): Credentials;
|
|
14
15
|
//# sourceMappingURL=pat.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pat.d.ts","sourceRoot":"","sources":["../../src/credentials/pat.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAC,WAAW,EAAS,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"pat.d.ts","sourceRoot":"","sources":["../../src/credentials/pat.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAC,WAAW,EAAS,MAAM,SAAS,CAAC;AAIjD;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAc5D"}
|
package/dist/credentials/pat.js
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Personal Access Token (PAT) credentials for the Databricks SDK.
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
* Error thrown when a token is required but not provided.
|
|
6
|
-
*/
|
|
7
|
-
class TokenRequiredError extends Error {
|
|
8
|
-
constructor() {
|
|
9
|
-
super('token is required');
|
|
10
|
-
this.name = 'TokenRequiredError';
|
|
11
|
-
}
|
|
12
|
-
}
|
|
4
|
+
import { PatCredentialsError } from './errors';
|
|
13
5
|
/**
|
|
14
6
|
* Creates a Credentials that can be used to authenticate with a Personal
|
|
15
7
|
* Access Token.
|
|
16
8
|
*
|
|
17
9
|
* @param token - The personal access token.
|
|
18
10
|
* @returns Credentials for PAT authentication.
|
|
19
|
-
* @throws
|
|
11
|
+
* @throws PatCredentialsError with code `TOKEN_REQUIRED` if the token is empty
|
|
12
|
+
* after trimming, or `TOKEN_MALFORMED` if it contains internal whitespace.
|
|
20
13
|
*/
|
|
21
14
|
export function newPatCredentials(token) {
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
const trimmed = token.trim();
|
|
16
|
+
if (trimmed === '') {
|
|
17
|
+
throw new PatCredentialsError('TOKEN_REQUIRED', 'token is required');
|
|
18
|
+
}
|
|
19
|
+
// Internal whitespace would corrupt the header even after trimming, so
|
|
20
|
+
// reject it rather than silently producing a malformed `Bearer` value.
|
|
21
|
+
if (/\s/.test(trimmed)) {
|
|
22
|
+
throw new PatCredentialsError('TOKEN_MALFORMED', 'token must not contain whitespace');
|
|
24
23
|
}
|
|
25
|
-
return new PatCredentials(
|
|
24
|
+
return new PatCredentials(trimmed);
|
|
26
25
|
}
|
|
27
26
|
class PatCredentials {
|
|
28
27
|
token;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pat.js","sourceRoot":"","sources":["../../src/credentials/pat.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH
|
|
1
|
+
{"version":3,"file":"pat.js","sourceRoot":"","sources":["../../src/credentials/pat.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAC,mBAAmB,EAAC,MAAM,UAAU,CAAC;AAE7C;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC7C,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC;QACnB,MAAM,IAAI,mBAAmB,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,CAAC;IACvE,CAAC;IACD,uEAAuE;IACvE,uEAAuE;IACvE,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,mBAAmB,CAC3B,iBAAiB,EACjB,mCAAmC,CACpC,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC;AAED,MAAM,cAAc;IACW;IAA7B,YAA6B,KAAa;QAAb,UAAK,GAAL,KAAK,CAAQ;IAAG,CAAC;IAE9C,IAAI;QACF,OAAO,KAAK,CAAC;IACf,CAAC;IAED,WAAW;QACT,OAAO,OAAO,CAAC,OAAO,CAAC;YACrB,EAAC,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,UAAU,IAAI,CAAC,KAAK,EAAE,EAAC;SACtD,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@databricks/sdk-auth",
|
|
3
|
-
"version": "0.1.0-dev.
|
|
3
|
+
"version": "0.1.0-dev.5",
|
|
4
4
|
"description": "Databricks authentication library for JavaScript/TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -8,28 +8,32 @@
|
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
|
-
"import": "./dist/index.js"
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
12
13
|
},
|
|
13
14
|
"./credentials": {
|
|
14
15
|
"types": "./dist/credentials/index.d.ts",
|
|
15
|
-
"import": "./dist/credentials/index.js"
|
|
16
|
+
"import": "./dist/credentials/index.js",
|
|
17
|
+
"default": "./dist/credentials/index.js"
|
|
16
18
|
},
|
|
17
19
|
"./credentials/browser": {
|
|
18
20
|
"types": "./dist/credentials/index.browser.d.ts",
|
|
19
|
-
"import": "./dist/credentials/index.browser.js"
|
|
21
|
+
"import": "./dist/credentials/index.browser.js",
|
|
22
|
+
"default": "./dist/credentials/index.browser.js"
|
|
20
23
|
},
|
|
21
24
|
"./oidc": {
|
|
22
25
|
"types": "./dist/oidc/index.d.ts",
|
|
23
|
-
"import": "./dist/oidc/index.js"
|
|
26
|
+
"import": "./dist/oidc/index.js",
|
|
27
|
+
"default": "./dist/oidc/index.js"
|
|
24
28
|
},
|
|
25
29
|
"./oidc/browser": {
|
|
26
30
|
"types": "./dist/oidc/index.browser.d.ts",
|
|
27
|
-
"import": "./dist/oidc/index.browser.js"
|
|
31
|
+
"import": "./dist/oidc/index.browser.js",
|
|
32
|
+
"default": "./dist/oidc/index.browser.js"
|
|
28
33
|
}
|
|
29
34
|
},
|
|
30
35
|
"files": [
|
|
31
36
|
"dist",
|
|
32
|
-
"src",
|
|
33
37
|
"LICENSE"
|
|
34
38
|
],
|
|
35
39
|
"scripts": {
|
|
@@ -49,7 +53,7 @@
|
|
|
49
53
|
"node": ">=22.0.0"
|
|
50
54
|
},
|
|
51
55
|
"dependencies": {
|
|
52
|
-
"@databricks/sdk-core": ">=0.1.0-dev.
|
|
56
|
+
"@databricks/sdk-core": ">=0.1.0-dev.6 <1.0.0",
|
|
53
57
|
"zod": "^4.3.6"
|
|
54
58
|
}
|
|
55
59
|
}
|
package/src/auth.ts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Core authentication interfaces and types for the Databricks SDK.
|
|
3
|
-
*
|
|
4
|
-
* This module is not meant to be used directly by consumers of the SDK
|
|
5
|
-
* and is subject to change without notice.
|
|
6
|
-
*
|
|
7
|
-
* @packageDocumentation
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Represents a header that can be used to sign requests.
|
|
12
|
-
*/
|
|
13
|
-
export interface Header {
|
|
14
|
-
key: string;
|
|
15
|
-
value: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Anything that can return authentication headers.
|
|
20
|
-
*/
|
|
21
|
-
export interface Credentials {
|
|
22
|
-
/**
|
|
23
|
-
* Short identifier for the authentication strategy, e.g. `pat` or
|
|
24
|
-
* `oauth-m2m`. Used for logging and for selecting between strategies.
|
|
25
|
-
*/
|
|
26
|
-
name(): string;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Returns headers to authenticate requests.
|
|
30
|
-
*/
|
|
31
|
-
authHeaders(): Promise<Header[]>;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Represents a token that can be used to sign requests.
|
|
36
|
-
*/
|
|
37
|
-
export interface Token {
|
|
38
|
-
/**
|
|
39
|
-
* The raw value to sign requests with.
|
|
40
|
-
* It typically is an access token but can represent other types of tokens
|
|
41
|
-
* (e.g., ID tokens).
|
|
42
|
-
*/
|
|
43
|
-
value: string;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* The type of token. If empty, the token type is assumed to be "Bearer".
|
|
47
|
-
*/
|
|
48
|
-
type?: string;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* The time at which the token expires.
|
|
52
|
-
* If undefined, the token is considered to be valid indefinitely.
|
|
53
|
-
*/
|
|
54
|
-
expiry?: Date;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Anything that can return a token.
|
|
59
|
-
*/
|
|
60
|
-
export interface TokenProvider {
|
|
61
|
-
/**
|
|
62
|
-
* Returns a token or throws an error.
|
|
63
|
-
* The returned Token should be considered immutable and should not be
|
|
64
|
-
* modified.
|
|
65
|
-
*/
|
|
66
|
-
token(): Promise<Token>;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Adapter to allow the use of ordinary functions as TokenProvider.
|
|
71
|
-
*
|
|
72
|
-
* @example
|
|
73
|
-
* const provider = tokenProviderFn(async () => ({ value: 'my-token' }));
|
|
74
|
-
*/
|
|
75
|
-
export function tokenProviderFn(fn: () => Promise<Token>): TokenProvider {
|
|
76
|
-
return {token: fn};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Combines TokenProvider and Credentials interfaces.
|
|
81
|
-
*/
|
|
82
|
-
export interface TokenCredentials extends TokenProvider, Credentials {}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Creates a TokenCredentials that uses the given TokenProvider to return
|
|
86
|
-
* authentication headers.
|
|
87
|
-
*
|
|
88
|
-
* @param name - Short identifier for the auth strategy (e.g. `oauth-m2m`).
|
|
89
|
-
* @param provider - Source of tokens used to build the Authorization header.
|
|
90
|
-
*/
|
|
91
|
-
export function newTokenCredentials(
|
|
92
|
-
name: string,
|
|
93
|
-
provider: TokenProvider
|
|
94
|
-
): TokenCredentials {
|
|
95
|
-
return new TokenCredentialsImpl(name, provider);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
class TokenCredentialsImpl implements TokenCredentials {
|
|
99
|
-
constructor(
|
|
100
|
-
private readonly strategyName: string,
|
|
101
|
-
private readonly provider: TokenProvider
|
|
102
|
-
) {}
|
|
103
|
-
|
|
104
|
-
name(): string {
|
|
105
|
-
return this.strategyName;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
async token(): Promise<Token> {
|
|
109
|
-
return this.provider.token();
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
async authHeaders(): Promise<Header[]> {
|
|
113
|
-
const t = await this.token();
|
|
114
|
-
const scheme = t.type ?? 'Bearer';
|
|
115
|
-
return [{key: 'Authorization', value: `${scheme} ${t.value}`}];
|
|
116
|
-
}
|
|
117
|
-
}
|