Module: Sinatra::Geoloqi
- Defined in:
- lib/sinatra/geoloqi.rb
Class Method Summary collapse
-
.registered(app) ⇒ Object
Registers the Geoloqi plugin.
Class Method Details
.registered(app) ⇒ Object
Registers the Geoloqi plugin. This call is required for classy apps which inherit Sinatra::Base, and not required for classic apps.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sinatra/geoloqi.rb', line 7 def self.registered(app) app.enable :sessions unless app.test? app.after do session[:_geoloqi_auth] = @_geoloqi.auth unless session[:_geoloqi_auth].nil? && @_geoloqi.nil? end app.helpers do # Instantiate (or retrieve) the current Geoloqi session. # # @return [Geoloqi::Session] def geoloqi @_geoloqi ||= ::Geoloqi::Session.new :auth => session[:_geoloqi_auth], :config => {:client_id => settings.geoloqi_client_id, :client_secret => settings.geoloqi_client_secret} end # Redirects to Geoloqi OAuth2 authentication if the user is not logged in. Use this to force login for routes. def require_geoloqi_login geoloqi.get_auth(params[:code], settings.geoloqi_redirect_uri) if params[:code] && !geoloqi.access_token? redirect geoloqi.(settings.geoloqi_redirect_uri) unless geoloqi.access_token? end end end |