From 0268843c29fca51c73343a40ad70401c0ac72238 Mon Sep 17 00:00:00 2001 From: FengbinShi Date: Thu, 11 Jan 2024 16:57:47 +0800 Subject: [PATCH] feat: TokenFileName --- websockify/token_plugins.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/websockify/token_plugins.py b/websockify/token_plugins.py index d42414e..24c3943 100644 --- a/websockify/token_plugins.py +++ b/websockify/token_plugins.py @@ -65,6 +65,19 @@ class TokenFile(ReadOnlyTokenFile): return super().lookup(token) +class TokenFileName(BasePlugin): + def __init__(self, src): + super().__init__(src) + if not os.path.isdir(src): + raise Exception("TokenFileName plugin requires a directory") + + def lookup(self, token): + path = os.path.join(self.source, token) + if os.path.exists(path): + return open(path).read().strip().split(':') + else: + return None + class BaseTokenAPI(BasePlugin): # source is a url with a '%s' in it where the token