knock
knock copied to clipboard
Fix security flaw and add Soft(optional) authentication feature
Hi, here are my modifications in detail
- Security flaw in authenticate_for.
-
Using authenticate_for directly for namespaced models(any model actually) doesn't send back an Unauthorized header when an invalid/no token is sent as authenticate_for doesn't check for that.
-
I added wrapper functions
set_authenticate_for
andset_soft_authenticated_for
to fix that issue for strict and optional authentications respectively.
- Soft (Optional) Authentication
-
Some controllers may not require authentication but acts slightly different if authenticated. Example: It may add extra(private or user-specific) values to JSON response if authenticated.
-
Modified
method_missing
inauthenticable.rb
to accept thesoft_authenticate_<entity>
method to implement said behaviour. -
Also added
set_soft_authenticate_for
for same functionality as explained in 1.
-
Added tests to ensure changes are working
-
Updated README
- Updated readme to reflect changes