require File.expand_path('../setup', __FILE__) module Example class SimpleApp < BaseApp include Warden::GitHub::SSO enable :inline_templates GITHUB_CONFIG = { client_id: ENV['GITHUB_CLIENT_ID'] || 'test_client_id', client_secret: ENV['GITHUB_CLIENT_SECRET'] || 'test_client_secret', scope: 'user' } use Warden::Manager do |config| config.failure_app = BadAuthentication config.default_strategies :github config.scope_defaults :default, config: GITHUB_CONFIG config.serialize_from_session { |key| Warden::GitHub::Verifier.load(key) } config.serialize_into_session { |user| Warden::GitHub::Verifier.dump(user) } end def verify_browser_session if env['warden'].user && !warden_github_sso_session_valid?(env['warden'].user, 10) env['warden'].logout end end get '/' do erb :index end get '/profile' do verify_browser_session env['warden'].authenticate! erb :profile end get '/login' do verify_browser_session env['warden'].authenticate! redirect '/' end get '/logout' do env['warden'].logout redirect '/' end end def self.app @app ||= Rack::Builder.new do run SimpleApp end end end __END__ @@ layout

Simple App Example


<%= yield %> @@ index <% if env['warden'].authenticated? %>

' width='50' height='50' /> Welcome <%= env['warden'].user.name %>

<% else %>

Welcome stranger

<% end %> @@ profile

Profile

Rails Org Member:
<%= env['warden'].user.organization_member?('rails') %>
Publicized Rails Org Member:
<%= env['warden'].user.organization_public_member?('rails') %>
Rails Committer Team Member:
<%= env['warden'].user.team_member?(632) %>
GitHub Site Admin:
<%= env['warden'].user.site_admin? %>
<% if env['warden'].user.using_single_sign_out? %>
GitHub Browser Session ID
<%= env['warden'].user.browser_session_id %>
GitHub Browser Session Valid
<%= warden_github_sso_session_valid?(env['warden'].user, 10) %>
GitHub Browser Session Verified At
<%= Time.at(warden_github_sso_session_verified_at) %>
<% end %>