26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/roda/plugins/token_auth.rb', line 26
def token_auth(opts = {}, &authenticator)
auth_opts = roda_class.opts[:token_auth].merge(opts)
authenticator ||= auth_opts[:authenticator]
raise "Must provide an authenticator block" if authenticator.nil?
auth_token = (auth_opts, :token_variable)
auth_secret = (auth_opts, :secret_variable)
return if authenticator.call(auth_token, auth_secret)
auth_opts[:unauthorized]&.call(self)
halt [401,
auth_opts[:unauthorized_headers].call(auth_opts),
[auth_opts[:unauthorized_body].call(auth_opts).to_json]]
end
|