Sha256: 2b89981d713f3d82c6407b4fc42a0282dba31ed60e2dbf3e63be5819c7bb2a47

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

module Stoor
  class GithubAuth < Sinatra::Base

    register Sinatra::Auth::Github
    register Mustache::Sinatra

    get '/logout' do
      logout!
      mustache :logout
    end

    get '/sorry' do
      mustache :sorry
    end

    get '/*' do
      session['stoor.github.authorized'] = nil

      pass unless github_options[:client_id] && github_options[:secret]

      pass if request.path_info =~ /\./

      authenticate!
      if stoor_options[:github_team_id]
        github_team_authenticate!(stoor_options[:github_team_id])
      end

      session['stoor.github.authorized'] = 'yes'

      email = nil
      emails = github_user.api.emails
      if stoor_options[:github_email_domain]
        email = emails.find { |e| e =~ /#{stoor_options[:github_email_domain]}/ }
      end
      email ||= emails.first
      session['gollum.author'] = { :name => github_user.name, :email => email }
      pass
    end

    private

    def github_options
      @github_options ||= settings.github_options || {}
    end

    def stoor_options
      @stoor_options ||= settings.stoor_options || {}
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
stoor-0.1.12 lib/stoor/github_auth.rb
stoor-0.1.11 lib/stoor/github_auth.rb
stoor-0.1.9 lib/stoor/github_auth.rb