cloudhdr_auth 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 423683423008a20547d2c2d5fa76a773a1769b47
4
+ data.tar.gz: 5e09beb46b0ba6de52303cf20366d72dae4ba674
5
+ SHA512:
6
+ metadata.gz: 9738a979dc4e0bf7a33405517f69d610c860b56552df0848b114860b51541736c083e2c2d570a6e8cd4896a30d93d686fb37ef118dba5b9ba17431e81d593d23
7
+ data.tar.gz: bc89b321772ef73eb5b96f3694a6d585f599deac3f350dbf9526ad694828cd1003f184f6b3ebeda66bfe25f1366f1f5bc59e7420a4bb1a8c8e0ec6d9d82d733d
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
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,79 @@
1
+ CloudhdrAuth
2
+ ==============
3
+
4
+ ## Setup the `Gemfile`
5
+
6
+ ```ruby
7
+ gem 'cloudhdr_auth', :git => 'need to figure out the private gem thing'
8
+ ```
9
+
10
+ ## Setup `config/environment.rb` to load constants
11
+
12
+ Add this just before `MyApp::Application.initialize!`
13
+
14
+ ```ruby
15
+ Dir.glob( "config/constants/*" ).each do |file|
16
+ Kernel.const_set File.basename(file, ".yml").upcase, YAML::load_file(File.join(Rails.root, file))[Rails.env]
17
+ end
18
+
19
+ require 'omniauth/strategies/cloudhdr'
20
+ ```
21
+
22
+ ## Create the `auth_provider.yml` constant file
23
+
24
+ Put this in `config/constants/auth_provider.yml`
25
+
26
+ Alter the URL as needed, and make sure that the app_id and app_secret
27
+ are registerd with the provider located at the URL. It's best to have a
28
+ unique id and secret for each app and env.
29
+
30
+ ```
31
+ development:
32
+ url: http://localhost:3000
33
+ app_id: testid
34
+ app_secret: testsecret
35
+ test:
36
+ staging:
37
+ production:
38
+ ```
39
+
40
+ ## Create an `omniauth.rb` initializer
41
+
42
+ Put this in `config/initializers/omniauth.rb`
43
+
44
+ ```ruby
45
+ # Change this omniauth configuration to point to your registered provider
46
+ # Since this is a registered application, add the app id and secret here
47
+ APP_ID = AUTH_PROVIDER['app_id']
48
+ APP_SECRET = AUTH_PROVIDER['app_secret']
49
+
50
+ Rails.application.config.middleware.use OmniAuth::Builder do
51
+ provider :cloudhdr, APP_ID, APP_SECRET
52
+ end
53
+ ```
54
+
55
+ ## Create a `User` model
56
+
57
+ The `User` model should use `binary` for the id
58
+
59
+ ```bash
60
+ create_table :users, :id => false do |t|
61
+ t.binary :id, :primary => true, :null => false
62
+ t.timestamps
63
+ end
64
+ add_index :users, :id, :unique => true
65
+ ```
66
+
67
+ ## Update `ApplicationController`
68
+
69
+ The first line should look like this
70
+
71
+ ```ruby
72
+ class ApplicationController < CloudhdrAuth::BaseController
73
+ ```
74
+
75
+ ## Protect some stuff
76
+
77
+ ```ruby
78
+ before_filter :login_required
79
+ ```
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'CloudhdrAuth'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
@@ -0,0 +1,44 @@
1
+ class CloudhdrAuth::BaseController < ActionController::Base
2
+ protect_from_forgery
3
+
4
+ before_filter :check_cookie
5
+ def check_cookie
6
+ if cookies[:cloudhdr_auth].nil? && session[:user_id].present?
7
+ session[:user_id] = nil
8
+ not_authorized
9
+ elsif cookies[:cloudhdr_auth].present? && session[:user_id].present? && cookies[:cloudhdr_auth] != session[:user_id]['uid']
10
+ session[:user_id] = nil
11
+ not_authorized
12
+ end
13
+ end
14
+
15
+ def login_required
16
+ if !current_user
17
+ not_authorized
18
+ end
19
+ end
20
+
21
+ def not_authorized
22
+ respond_to do |format|
23
+ format.html{ auth_redirect }
24
+ format.json{ head :unauthorized }
25
+ end
26
+ end
27
+
28
+ def auth_redirect
29
+ redirect_to "/auth/cloudhdr?origin=#{request.protocol}#{request.host_with_port}#{request.fullpath}"
30
+ end
31
+
32
+ def current_user
33
+ return nil unless session[:user_id]
34
+ @current_user ||= User.find_by_id(session[:user_id]['uid'])
35
+ end
36
+
37
+ def signed_in?
38
+ current_user.present?
39
+ end
40
+
41
+ helper_method :signed_in?
42
+ helper_method :current_user
43
+
44
+ end
@@ -0,0 +1,47 @@
1
+ class CloudhdrAuth::UserSessionsController < CloudhdrAuth::BaseController
2
+ before_filter :login_required, :only => [ :destroy ]
3
+
4
+ #respond_to :html
5
+
6
+ # omniauth callback method
7
+ def create
8
+ omniauth = env['omniauth.auth']
9
+ logger.debug "+++ #{omniauth}"
10
+
11
+ user = User.find_by_id(omniauth['uid'])
12
+ if not user
13
+ # New user registration
14
+ user = User.new
15
+ # avoid trouble with attr_accessible
16
+ user.id = omniauth['uid']
17
+ end
18
+ user.current_sign_in_at = omniauth['extra']['current_sign_in_at'] if user.respond_to?(:current_sign_in_at)
19
+ user.name = omniauth['extra']['name'] if user.respond_to?(:name)
20
+ #user.first_name = omniauth['extra']['first_name']
21
+ #user.last_name = omniauth['extra']['last_name']
22
+ user.save!
23
+
24
+ #p omniauth
25
+
26
+ # Currently storing all the info
27
+ session[:user_id] = omniauth
28
+
29
+ flash[:notice] = "Successfully logged in"
30
+ redirect_to request.env['omniauth.origin'] || root_path
31
+ end
32
+
33
+ # Omniauth failure callback
34
+ def failure
35
+ flash[:notice] = params[:message]
36
+ end
37
+
38
+ # logout - Clear our rack session BUT essentially redirect to the provider
39
+ # to clean up the Devise session from there too !
40
+ def destroy
41
+ session[:user_id] = nil
42
+
43
+ flash[:notice] = 'You have successfully signed out!'
44
+ redirect_to "#{CUSTOM_PROVIDER_URL}/users/sign_out"
45
+ end
46
+
47
+ end
@@ -0,0 +1,8 @@
1
+ <%
2
+ rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
3
+ rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
4
+ std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
5
+ %>
6
+ default: <%= std_opts %> features
7
+ wip: --tags @wip:3 --wip features
8
+ rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
data/config/routes.rb ADDED
@@ -0,0 +1,11 @@
1
+ Rails.application.routes.draw do
2
+
3
+ # omniauth
4
+ match '/auth/:provider/callback', :to => 'cloudhdr_auth/user_sessions#create', via: [:get, :post]
5
+ match '/auth/failure', :to => 'cloudhdr_auth/user_sessions#failure', via: [:get, :post]
6
+
7
+ # Custom logout
8
+ match '/logout', :to => 'cloudhdr_auth/user_sessions#destroy', via: [:get, :post]
9
+
10
+ end
11
+
@@ -0,0 +1,4 @@
1
+ require "cloudhdr_auth/engine"
2
+
3
+ module CloudhdrAuth
4
+ end
@@ -0,0 +1,5 @@
1
+ module CloudhdrAuth
2
+ class Engine < ::Rails::Engine
3
+
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module CloudhdrAuth
2
+ VERSION = "0.0.4"
3
+ end
@@ -0,0 +1,37 @@
1
+ require 'omniauth-oauth2'
2
+ module OmniAuth
3
+ module Strategies
4
+ class Cloudhdr < OmniAuth::Strategies::OAuth2
5
+
6
+ CUSTOM_PROVIDER_URL = AUTH_PROVIDER['url']
7
+
8
+ option :client_options, {
9
+ :site => CUSTOM_PROVIDER_URL,
10
+ :authorize_url => "#{CUSTOM_PROVIDER_URL}/auth/cloudhdr_auth/authorize",
11
+ :access_token_url => "#{CUSTOM_PROVIDER_URL}/auth/cloudhdr_auth/access_token"
12
+ }
13
+
14
+ uid { raw_info['id'] }
15
+
16
+ info do
17
+ {
18
+ :email => raw_info['email']
19
+ }
20
+ end
21
+
22
+ extra do
23
+ {
24
+ :current_sign_in_at => raw_info['extra']['current_sign_in_at'],
25
+ :name => raw_info['extra']['name']
26
+ #:first_name => raw_info['extra']['first_name'],
27
+ #:last_name => raw_info['extra']['last_name']
28
+ }
29
+ end
30
+
31
+ def raw_info
32
+ @raw_info ||= access_token.get("/auth/cloudhdr_auth/user.json?oauth_token=#{access_token.token}").parsed
33
+ end
34
+ end
35
+ end
36
+ end
37
+
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :cloudhdr_auth do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,65 @@
1
+ # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
2
+ # It is recommended to regenerate this file in the future when you upgrade to a
3
+ # newer version of cucumber-rails. Consider adding your own code to a new file
4
+ # instead of editing this one. Cucumber will automatically load all features/**/*.rb
5
+ # files.
6
+
7
+
8
+ unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
9
+
10
+ vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
11
+ $LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
12
+
13
+ begin
14
+ require 'cucumber/rake/task'
15
+
16
+ namespace :cucumber do
17
+ Cucumber::Rake::Task.new({:ok => 'test:prepare'}, 'Run features that should pass') do |t|
18
+ t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
19
+ t.fork = true # You may get faster startup if you set this to false
20
+ t.profile = 'default'
21
+ end
22
+
23
+ Cucumber::Rake::Task.new({:wip => 'test:prepare'}, 'Run features that are being worked on') do |t|
24
+ t.binary = vendored_cucumber_bin
25
+ t.fork = true # You may get faster startup if you set this to false
26
+ t.profile = 'wip'
27
+ end
28
+
29
+ Cucumber::Rake::Task.new({:rerun => 'test:prepare'}, 'Record failing features and run only them if any exist') do |t|
30
+ t.binary = vendored_cucumber_bin
31
+ t.fork = true # You may get faster startup if you set this to false
32
+ t.profile = 'rerun'
33
+ end
34
+
35
+ desc 'Run all features'
36
+ task :all => [:ok, :wip]
37
+
38
+ task :statsetup do
39
+ require 'rails/code_statistics'
40
+ ::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features')
41
+ ::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features')
42
+ end
43
+ end
44
+ desc 'Alias for cucumber:ok'
45
+ task :cucumber => 'cucumber:ok'
46
+
47
+ task :default => :cucumber
48
+
49
+ task :features => :cucumber do
50
+ STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
51
+ end
52
+
53
+ # In case we don't have the generic Rails test:prepare hook, append a no-op task that we can depend upon.
54
+ task 'test:prepare' do
55
+ end
56
+
57
+ task :stats => 'cucumber:statsetup'
58
+ rescue LoadError
59
+ desc 'cucumber rake task not available (cucumber not installed)'
60
+ task :cucumber do
61
+ abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
62
+ end
63
+ end
64
+
65
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cloudhdr_auth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Green
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-07 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: 3.2.13
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.13
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: omniauth-oauth2
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.1.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.1.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 2.13.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 2.13.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: cucumber-rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 1.3.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 1.3.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: database_cleaner
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 0.9.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 0.9.1
111
+ description: Auth gem for CloudHDR projects.
112
+ email:
113
+ - jeremy@octolabs.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - MIT-LICENSE
119
+ - README.md
120
+ - Rakefile
121
+ - app/controllers/cloudhdr_auth/base_controller.rb
122
+ - app/controllers/cloudhdr_auth/user_sessions_controller.rb
123
+ - config/cucumber.yml
124
+ - config/routes.rb
125
+ - lib/cloudhdr_auth.rb
126
+ - lib/cloudhdr_auth/engine.rb
127
+ - lib/cloudhdr_auth/version.rb
128
+ - lib/omniauth/strategies/cloudhdr.rb
129
+ - lib/tasks/cloudhdr_auth_tasks.rake
130
+ - lib/tasks/cucumber.rake
131
+ homepage: https://github.com/jagthedrummer/cloudhdr_auth
132
+ licenses: []
133
+ metadata: {}
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.2.2
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: Auth gem for CloudHDR projects.
154
+ test_files: []