* Move src under playlet-lib * Update configuration * Update script * Update script * Working version * Vs code config WIP * Package lock sync * Lint fix * Fix images * Reuse config files * Kind of a working setup * Lock node version * Rename scripts to tools * Fix build scripts, lib url system * Lint fix * rale * Fix args and web server * Load fallbacks and build script cleanups * Remove unused method * no message * no message * Remove generic message field * Lint fix * no message * Use loading indicator on main app * Add playlet lib version to settings --------- Co-authored-by: github-action linter <githubaction@githubaction.com>
51 lines
1.4 KiB
Plaintext
51 lines
1.4 KiB
Plaintext
import "pkg:/source/utils/StringUtils.bs"
|
|
|
|
namespace Http
|
|
|
|
class BasicAuthMiddleware extends HttpRouter
|
|
public Username = "playlet"
|
|
public Password = "1234"
|
|
|
|
function new()
|
|
super()
|
|
|
|
m.All("*", function(context as object) as boolean
|
|
router = context.router
|
|
request = context.request
|
|
response = context.response
|
|
|
|
if not router.IsAuthorized(request, router)
|
|
response.headers["WWW-Authenticate"] = `Basic realm="Playlet web app"`
|
|
response.Default(401, "Unauthorized")
|
|
return true
|
|
end if
|
|
|
|
return false
|
|
end function)
|
|
end function
|
|
|
|
function IsAuthorized(request as HttpRequest, router as HttpRouter) as boolean
|
|
authHeader = request.headers["Authorization"]
|
|
if authHeader = invalid
|
|
return false
|
|
end if
|
|
|
|
if not authHeader.StartsWith("Basic ")
|
|
return false
|
|
end if
|
|
|
|
encoded = authHeader.Mid(6)
|
|
decoded = FromBase64(encoded)
|
|
components = decoded.Tokenize(":")
|
|
|
|
if components.Count() = 2
|
|
return components[0] = router.Username and components[1] = router.Password
|
|
end if
|
|
|
|
return false
|
|
end function
|
|
|
|
end class
|
|
|
|
end namespace
|