Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Google openid #98

Open
wants to merge 4 commits into from

2 participants

@madsheep

Hi guys,

This is my 1h work on the main feature that BT was missing for us at netguru - authorization. So this is my really basic version of google apps auth. If you don't mind, i'm going to work on this in the future - i wish to add some real user model, and utilize another omniauth providers. Any feed back and suggestions are welcome!

This is updated version of pull #95, on separate branch.

@unsay

I agree with the omniauth providers. I was also thinking if a user has GitHub access to a a GitHub project, it would display, allowing for some finer-grained access.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 13, 2012
  1. @madsheep
  2. @madsheep

    simple fixes, auth info

    madsheep authored jenkins committed
Commits on Feb 14, 2012
  1. @madsheep

    display some info

    madsheep authored
  2. @madsheep

    stupid testing mistake

    madsheep authored
This page is out of date. Refresh to see the latest.
View
1  .gitignore
@@ -2,6 +2,7 @@
bin/*
log/*.log
tmp/**/*
+tmp/
.DS_Store
*.swp
View
1  .rvmrc
@@ -0,0 +1 @@
+rvm 1.9.3-p0
View
4 Gemfile
@@ -10,6 +10,10 @@ gem "json"
gem "jquery-rails"
gem "thin"
+# for auth purposes
+gem 'omniauth'
+gem 'omniauth-google-apps'
+
# ruby 1.9 compatible version
gem "scashin133-xmpp4r-simple", '0.8.9', :require => 'xmpp4r-simple'
View
19 Gemfile.lock
@@ -65,6 +65,7 @@ GEM
rack (>= 1.1.0, < 2)
ffi (1.0.11)
haml (3.0.25)
+ hashie (1.2.0)
httparty (0.4.5)
crack (>= 0.1.1)
i18n (0.5.0)
@@ -91,11 +92,24 @@ GEM
nokogiri (1.4.4)
notifo (0.1.0)
httparty (~> 0.4.5)
+ omniauth (1.0.2)
+ hashie (~> 1.2)
+ rack
+ omniauth-google-apps (0.0.1)
+ omniauth (~> 1.0)
+ omniauth-openid (~> 1.0)
+ ruby-openid-apps-discovery (~> 1.2.0)
+ omniauth-openid (1.0.1)
+ omniauth (~> 1.0)
+ rack-openid (~> 1.3.1)
open4 (1.0.1)
polyglot (0.3.3)
rack (1.2.5)
rack-mount (0.6.14)
rack (>= 1.0.0)
+ rack-openid (1.3.1)
+ rack (>= 1.1.0)
+ ruby-openid (>= 2.1.8)
rack-test (0.5.7)
rack (>= 1.0)
rails (3.0.11)
@@ -128,6 +142,9 @@ GEM
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby-debug-base19 (>= 0.11.19)
+ ruby-openid (2.1.8)
+ ruby-openid-apps-discovery (1.2.0)
+ ruby-openid (>= 2.1.7)
ruby_core_source (0.1.5)
archive-tar-minitar (>= 0.5.2)
rubyzip (0.9.4)
@@ -188,6 +205,8 @@ DEPENDENCIES
mocha
nokogiri
notifo
+ omniauth
+ omniauth-google-apps
open4
rails (~> 3.0.11)
ruby-debug
View
14 app/controllers/application_controller.rb
@@ -1,4 +1,18 @@
class ApplicationController < ActionController::Base
self.append_view_path("lib/big_tuna/hooks")
protect_from_forgery
+
+ before_filter :gapps_required, :if => proc{ BigTuna.google_apps_domain }
+ helper_method :gapps?
+
+ def gapps_required
+ redirect_to '/auth/gapps' unless gapps?
+ end
+
+ private
+
+ def gapps?
+ session[:gapps_user].present?
+ end
+
end
View
1  app/controllers/hooks_controller.rb
@@ -1,5 +1,6 @@
class HooksController < ApplicationController
skip_before_filter :verify_authenticity_token
+ skip_before_filter :gapps_required, :only => [:autobuild, :github, :bitbucket]
def autobuild
project = Project.where(:hook_name => params[:hook_name]).first
View
17 app/controllers/sessions_controller.rb
@@ -0,0 +1,17 @@
+class SessionsController < ApplicationController
+
+ skip_before_filter :gapps_required
+
+ def authenticate_gapps
+ auth_hash = request.env['omniauth.auth']
+ session[:gapps_user] = auth_hash['info'].try(:[], 'email')
+
+ if gapps?
+ redirect_to '/'
+ else
+ render :text => '401 Unauthorized', :status => 401
+ end
+
+ end
+
+end
View
9 app/views/layouts/application.html.haml
@@ -14,13 +14,18 @@
.navbar.navbar-fixed-top
.navbar-inner
.container
- = link_to("BigTuna", "http://bigtuna.appelier.com", :target => "_blank", :title => "BigTuna v#{BigTuna::VERSION}", :class => "brand")
- %span.brand.hint checked with
%ul.nav
%li
= link_to("Projects", root_path)
= yield :topbar
+ .pull-right
+ = link_to("BigTuna", "http://bigtuna.appelier.com", :target => "_blank", :title => "BigTuna v#{BigTuna::VERSION}", :class => "brand")
+ %span.brand.hint checked with
+ -if gapps?
+ %span.brand.hint.user_name #{session[:gapps_user]}
+
+
.container
= flash[:error]
View
2  config/bigtuna.yml.sample
@@ -5,3 +5,5 @@
# ajax_reload: false # "building" or "always"
# build_dir: "tmp" # default: "builds"
# log: "log/bigtuna.log" # default: use Rails log
+# google_apps_domain: example.com # default: nil
+
View
5 config/initializers/omniauth.rb
@@ -0,0 +1,5 @@
+Rails.application.config.middleware.use OmniAuth::Builder do
+
+ provider :google_apps, :domain => BigTuna.google_apps_domain, :name =>
+'gapps'
+end if BigTuna.google_apps_domain
View
4 config/routes.rb
@@ -18,6 +18,10 @@
end
+ if BigTuna.google_apps_domain
+ match '/auth/gapps/callback', :to => 'sessions#authenticate_gapps'
+ end
+
match "/hooks/build/:hook_name", :to => "hooks#autobuild"
match "/hooks/build/github/:secure", :to => "hooks#github"
match "/hooks/build/bitbucket/:secure", :to => "hooks#bitbucket"
View
2  lib/big_tuna.rb
@@ -18,7 +18,7 @@ def config
@config = config.symbolize_keys!
end
- [:ajax_reload, :github_secure, :log, :bitbucket_secure, :build_dir, :read_only].each do |key|
+ [:google_apps_domain, :ajax_reload, :github_secure, :log, :bitbucket_secure, :build_dir, :read_only].each do |key|
define_method key do
config[key]
end
View
4 public/stylesheets/master_new.css
@@ -110,6 +110,10 @@ h1.project-title {
margin-top: 6px;
}
+.navbar-fixed-top .user_name {
+ margin-right: 10px;
+}
+
.navbar-fixed-top a.brand:hover {
text-shadow: 0 1px 0 rgba(255, 255, 255, .1), 0 0 30px rgba(255, 255, 255, .125);
color: #fff;
View
13 test/integration/autobuild_test.rb
@@ -35,6 +35,19 @@ class AutobuildTest < ActionController::IntegrationTest
end
end
+ test "dont care about google_apps domain config" do
+ with_config(:google_apps_domain, "somedomain.com") do
+ project1 = github_project(:name => "obywatelkagc", :vcs_branch => "master")
+ with_github_token do
+ assert_difference("project1.builds.count", +1) do
+ post "/hooks/build/github/#{@token}", :payload => github_payload(project1)
+ assert_status_code(200)
+ assert response.body.include?(%{build for the following projects were triggered: "#{project1.name}"})
+ end
+ end
+ end
+ end
+
test "build all projects that match name and branch specified by github" do
project1 = github_project(:name => "obywatelgc", :vcs_branch => "master")
project2 = github_project(:name => "obywatelgc2", :vcs_branch => "master")
View
12 test/integration/google_apps_auth_test.rb
@@ -0,0 +1,12 @@
+require "integration_test_helper"
+
+class GoogleAppsAuth < ActionController::IntegrationTest
+
+ test "with google apps domain in config accesing root" do
+ with_config(:google_apps_domain, "somedomain.com") do
+ get "/"
+ assert_redirected_to "http://www.example.com/auth/gapps"
+ end
+ end
+
+end
Something went wrong with that request. Please try again.