lib/hadley/middleware.rb in hadley-0.0.2 vs lib/hadley/middleware.rb in hadley-0.0.3

- old
+ new

@@ -1,23 +1,26 @@ +# This class provides the rack middleware that builds on top of warden to provide the necessary endpoints for a rack +# application to function as an AFID protected resource. class Hadley::Middleware < Sinatra::Base include Hadley::Authz - attr_reader :confg - + # Initializes the middleware with the provided application and options + # + # @param [Rack::Application] app The rack application that this middleware is participating in + # @param [Hash] options The Hash of keyword arguments + # @param [Hadley::TokenStore] options.store The token store to be used for persisting tokens provisioned by the AFID + # authorization server def initialize(app=nil, options={}) super(app) @config ||= Hadley::Config.new(options) yield @config if block_given? @tokens = @config.token_store self end - # ------------------------------------------ - # Routes - # ------------------------------------------ - + # The required endpoint for provisioning AFID access tokens. put '/access/tokens/:token' do |token| warden.authenticate!(:afid_server) begin @tokens.put(token, Integer(params.fetch('expires_in')), identity: params.fetch('identity'), @@ -28,9 +31,10 @@ status 400 body e.to_s end end + # The required endpoint for invalidating AFID access tokens. delete '/access/tokens/:token' do |token| warden.authenticate!(:afid_server) begin @tokens.delete(token) body 'Token Deleted'