HTTP 401 Unauthorized vs gRPC 16 UNAUTHENTICATED
HTTP 401 and gRPC UNAUTHENTICATED both mean the caller has not provided valid credentials. Despite the misleading name 'Unauthorized' in HTTP, both codes are about authentication (identity), not authorization (permissions).
Beschreibung
The request requires user authentication. The response includes a WWW-Authenticate header indicating the authentication scheme.
Wann Sie es sehen
When accessing a protected resource without credentials or with expired tokens.
Wie man es behebt
Include valid authentication credentials (API key, Bearer token, Basic auth) in the Authorization header.
Beschreibung
The request does not have valid authentication credentials for the operation.
Wann Sie es sehen
No credentials were provided, or the provided token/certificate is expired or invalid. Different from PERMISSION_DENIED (code 7), which means authenticated but not authorized.
Wie man es behebt
Provide valid authentication credentials (e.g., refresh the OAuth token, regenerate the API key, or renew the client certificate).
Wesentliche Unterschiede
HTTP 401 must include a WWW-Authenticate header specifying the authentication scheme; gRPC has no such requirement.
gRPC UNAUTHENTICATED is named more accurately — it clearly means 'not authenticated' rather than the confusing HTTP 'Unauthorized'.
HTTP 401 triggers browser-native authentication dialogs (Basic/Digest); gRPC has no browser-native auth flow.
In gRPC, credentials are typically sent via metadata (similar to HTTP headers) using tokens or certificates.
Both indicate the fix is the same: provide valid credentials (token, API key, certificate).
Wann welchen verwenden
Return HTTP 401 when a request lacks valid credentials — an expired JWT, missing API key, or invalid session cookie. Return gRPC UNAUTHENTICATED for the same reason in RPC calls. When building a gRPC-to-HTTP gateway, map gRPC 16 UNAUTHENTICATED to HTTP 401.