add jellyfin auth
This commit is contained in:
@@ -14,6 +14,22 @@ export default {
|
|||||||
}
|
}
|
||||||
const authorizationHeader = request.headers.get('Authorization').split(' ').pop()
|
const authorizationHeader = request.headers.get('Authorization').split(' ').pop()
|
||||||
const [user, pass] = atob(authorizationHeader).split(':')
|
const [user, pass] = atob(authorizationHeader).split(':')
|
||||||
|
if (env.JELLYFIN_HOST) {
|
||||||
|
const response = await fetch(new URL('/Users/AuthenticateByName', env.JELLYFIN_HOST), {
|
||||||
|
'method': 'POST',
|
||||||
|
'body': JSON.stringify({
|
||||||
|
'Username': user,
|
||||||
|
'Pw': pass
|
||||||
|
}),
|
||||||
|
'headers': {
|
||||||
|
'content-type': 'application/json',
|
||||||
|
'authorization':'MediaBrowser Client="cf-basic-auth", Device="cf-basic-auth", DeviceId="cf-basic-auth", Version="0.0.0"'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (response.ok) {
|
||||||
|
return fetch(request)
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!(user in env) || env[user] !== pass) {
|
if (!(user in env) || env[user] !== pass) {
|
||||||
return deny()
|
return deny()
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-5
@@ -1,7 +1,5 @@
|
|||||||
name = "cf-basic-auth"
|
name = "cf-basic-auth-jellyfin"
|
||||||
main = "src/index.js"
|
main = "src/index.js"
|
||||||
compatibility_date = "2024-12-18"
|
compatibility_date = "2024-12-18"
|
||||||
|
workers_dev=false
|
||||||
#[route]
|
keep_vars=true
|
||||||
#pattern="sub.domain.com/*"
|
|
||||||
#zone_name = "domain.com"
|
|
||||||
Reference in New Issue
Block a user