Skip to content
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
7 changes: 7 additions & 0 deletions napi/NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ layout, or npm publishing. Pure-kernel changes go in the root
encrypted PKCS#8 keys), and `jwtAlgorithm` (optional, default `RS256`), alongside
the existing `oauthClientId` / `oauthScopes`. Forwards to the kernel's
`AuthConfig::OAuthM2MPrivateKey`.
- `ConnectionOptions.tokenUrl` — OAuth token endpoint override. When omitted the
kernel discovers the endpoint via the workspace's OIDC configuration; set it to
point the client-credentials / JWT client-assertion grant at the workspace's
configured IdP token endpoint (e.g. Entra ID for Azure Databricks). Required for
`AuthMode.OAuthM2mJwt` against an external-IdP-backed workspace, since
Databricks-native OIDC does not advertise the `private_key_jwt` method. Applies to
`AuthMode.OAuthM2m` too. Forwards to the kernel's `token_url_override`.
- `ConnectionOptions.identityFederationClientId` selects SP-wide Workload
Identity Federation during mandatory token exchange.

Expand Down
9 changes: 9 additions & 0 deletions napi/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,15 @@ export interface ConnectionOptions {
* (`["all-apis"]` for M2M; `["sql", "offline_access"]` for U2M).
*/
oauthScopes?: Array<string>
/**
* OAuth token endpoint override. When omitted the kernel discovers the
* endpoint via the workspace's OIDC configuration. Set it to point the
* client-credentials / JWT client-assertion grant at the workspace's
* configured IdP token endpoint (e.g. Entra ID for Azure Databricks),
* which is required when that IdP — not Databricks-native OIDC — is the
* authority for [`AuthMode::OAuthM2m`] / [`AuthMode::OAuthM2mJwt`].
*/
tokenUrl?: string
/**
* Path to the PEM private-key file. Required for
* [`AuthMode::OAuthM2mJwt`].
Expand Down
16 changes: 14 additions & 2 deletions napi/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ pub struct ConnectionOptions {
/// OAuth scopes override (M2M / U2M). Omitted ⇒ kernel defaults
/// (`["all-apis"]` for M2M; `["sql", "offline_access"]` for U2M).
pub oauth_scopes: Option<Vec<String>>,
/// OAuth token endpoint override. When omitted the kernel discovers the
/// endpoint via the workspace's OIDC configuration. Set it to point the
/// client-credentials / JWT client-assertion grant at the workspace's
/// configured IdP token endpoint (e.g. Entra ID for Azure Databricks),
/// which is required when that IdP — not Databricks-native OIDC — is the
/// authority for [`AuthMode::OAuthM2m`] / [`AuthMode::OAuthM2mJwt`].
pub token_url: Option<String>,
/// Path to the PEM private-key file. Required for
/// [`AuthMode::OAuthM2mJwt`].
pub jwt_key_file: Option<String>,
Expand Down Expand Up @@ -361,7 +368,7 @@ fn build_auth_config(options: &ConnectionOptions) -> napi::Result<AuthConfig> {
options.oauth_client_id.clone(),
options.oauth_client_secret.clone(),
options.oauth_scopes.clone(),
None,
options.token_url.clone(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Low — The OAuthM2m path also changed from hardcoded None to options.token_url.clone(), but only the JWT (OAuthM2mJwt) test was extended to assert the override reaches token_url_override. The m2m_requires_client_id_and_secret test (lines 734-763) sets oauth_scopes/identity_federation_client_id and matches on AuthConfig::OAuthM2M { .. } asserting only scopes — it never sets token_url nor asserts it is threaded through. So the M2M half of this change is untested. Consider setting o.token_url and asserting token_url_override in the M2M test too, mirroring the JWT test, to guard against a future regression in argument order on that call site.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Low — The token_url override is now threaded into both the OAuthM2m and OAuthM2mJwt paths, but only the JWT path (OAuthM2MPrivateKey) gained a test asserting the value reaches token_url_override. The plain AuthMode.OAuthM2m path here is left without coverage for the new argument, so a future regression (e.g. reverting to None or swapping it with identity_federation_client_id) on the M2M branch would not be caught. Consider extending the M2M build_auth_config test to assert token_url_override as well.

options.identity_federation_client_id.clone(),
)
.map_err(napi_err_from_kernel),
Expand All @@ -376,7 +383,7 @@ fn build_auth_config(options: &ConnectionOptions) -> napi::Result<AuthConfig> {
options.jwt_passphrase.clone(),
options.jwt_algorithm.clone(),
options.oauth_scopes.clone(),
None,
options.token_url.clone(),
)
.map_err(napi_err_from_kernel),
// napi injects no client_id/scope default: it rides the kernel's
Expand Down Expand Up @@ -632,6 +639,7 @@ mod tests {
oauth_client_secret: None,
oauth_redirect_port: None,
oauth_scopes: None,
token_url: None,
jwt_key_file: None,
jwt_kid: None,
jwt_passphrase: None,
Expand Down Expand Up @@ -765,6 +773,8 @@ mod tests {
o.jwt_passphrase = Some("pass".to_owned());
o.jwt_algorithm = Some("ES256".to_owned());
o.oauth_scopes = Some(vec!["all-apis".to_owned()]);
let token_url = "https://idp.example/token";
o.token_url = Some(token_url.to_owned());
match build_auth_config(&o).unwrap() {
AuthConfig::OAuthM2MPrivateKey {
client_id,
Expand All @@ -773,6 +783,7 @@ mod tests {
jwt_passphrase,
jwt_algorithm,
scopes,
token_url_override,
..
} => {
assert_eq!(client_id, "cid");
Expand All @@ -781,6 +792,7 @@ mod tests {
assert_eq!(jwt_passphrase.as_deref(), Some("pass"));
assert_eq!(jwt_algorithm.as_deref(), Some("ES256"));
assert_eq!(scopes, Some(vec!["all-apis".to_owned()]));
assert_eq!(token_url_override.as_deref(), Some(token_url));
}
other => panic!("expected OAuthM2MPrivateKey, got {other:?}"),
}
Expand Down
Loading