Sha256: 3838b04b27e32efc41a1f5f959fccee62d88ebda574d2fe6f22c4f3ae3e6fb03

Contents?: true

Size: 952 Bytes

Versions: 4

Compression:

Stored size: 952 Bytes

Contents

require 'pp'
require 'ruby-debug'

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.login}!"
    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.5.3 spec/app.rb
sinatra_auth_github-0.5.2 spec/app.rb
sinatra_auth_github-0.5.1 spec/app.rb
sinatra_auth_github-0.5.0 spec/app.rb