Sha256: 19791f57d3e1deec40a44ab5cf2ac5c470e9e30a4f7b93313ed5fafb7cb2b5ad

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 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'],
                         }

    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_public_organization_authenticate!(params['id'])
      "Hello There, #{github_user.name}! You have access to the #{params['id']} organization."
    end

    # the scopes above need to include repo for team access :(
    # 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

4 entries across 4 versions & 1 rubygems

Version Path
sinatra_auth_github-0.3.0 spec/app.rb
sinatra_auth_github-0.2.1 spec/app.rb
sinatra_auth_github-0.2.0 spec/app.rb
sinatra_auth_github-0.1.5 spec/app.rb