Support paired security requirements - e.g. basic and apiKey

This commit is contained in:
domaindrivendev
2017-08-21 01:07:47 -07:00
parent d91601b02c
commit ad9cd5de66
8 changed files with 155 additions and 38 deletions

View File

@@ -2,10 +2,29 @@ class AuthTestsController < ApplicationController
# POST /auth-tests/basic
def basic
if authenticate_with_http_basic { |u, p| u == 'jsmith' && p == 'jspass' }
head :no_content
else
request_http_basic_authentication
end
return head :unauthorized unless authenticate_basic
head :no_content
end
# POST /auth-tests/api-key
def api_key
return head :unauthorized unless authenticate_api_key
head :no_content
end
# POST /auth-tests/basic-and-api-key
def basic_and_api_key
return head :unauthorized unless authenticate_basic and authenticate_api_key
head :no_content
end
private
def authenticate_basic
authenticate_with_http_basic { |u, p| u == 'jsmith' && p == 'jspass' }
end
def authenticate_api_key
params['api_key'] == 'foobar'
end
end