class Gemstash::ApiKeyAuthorization
Authorize actions via an API key and Gemstash::Authorization
.
Public Class Methods
new(key)
click to toggle source
# File lib/gemstash/api_key_authorization.rb, line 8 def initialize(key) @key = key end
protect(app) { || ... }
click to toggle source
# File lib/gemstash/api_key_authorization.rb, line 12 def self.protect(app, &block) key = parse_authorization(app.request.env) app.auth = new(key) yield rescue Gemstash::NotAuthorizedError => e app.headers["WWW-Authenticate"] = "Basic realm=\"Gemstash Private Gems\"" app.halt 401, e.message end
Public Instance Methods
check(permission)
click to toggle source
# File lib/gemstash/api_key_authorization.rb, line 28 def check(permission) Gemstash::Authorization.check(@key, permission) end