Sha256: 207dba94feb81789e8603ff6915d1f996945deae9bd90640fcfbe44cee11011b

Contents?: true

Size: 1.61 KB

Versions: 3

Compression:

Stored size: 1.61 KB

Contents

require 'pp'

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

    set  :github_options, {
                            # GitHub Provided secrets
                            :secret       => ENV['GITHUB_CLIENT_SECRET'],
                            :client_id    => ENV['GITHUB_CLIENT_ID'],

                            # How much info you need about the user
                            :scopes       => 'user,offline_access,repo',

                            # restrict access to a members of organization named
                            :organization => "github",

                            # restrict access to specific team on an organization
                            :team         => nil # || 42
                           }

    register Sinatra::Auth::Github

    before do
      # authenticate!
      # halt([401, "Unauthorized User"]) unless github_organization_member?
    end

    helpers do
      def repos
        github_request("repos/show/#{github_user.login}")
      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 '/orgs/:org_id/team/:id' do
      github_organization_team_authenticate!(params['org_id'], params['id'])
      "Hello There, #{github_user.name}! You have access to the #{params['id']} team under the #{params['org_id']} organization."
    end

    get '/logout' do
      logout!
      redirect '/'
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sinatra_auth_github-0.0.16 spec/app.rb
sinatra_auth_github-0.0.15 spec/app.rb
sinatra_auth_github-0.0.14 spec/app.rb