Sha256: 18dc08dc81aec2de6a2032448e875459baaca54ce645e68888eb1ab62dad6fb2
Contents?: true
Size: 1.37 KB
Versions: 1
Compression:
Stored size: 1.37 KB
Contents
require 'sinatra' module Example class App < Sinatra::Base enable :sessions enable :raise_errors disable :show_exceptions use Warden::Manager do |manager| manager.default_strategies :oauthed manager.failure_app = BadAuthentication manager[:oauthed_client_id] = ENV['APPLICATION_CLIENT_ID'] manager[:oauthed_secret] = ENV['APPLICATION_CLIENT_SECRET'] manager[:oauthed_scopes] = ENV['APPLICATION_SCOPES_REQUESTED'] manager[:oauthed_oauth_domain] = ENV['OAUTH_BASE_URL'] manager[:oauthed_callback_url] = '/auth/oauthed/callback' end helpers do def ensure_authenticated throw(:warden) unless env['warden'].authenticate! end def user env['warden'].user end end get '/' do ensure_authenticated "Hello There,\n<pre>#{user.token}</pre>" end get '/redirect_to' do ensure_authenticated "Hello There, #{user.name}! return_to is working!" end get '/auth/oauthed/callback' do ensure_authenticated redirect '/' end get '/logout' do env['warden'].logout 'Peace!' end end class BadAuthentication < Sinatra::Base get '/unauthenticated' do status 403 'Unable to authenticate, sorry bud.' end end def self.app @app ||= Rack::Builder.new do run App end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
warden-oauthed-0.0.4 | spec/app.rb |