Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Add Support for Basic Auth? #118

Open
blaineam opened this issue Sep 16, 2024 · 2 comments
Open

Feature Request: Add Support for Basic Auth? #118

blaineam opened this issue Sep 16, 2024 · 2 comments

Comments

@blaineam
Copy link

Would it be possible to implement a server configuration option that implements Basic Auth for all http requests? I know it's not really the most secure method but some authentication is better than no authentication for requests made to the FlyingFox HTTP Server. Something as simple as a configurable user name and password that implements the Basic Auth spec would be nice.

@swhitty
Copy link
Owner

swhitty commented Sep 17, 2024

I think that is a nice idea, this really is just another HTTPHandler that acts as a middleware in-between requests and handlers. It may take me a while to workout exactly how to handle this in a generic way but I have pushed a quick branch that shows how you could easily implement it: basic-auth:

var authRoutes = BasicAuthRoutedHTTPHandler(realm: "fox", username: "fish", password: "chips")
authRoutes.appendRoute("/auth/fish") {
    HTTPResponse(statusCode: .ok,
                 headers: [.contentType: "text/plain; charset=UTF-8"],
                 body: "🎣 🍟".data(using: .utf8)!)
}

// all routes under this path require authentication;
await server.appendRoute("/auth/*", to: authRoutes)

@blaineam
Copy link
Author

Your basic auth branch is working nicely in my app. Had a little bit of trickery with my apps internal web view but was able to find a solution by removing the credential persistence so it re-authenticates every time including right after a credential change and a restart of FlyingFox to immediately start using the new credentials.

Thank you for adding this. Let me know when something like this gets merged back into main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants