Skip to content

Commit 17772cf

Browse files
committed
krn-napi-binding: reclassify OAuth token-exchange failures as Unauthenticated
Per src/kernel_error.rs:74-77 doc-comment, Unauthenticated is the intended ErrorCode for "Server returned HTTP 401 (or OIDC discovery rejected the token request)". M2M and U2M token-exchange paths were using Error::io() (-> Internal), which is reserved for kernel-side I/O / parsing failures. The misclassification caused authentication failures to surface in NodeJS as HiveDriverError instead of AuthenticationError (D-015). Fix: m2m.rs:270 and u2m.rs:433 swap Error::io() -> Error::unauthenticated(). No kernel unit tests assert ErrorCode::Internal on these paths (verified by grep) so no test updates are needed. The U2M test `test_u2m_cache_miss_with_expired_refresh` asserts only `result.is_err()`, which remains true. Deferred (worth a follow-up): distinguish oauth2::RequestTokenError subtypes so 5xx token-endpoint failures get NetworkError while invalid_client / invalid_grant / unauthorized_client stay Unauthenticated. The current change correctly handles the dominant case (bad-credentials -> 400/401 from server) and matches the existing kernel doc-comment intent. Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
1 parent 62f6c10 commit 17772cf

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

‎src/auth/oauth/m2m.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl AuthProvider for ClientCredentialsProvider {
287287
.request_async(http_client.inner())
288288
.await
289289
.map_err(|e| {
290-
Error::io()
290+
Error::unauthenticated()
291291
.message(format!("M2M token exchange failed: {}", e))
292292
.context("client credentials grant")
293293
})?;

‎src/auth/oauth/u2m.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ impl AuthProvider for AuthorizationCodeProvider {
447447
.request_async(http_client.inner())
448448
.await
449449
.map_err(|e| {
450-
Error::io()
450+
Error::unauthenticated()
451451
.message(format!("U2M authorization code exchange failed: {}", e))
452452
.context("authorization code grant")
453453
})?;

0 commit comments

Comments
 (0)