Module: Perkins::Auth::Github

Defined in:
lib/perkins/auth/github.rb

Defined Under Namespace

Modules: Helpers Classes: AccessDenied, BadAuthentication

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/perkins/auth/github.rb', line 150

def self.registered(app)
  app.use AccessDenied
  app.use BadAuthentication

  app.use Warden::Manager do |manager|
    manager.default_strategies :github

    manager.failure_app     = app.github_options[:failure_app] || BadAuthentication

    manager.scope_defaults :default, :config => {
      :client_id     => app.github_options[:client_id]    || ENV['GITHUB_CLIENT_ID'],
      :client_secret => app.github_options[:secret]       || ENV['GITHUB_CLIENT_SECRET'],
      :scope         => app.github_options[:scopes]       || "admin:repo_hook,repo,user:email",
      :redirect_uri  => app.github_options[:callback_url] || '/auth/github/callback'
    }
  end

  app.helpers Helpers

  app.get '/auth/github/callback' do
    if params["error"]
      redirect "/unauthenticated"
    else
      authenticate!
      return_to = session.delete('return_to') || _relative_url_for('/')
      redirect return_to
    end
  end
end