summaryrefslogtreecommitdiff
path: root/lib/helper.rb
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.de>2009-08-15 13:45:32 +0200
committerChristoph Helma <helma@in-silico.de>2009-08-15 13:45:32 +0200
commit5bf99a0df4e24aef86681814951a9a8c08f5a1e6 (patch)
treef255c26fc0f962030bb21ae951048ae95a79d69f /lib/helper.rb
parent75d79c2f6556b466898e40049058199fabfe6dd2 (diff)
authentification helper added, lazar object added
Diffstat (limited to 'lib/helper.rb')
-rw-r--r--lib/helper.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/helper.rb b/lib/helper.rb
new file mode 100644
index 0000000..a9f451e
--- /dev/null
+++ b/lib/helper.rb
@@ -0,0 +1,26 @@
+helpers do
+
+ # Authentification
+ def protected!
+ response['WWW-Authenticate'] = %(Basic realm="Testing HTTP Auth") and \
+ throw(:halt, [401, "Not authorized\n"]) and \
+ return unless authorized?
+ end
+
+ def authorized?
+ @auth ||= Rack::Auth::Basic::Request.new(request.env)
+ @auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == ['api', API_KEY]
+ end
+
+
+=begin
+ def xml(object)
+ builder do |xml|
+ xml.instruct!
+ object.to_xml
+ end
+ end
+=end
+
+end
+