Chapter 18: BasicAuthenticatable with static value

hi @0xtim , if i want to set Basic Authen with static value such as username = “dev” pass “123” how can i setup it?

@0xtim Can you please help with this when you get a chance? Thank you - much appreciated! :]

@choioi do you mean it always works with those values? You’d need to write your own Basic Auth Middleware and use that. Or create a user as a migration with those credentials

do you mean it always works with those values?=> yes , you have example for that?

No unfortunately not. What exactly are you trying to achieve? If you just want those credentials and no user, you can write a custom middleware that just checks the header matches what you expect

1 Like

i dont want user spam call API when register with no authen.so i need static basic authen for non login user…btw thanks you .i think i found which i looking for at chapter 25!

One thing to be aware of is that basic authentication is designed to be used only with logged in user, since you have a username and password as the credentials. If you want to block random attempts at access, you’re better off using an API token (even if it’s hard coded) to protect the routes

1 Like