Sha256: 4ba65dbe4326c8a26967725fb3bf6da01b1b9316e49cc0071ef265728b600788

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

require 'pp'

module Example
  class App < Sinatra::Base
    enable :sessions

    set :github_options, {
                            :secret    => ENV['GITHUB_CLIENT_SECRET'],
                            :client_id => ENV['GITHUB_CLIENT_ID'],
                            :scopes    => 'user,offline_access,repo' # repo is need for org auth :\
                          }

    register Sinatra::Auth::Github

    helpers do
      def repos
        github_request("user/repos")
      end
    end

    get '/' do
      authenticate!
      "Hello There, #{github_user.name}!#{github_user.token}\n#{repos.inspect}"
    end

    get '/orgs/:id' do
      github_organization_authenticate!(params['id'])
      "Hello There, #{github_user.name}! You have access to the #{params['id']} organization."
    end

    get '/teams/:id' do
      github_team_authenticate!(params['id'])
      "Hello There, #{github_user.name}! You have access to the #{params['id']} team."
    end

    get '/logout' do
      logout!
      redirect 'https://github.com'
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sinatra_auth_github-0.1.4 spec/app.rb
sinatra_auth_github-0.1.3 spec/app.rb
sinatra_auth_github-0.1.2 spec/app.rb