gitkite 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 08a3be4e5508bc1bf89adf17a8bc607cbe054eeb
4
+ data.tar.gz: 6b0c56f929741b2b82ee4882fe5b8190562e93ca
5
+ SHA512:
6
+ metadata.gz: 78e21a67c5063f907810f79bb9c8db40f0f857fe2ee9d1a69bb10769ba3e0704f58fed3fc2a64073f72a85219d3ebc38d3a099c9064ca2376521d2bf9bf5ee8f
7
+ data.tar.gz: 99d0f4f65c1b10876e3ab67cb2b7489402d5edfa3ca35c4b294822744f7b00515d62ad864bc6f11c0b6a1db29c0ca76aefeea326dfb62cb158bfa1c5a6382969
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Mohan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # Gitkite
2
+ Gitkite is the Rails authentication engine for Google Identity Toolkit (gitkit). It provides all the endpoints and views necessary for gitkit.
3
+
4
+ Google Identity Toolkit (gitkit) - https://developers.google.com/identity/toolkit/
5
+
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'gitkite'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install gitkite
22
+ ```
23
+
24
+ Create a User model with the fields
25
+ ```
26
+ email
27
+ user_id
28
+ name
29
+ photo_url
30
+ provider_id
31
+ ```
32
+
33
+ Add these environment variables (all lowercase).
34
+ ```bash
35
+ export railsappname_p12=$(cat /path-to/xxxxxx.p12 | base64)
36
+ export railsappname_browser_key=xxxxxxxxx
37
+ export railsappname_server_key=xxxxxxxxx
38
+ export railsappname_project_name=xxxxxxxxx
39
+ export railsappname_service_account_email=xxxxxxxxx
40
+ ```
41
+
42
+ You can get the values from Google Developer Console. Instructions can be found here - https://developers.google.com/identity/toolkit/web/configure-service
43
+
44
+ Add these lines to application_controller.rb.
45
+
46
+ ```ruby
47
+ include Gitkite::ApplicationHelper
48
+ helper Gitkite::ApplicationHelper
49
+ ```
50
+
51
+ Add routes to your routes.rb
52
+ ```ruby
53
+ mount Gitkite::Engine, at: "/"
54
+ ```
55
+
56
+ Add the before action to controllers that need authentication
57
+ ```ruby
58
+ before_action :authenticate_user!
59
+ ```
60
+
61
+ To get the current user in a view or controller use -
62
+ ```ruby
63
+ current_user
64
+ ```
65
+
66
+ ## License
67
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Gitkite'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/gitkite .js
2
+ //= link_directory ../stylesheets/gitkite .css
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,7 @@
1
+ module Gitkite
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+
5
+ layout 'application'
6
+ end
7
+ end
@@ -0,0 +1,85 @@
1
+ require 'gitkit_client'
2
+ require_dependency "gitkite/application_controller"
3
+
4
+ module Gitkite
5
+ class GitkitController < ApplicationController
6
+ # Redirect from Gitkit to handle signin callback
7
+ def sign_in_callback
8
+ end
9
+
10
+ # Show sign in form
11
+ def sign_in
12
+ if !request.params['mode']
13
+ redirect_to gitkit_sign_in_url(:params => {:mode=>'select'})
14
+ end
15
+ end
16
+
17
+ # This will be called after successfull signin
18
+ def sign_in_success
19
+ g_user = signed_in?
20
+
21
+ if g_user
22
+ user = {
23
+ :email => g_user.email,
24
+ :user_id => g_user.user_id,
25
+ :name => g_user.name,
26
+ :photo_url => g_user.photo_url,
27
+ :provider_id => g_user.provider_id
28
+ }
29
+
30
+ @user = User.find_by(user_id: user[:user_id])
31
+
32
+ if @user.nil?
33
+ @user = User.create user
34
+ else
35
+ @user.update user
36
+ end
37
+
38
+ session[:user] = @user.id
39
+
40
+ if session[:previous_url]
41
+ previous_url = session[:previous_url]
42
+ session.delete :previous_url
43
+ redirect_to previous_url
44
+ else
45
+ redirect_to main_app.root_url
46
+ end
47
+ else
48
+ @user = false
49
+ session.delete :user
50
+
51
+ flash.alert = "Sign in failed. Please try again."
52
+ redirect_to gitkit_sign_in_url
53
+ end
54
+ end
55
+
56
+ def sign_out
57
+ reset_session
58
+ cookies.delete :gtoken
59
+ redirect_to main_app.root_url
60
+ end
61
+
62
+ def send_email
63
+ end
64
+
65
+ private
66
+ def signed_in?
67
+ gitkit_client = GitkitLib::GitkitClient.new(
68
+ ENV["#{Rails.application.class.parent_name.downcase}_service_account_email"],
69
+ "",
70
+ Base64.decode64(ENV["#{Rails.application.class.parent_name.downcase}_p12"]),
71
+ gitkit_sign_in_callback_url,
72
+ ENV["#{Rails.application.class.parent_name.downcase}_server_key"],
73
+ ENV["#{Rails.application.class.parent_name.downcase}_project_name"]
74
+ )
75
+
76
+ user = gitkit_client.verify_gitkit_token cookies["gtoken"]
77
+
78
+ if user.respond_to? 'user_id'
79
+ user
80
+ else
81
+ false
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,21 @@
1
+ module Gitkite
2
+ module ApplicationHelper
3
+ def current_user
4
+ user_id = session[:user]
5
+
6
+ if(user_id)
7
+ User.find(user_id)
8
+ else
9
+ false
10
+ end
11
+ end
12
+
13
+ def authenticate_user!
14
+ if !current_user
15
+ flash.alert = "Sign in to continue"
16
+ session[:previous_url] = request.fullpath
17
+ redirect_to gitkite.gitkit_sign_in_url
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,4 @@
1
+ module Gitkite
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module Gitkite
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Gitkite
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,39 @@
1
+ <div id="gitkitWidgetDiv"></div>
2
+
3
+ <script type="text/javascript">
4
+ (function($){
5
+ if( window.google && window.google.identitytoolkit ){
6
+ // This approach is needed because turbolinks is active
7
+ // Reload - Only one widget instance can be initialized per page.
8
+ window.location = window.location.href;
9
+ } else {
10
+ $('head').append('<link rel="stylesheet" href="//www.gstatic.com/authtoolkit/css/gitkit.css" type="text/css" />');
11
+ $.ajax({
12
+ url: '//www.gstatic.com/authtoolkit/js/gitkit.js',
13
+ dataType: "script",
14
+ cache: true,
15
+ success: function(){
16
+ start_gitkit_widget();
17
+ }
18
+ });
19
+ }
20
+
21
+ function start_gitkit_widget(){
22
+ var config = {
23
+ "widgetUrl": "<%= gitkit_sign_in_callback_url %>",
24
+ "signInSuccessUrl": "<%= gitkit_sign_in_success_url %>",
25
+ "signOutUrl": "<%= gitkit_sign_out_url %>",
26
+ "oobActionUrl": "<%= gitkit_send_email_url %>",
27
+ "apiKey": "<%= ENV["#{Rails.application.class.parent_name.downcase}_browser_key"] %>",
28
+ "siteName": "<%= Rails.application.class.parent_name %>",
29
+ "signInOptions": ["google", "facebook", "twitter", "microsoft", "yahoo", "password"]
30
+ };
31
+
32
+ // The HTTP POST body should be escaped by the server to prevent XSS
33
+ window.google.identitytoolkit.start(
34
+ '#gitkitWidgetDiv',
35
+ config,
36
+ 'JAVASCRIPT_ESCAPED_POST_BODY');
37
+ }
38
+ })(jQuery);
39
+ </script>
@@ -0,0 +1,18 @@
1
+ <div class='row'>
2
+ <div class='col-sm-6 col-sm-push-3 col-lg-4 col-lg-push-4'>
3
+ <div class="panel panel-default">
4
+ <h4 class="panel-heading" style='margin: 0;'>Enter your email to sign-in / register</h4>
5
+ <div class="panel-body" style="padding:0;">
6
+ <%= render 'sign_in_widget' %>
7
+ </div>
8
+ </div>
9
+
10
+ <div class='alert alert-warning text-center'>
11
+ Note: Name/email from your login will not be used or displayed anywhere.
12
+ </div>
13
+ </div>
14
+ </div>
15
+
16
+ <script type="text/javascript">
17
+ $('body').css({backgroundColor: '#eeeeee'});
18
+ </script>
@@ -0,0 +1 @@
1
+ <%= render 'sign_in_widget' %>
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ Gitkite::Engine.routes.draw do
2
+ get 'sign_in', to: 'gitkit#sign_in', as: 'gitkit_sign_in'
3
+ get 'sign_out', to: 'gitkit#sign_out', as: 'gitkit_sign_out'
4
+ get 'send_email', to: 'gitkit#send_email', as: 'gitkit_send_email'
5
+ get 'sign_in_success', to: 'gitkit#sign_in_success', as: 'gitkit_sign_in_success'
6
+ get 'sign_in_callback', to: 'gitkit#sign_in_callback', as: 'gitkit_sign_in_callback'
7
+ end
data/lib/gitkite.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "gitkite/engine"
2
+
3
+ module Gitkite
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,5 @@
1
+ module Gitkite
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Gitkite
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Gitkite
2
+ VERSION = '0.1.1'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :gitkite do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gitkite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Mohan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.1'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 4.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.1'
33
+ - !ruby/object:Gem::Dependency
34
+ name: identity-toolkit-ruby-client
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.0'
47
+ description: Gitkite is the Rails authentication engine for Google Identity Toolkit
48
+ (gitkit). It provides all the endpoints and views necessary for gitkit.
49
+ email:
50
+ - mohansandesh@gmail.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - MIT-LICENSE
56
+ - README.md
57
+ - Rakefile
58
+ - app/assets/config/gitkite_manifest.js
59
+ - app/assets/javascripts/gitkite/application.js
60
+ - app/assets/stylesheets/gitkite/application.css
61
+ - app/controllers/gitkite/application_controller.rb
62
+ - app/controllers/gitkite/gitkit_controller.rb
63
+ - app/helpers/gitkite/application_helper.rb
64
+ - app/jobs/gitkite/application_job.rb
65
+ - app/mailers/gitkite/application_mailer.rb
66
+ - app/models/gitkite/application_record.rb
67
+ - app/views/gitkite/gitkit/_sign_in_widget.html.erb
68
+ - app/views/gitkite/gitkit/sign_in.html.erb
69
+ - app/views/gitkite/gitkit/sign_in_callback.html.erb
70
+ - config/routes.rb
71
+ - lib/gitkite.rb
72
+ - lib/gitkite/engine.rb
73
+ - lib/gitkite/version.rb
74
+ - lib/tasks/gitkite_tasks.rake
75
+ homepage: https://github.com/mohan999/gitkite
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.5.1
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Rails authentication engine for Google Identity Toolkit (gitkit)
99
+ test_files: []