paulanthonywilson/basic_auth

Need to be able to exclude actions in a controller

Closed this issue · 4 comments

Currently I will need to have a separate controller if I have some actions which need to be secured and others which don't. It would be great if I could use the same controller for both and differentiate them by an except or only option.

Possible Example:

plug BasicAuth, use_config: { :your_app, :your_key, except: [:index] }

Actually, I think I figured out how do do this myself using the syntax below

plug BasicAuth, [use_config: {: your_app, : your_key}] when not action in [: index]

And to authenticate on only a single action, you can drop the not like so

plug BasicAuth, [use_config: {: your_app, : your_key}] when action in [: delete]

@paulanthonywilson I can submit a PR to add this to the README if you feel it would be of benefit to others? Otherwise I'll just add it to my own personal TIL list for today.

@joelbyler That PR would be great, @joelbyler. Thanks.

(Sorry, only noticed this issue when you mentioned me; I need to get my notifications sorted out.)

@paulanthonywilson please have a look at #17 I'm up for any feedback you have on it. Thanks!