You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When accessing the API while using JWT auth, the API only recognises the jwt if it is in the query string. Whereas the more normal method of delivering the token - in the Authorization header - is ignored and a 401 issued. Although I have not tested it, I suspect this is true also of METRICS, PLAYBACK and PPROF too.
Describe how to replicate the issue
Conf: set api to yes
Conf: set authMethod to jwt
Follow instructions in README.md to set up keycloak.
Conf: set authJWTJWKS to url for keycloak server
Start the MediaMTX server
Get valid JWT from keycloak
Using your favourite API access tool (have tested with Postman and curl) access the API with Authorization header set eg
I think this problem is already solved for HLS and WebRTC connection. The same strategy could be used here.
On line 162 of internal/servers/hls/http_server.go a function scrapes the Authorization header and adds it to the request query, ready for the JWT auth routine to process.
The function addJWTFromAuthorization id defined in the same file at line 40.
Similar code exists in internal/servers/webrtc/http_server.go at lines 126 and 206. And again the addJWTFromAuthorization function is defined in that file as a copy/paste.
I would suggest that the function addJWTFromAuthorization is centralised, then code similar to above added to internal/api/apo.go, probably in the function middlewareAuth around line 267.
I have not tested it, but suspect similar is required in internal/metric/metrics.go in the function onRequest near line 124; internal/pprof/pprof.go in the function onRequest near line 96; and in internal/playback/server.go in the function doAuth near line 125.
The text was updated successfully, but these errors were encountered:
aler9
changed the title
API: JWT Auth only works with jwt in Query not in Header
API, metrics, pprof: JWT Auth only works with jwt in Query not in Header
Sep 22, 2024
Which version are you using?
v1.8.5
Which operating system are you using?
Describe the issue
When accessing the API while using JWT auth, the API only recognises the jwt if it is in the query string. Whereas the more normal method of delivering the token - in the
Authorization
header - is ignored and a401
issued. Although I have not tested it, I suspect this is true also of METRICS, PLAYBACK and PPROF too.Describe how to replicate the issue
api
toyes
authMethod
tojwt
README.md
to set up keycloak.authJWTJWKS
to url for keycloak serverAuthorization
header set egcurl -v -H "Authorization: Bearer <<YOUR_JWT>>" http://localhost:9997/v3/config/global/get
jwt
query param set egDid you attach the server logs?
no
Did you attach a network dump?
no
Comments
I think this problem is already solved for HLS and WebRTC connection. The same strategy could be used here.
On line 162 of
internal/servers/hls/http_server.go
a function scrapes theAuthorization
header and adds it to the request query, ready for the JWT auth routine to process.The function
addJWTFromAuthorization
id defined in the same file at line 40.Similar code exists in
internal/servers/webrtc/http_server.go
at lines 126 and 206. And again theaddJWTFromAuthorization
function is defined in that file as a copy/paste.I would suggest that the function
addJWTFromAuthorization
is centralised, then code similar to above added tointernal/api/apo.go
, probably in the functionmiddlewareAuth
around line 267.I have not tested it, but suspect similar is required in
internal/metric/metrics.go
in the functiononRequest
near line 124;internal/pprof/pprof.go
in the functiononRequest
near line 96; and ininternal/playback/server.go
in the functiondoAuth
near line 125.The text was updated successfully, but these errors were encountered: