Import path:Documentation Index
Fetch the complete documentation index at: https://mintlify.com/bluenviron/gortsplib/llms.txt
Use this file to discover all available pages before exploring further.
github.com/bluenviron/gortsplib/v5/pkg/auth
Overview
pkg/auth provides two complementary helpers:
Sender— client-side: reads aWWW-Authenticatechallenge from the server and adds anAuthorizationheader to outgoing requests.Verify— server-side: validates theAuthorizationheader on an incoming request against a known username and password.
GenerateNonce and GenerateWWWAuthenticate, support server
implementations that need to issue challenges.
Supported authentication methods
VerifyMethod constant | Method | Algorithm |
|---|---|---|
VerifyMethodBasic | Basic | — |
VerifyMethodDigestMD5 | Digest | MD5 |
VerifyMethodDigestSHA256 | Digest | SHA-256 |
VerifyMethodDigestSHA256 is not included in the default method set because it
prevents FFmpeg from authenticating. Enable it explicitly when your clients support it.methods is nil in Verify or GenerateWWWAuthenticate, the default set is
{VerifyMethodBasic, VerifyMethodDigestMD5}.
Sender
Sender is used by RTSP clients to respond to a WWW-Authenticate challenge.
Fields
The raw
WWW-Authenticate header value received from the server’s 401 Unauthorized
response. May contain multiple challenge entries (one per element of the slice).The username to authenticate with.
The password to authenticate with.
Methods
Initialize
WWWAuth header and selects the strongest available authentication method.
Priority order: Digest SHA-256 > Digest MD5 > Basic. Returns an error if no recognized
authentication method is found.
Must be called once before AddAuthorization.
AddAuthorization
Authorization header to req, computed for the request’s method and URL.
For Digest authentication the response hash is recomputed on every call, so the same
Sender instance can be reused across multiple requests in the same session.
Verify
Verify is a standalone function used by RTSP servers to validate an incoming request.
Parameters
The incoming RTSP request whose
Authorization header is to be validated.Expected username.
Expected password.
Allowed authentication methods. Pass
nil to use the default set
(VerifyMethodBasic + VerifyMethodDigestMD5).The realm string used when generating the original
WWW-Authenticate challenge.The nonce string used when generating the original
WWW-Authenticate challenge.
Generate one with GenerateNonce.nil on success, or a non-nil error describing why authentication failed.
GenerateNonce
GenerateWWWAuthenticate and store it
for later use in Verify.
GenerateWWWAuthenticate
WWW-Authenticate header value to include in a 401 Unauthorized response.
One challenge entry is added per method in methods. Pass nil for methods to use
the default set.
Server-side example
Handling authentication challenges in a server:Client-side example
Responding to a401 Unauthorized challenge:
The higher-level
ServerConn type exposes a VerifyCredentials convenience method
that wraps Verify and nonce management. Use pkg/auth directly only when you need
fine-grained control over the authentication flow.