velir_identity_engine 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "omniauth", :git => "git://github.com/Velir/omniauth.git"
4
+ gem "diesel", "~> 0.1"
5
+ gem "rake", "0.8.7"
6
+ gem "rails", "~> 3.0"
7
+
8
+ group :development do
9
+ gem "rspec", "~> 2.6.0"
10
+ gem "rspec-rails", "~> 2.6.0"
11
+ gem "shoulda-matchers"
12
+ gem "yard", "~> 0.6.0"
13
+ gem "bundler", "~> 1.0.0"
14
+ gem "jeweler", "~> 1.6.0"
15
+ gem "rcov", ">= 0"
16
+ gem "sqlite3"
17
+ gem "factory_girl_rails"
18
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,174 @@
1
+ GIT
2
+ remote: git://github.com/Velir/omniauth.git
3
+ revision: d945a990dee3cd25c550ff7e404d09828922de47
4
+ specs:
5
+ oa-basic (0.2.0.beta3)
6
+ multi_json (~> 0.0.2)
7
+ nokogiri (~> 1.4.2)
8
+ oa-core (= 0.2.0.beta3)
9
+ rest-client (~> 1.6.0)
10
+ oa-core (0.2.0.beta3)
11
+ rack (~> 1.1)
12
+ oa-enterprise (0.2.0.beta3)
13
+ net-ldap (~> 0.1.1)
14
+ nokogiri (~> 1.4.2)
15
+ oa-core (= 0.2.0.beta3)
16
+ pyu-ruby-sasl (~> 0.0.3.1)
17
+ rubyntlm (~> 0.1.1)
18
+ oa-more (0.2.0.beta3)
19
+ multi_json (~> 0.0.2)
20
+ oa-core (= 0.2.0.beta3)
21
+ rest-client (~> 1.6.0)
22
+ oa-oauth (0.2.0.beta3)
23
+ multi_json (~> 0.0.2)
24
+ nokogiri (~> 1.4.2)
25
+ oa-core (= 0.2.0.beta3)
26
+ oauth (~> 0.4.0)
27
+ oauth2 (~> 0.1.1)
28
+ oa-openid (0.2.0.beta3)
29
+ oa-core (= 0.2.0.beta3)
30
+ rack-openid (~> 1.2.0)
31
+ ruby-openid-apps-discovery
32
+ omniauth (0.2.0.beta3)
33
+ oa-basic (= 0.2.0.beta3)
34
+ oa-core (= 0.2.0.beta3)
35
+ oa-enterprise (= 0.2.0.beta3)
36
+ oa-more (= 0.2.0.beta3)
37
+ oa-oauth (= 0.2.0.beta3)
38
+ oa-openid (= 0.2.0.beta3)
39
+
40
+ GEM
41
+ remote: http://rubygems.org/
42
+ specs:
43
+ abstract (1.0.0)
44
+ actionmailer (3.0.7)
45
+ actionpack (= 3.0.7)
46
+ mail (~> 2.2.15)
47
+ actionpack (3.0.7)
48
+ activemodel (= 3.0.7)
49
+ activesupport (= 3.0.7)
50
+ builder (~> 2.1.2)
51
+ erubis (~> 2.6.6)
52
+ i18n (~> 0.5.0)
53
+ rack (~> 1.2.1)
54
+ rack-mount (~> 0.6.14)
55
+ rack-test (~> 0.5.7)
56
+ tzinfo (~> 0.3.23)
57
+ activemodel (3.0.7)
58
+ activesupport (= 3.0.7)
59
+ builder (~> 2.1.2)
60
+ i18n (~> 0.5.0)
61
+ activerecord (3.0.7)
62
+ activemodel (= 3.0.7)
63
+ activesupport (= 3.0.7)
64
+ arel (~> 2.0.2)
65
+ tzinfo (~> 0.3.23)
66
+ activeresource (3.0.7)
67
+ activemodel (= 3.0.7)
68
+ activesupport (= 3.0.7)
69
+ activesupport (3.0.7)
70
+ addressable (2.2.6)
71
+ arel (2.0.10)
72
+ builder (2.1.2)
73
+ diesel (0.1.4)
74
+ railties (~> 3.0.3)
75
+ diff-lcs (1.1.2)
76
+ erubis (2.6.6)
77
+ abstract (>= 1.0.0)
78
+ factory_girl (1.3.3)
79
+ factory_girl_rails (1.0.1)
80
+ factory_girl (~> 1.3)
81
+ railties (>= 3.0.0)
82
+ faraday (0.5.7)
83
+ addressable (~> 2.2.4)
84
+ multipart-post (~> 1.1.0)
85
+ rack (< 2, >= 1.1.0)
86
+ git (1.2.5)
87
+ i18n (0.5.0)
88
+ jeweler (1.6.0)
89
+ bundler (~> 1.0.0)
90
+ git (>= 1.2.5)
91
+ rake
92
+ mail (2.2.19)
93
+ activesupport (>= 2.3.6)
94
+ i18n (>= 0.4.0)
95
+ mime-types (~> 1.16)
96
+ treetop (~> 1.4.8)
97
+ mime-types (1.16)
98
+ multi_json (0.0.5)
99
+ multipart-post (1.1.2)
100
+ net-ldap (0.1.1)
101
+ nokogiri (1.4.4)
102
+ oauth (0.4.4)
103
+ oauth2 (0.1.1)
104
+ faraday (~> 0.5.0)
105
+ multi_json (~> 0.0.4)
106
+ polyglot (0.3.1)
107
+ pyu-ruby-sasl (0.0.3.2)
108
+ rack (1.2.3)
109
+ rack-mount (0.6.14)
110
+ rack (>= 1.0.0)
111
+ rack-openid (1.2.0)
112
+ rack (>= 1.1.0)
113
+ ruby-openid (>= 2.1.8)
114
+ rack-test (0.5.7)
115
+ rack (>= 1.0)
116
+ rails (3.0.7)
117
+ actionmailer (= 3.0.7)
118
+ actionpack (= 3.0.7)
119
+ activerecord (= 3.0.7)
120
+ activeresource (= 3.0.7)
121
+ activesupport (= 3.0.7)
122
+ bundler (~> 1.0)
123
+ railties (= 3.0.7)
124
+ railties (3.0.7)
125
+ actionpack (= 3.0.7)
126
+ activesupport (= 3.0.7)
127
+ rake (>= 0.8.7)
128
+ thor (~> 0.14.4)
129
+ rake (0.8.7)
130
+ rcov (0.9.9)
131
+ rest-client (1.6.1)
132
+ mime-types (>= 1.16)
133
+ rspec (2.6.0)
134
+ rspec-core (~> 2.6.0)
135
+ rspec-expectations (~> 2.6.0)
136
+ rspec-mocks (~> 2.6.0)
137
+ rspec-core (2.6.3)
138
+ rspec-expectations (2.6.0)
139
+ diff-lcs (~> 1.1.2)
140
+ rspec-mocks (2.6.0)
141
+ rspec-rails (2.6.0)
142
+ actionpack (~> 3.0)
143
+ activesupport (~> 3.0)
144
+ railties (~> 3.0)
145
+ rspec (~> 2.6.0)
146
+ ruby-openid (2.1.8)
147
+ ruby-openid-apps-discovery (1.2.0)
148
+ ruby-openid (>= 2.1.7)
149
+ rubyntlm (0.1.1)
150
+ shoulda-matchers (1.0.0.beta2)
151
+ sqlite3 (1.3.3)
152
+ thor (0.14.6)
153
+ treetop (1.4.9)
154
+ polyglot (>= 0.3.1)
155
+ tzinfo (0.3.27)
156
+ yard (0.6.8)
157
+
158
+ PLATFORMS
159
+ ruby
160
+
161
+ DEPENDENCIES
162
+ bundler (~> 1.0.0)
163
+ diesel (~> 0.1)
164
+ factory_girl_rails
165
+ jeweler (~> 1.6.0)
166
+ omniauth!
167
+ rails (~> 3.0)
168
+ rake (= 0.8.7)
169
+ rcov
170
+ rspec (~> 2.6.0)
171
+ rspec-rails (~> 2.6.0)
172
+ shoulda-matchers
173
+ sqlite3
174
+ yard (~> 0.6.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Velir
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,54 @@
1
+ Velir Identity Engine
2
+ =====================
3
+
4
+ The Velir Identity Engine gives you a quick and dirty Authentication/Authorization solution
5
+ for all your proof-of-concept/internal app/rapid prototyping needs. It isn't intended to replace
6
+ solutions such as Devise, it's just sticking around for when you don't need anything that heavy.
7
+
8
+ Installation
9
+ ------------
10
+
11
+ Add this sucker to your Rails app Gemfile along with Velir's OmniAuth:
12
+
13
+ gem "omniauth", :git => "git://github.com/Velir/omniauth.git"
14
+ gem "velir_identity_engine", :git => "git@github.com:Velir/velir_identity_engine.git"
15
+
16
+ (Make sure OmniAuth is first.)
17
+
18
+ Run the generator:
19
+
20
+ rails g velir_identity_engine:install
21
+
22
+ Get your keys from [http://velir.authorizely.com](http://velir.authorizely.com) and add them to the initializer:
23
+
24
+ # config/initializers/velir_identity_engine.rb
25
+ Rails.application.config.middleware.use OmniAuth::Builder do
26
+ provider :velir, '<ID>', '<SECRET>'
27
+ end
28
+
29
+ Run the database migration:
30
+
31
+ rake db:migrate
32
+
33
+ Ensure you have something mapped to root_url:
34
+
35
+ # config/routes.rb
36
+ root :to => "welcome#index"
37
+
38
+ Contributing to Velir Identity Engine
39
+ -------------------------------------
40
+
41
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
42
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
43
+ * Fork the project
44
+ * Start a feature/bugfix branch
45
+ * Commit and push until you are happy with your contribution
46
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
47
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
48
+
49
+ Copyright
50
+ ---------
51
+
52
+ Copyright (c) 2011 Velir. See LICENSE.txt for
53
+ further details.
54
+
data/Rakefile ADDED
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ require 'bundler/setup'
6
+ require 'rake'
7
+ require 'rubygems/package_task'
8
+ require 'jeweler'
9
+ require 'diesel/tasks'
10
+ require 'rspec/core'
11
+ require 'rspec/core/rake_task'
12
+ require 'yard'
13
+
14
+
15
+ begin
16
+ Bundler.setup(:default, :development)
17
+ rescue Bundler::BundlerError => e
18
+ $stderr.puts e.message
19
+ $stderr.puts "Run `bundle install` to install missing gems"
20
+ exit e.status_code
21
+ end
22
+ Jeweler::Tasks.new do |gem|
23
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
24
+ gem.name = "velir_identity_engine"
25
+ gem.homepage = "http://github.com/Velir/velir_identity_engine"
26
+ gem.license = "MIT"
27
+ gem.summary = "Instant auth/authz engine for Velir Identity client apps"
28
+ gem.description = "Instant auth/authz engine for Velir Identity client apps"
29
+ gem.email = "patrick.robertson@velir.com"
30
+ gem.authors = ["patricksrobertson"]
31
+ # dependencies defined in Gemfile
32
+ end
33
+ Jeweler::RubygemsDotOrgTasks.new
34
+
35
+
36
+ RSpec::Core::RakeTask.new(:spec) do |spec|
37
+ spec.pattern = FileList['spec/**/*_spec.rb']
38
+ end
39
+
40
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
41
+ spec.pattern = 'spec/**/*_spec.rb'
42
+ spec.rcov = true
43
+ end
44
+
45
+ task :default => :spec
46
+
47
+ YARD::Rake::YardocTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.5
@@ -0,0 +1,25 @@
1
+ class VelirIdentityEngine::SessionsController < ApplicationController
2
+
3
+ def create
4
+ user = ::User.find_by_provider_and_uid(omniauth['provider'],omniauth['uid'])
5
+ if user
6
+ session[:user_id] = user.id
7
+ else
8
+ new_user = ::User.create_with_omniauth(omniauth)
9
+ session[:user_id] = new_user.id
10
+ end
11
+ redirect_to root_url, :notice => "Signed in!"
12
+ end
13
+
14
+ def destroy
15
+ session[:user_id] = nil
16
+ redirect_to root_url, :notice => "Signed out!"
17
+ end
18
+
19
+ private
20
+
21
+ def omniauth
22
+ @omniauth ||= request.env["omniauth.auth"]
23
+ end
24
+
25
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ Rails.application.routes.draw do
2
+ resources :sessions, :controller => "velir_identity_engine/sessions", :only => [:create,:destroy]
3
+ match 'auth/:provider/callback' => 'velir_identity_engine/sessions#create'
4
+ match "/logout" => "velir_identity_engine/sessions#destroy", :as => :logout
5
+ end
@@ -0,0 +1,19 @@
1
+ class CreateIdentityUsers < ActiveRecord::Migration
2
+ def self.up
3
+ create_table(:users) do |t|
4
+ t.string :provider
5
+ t.string :uid
6
+ t.string :first_name
7
+ t.string :last_name
8
+ t.boolean :approved, :default => false
9
+
10
+ t.timestamps
11
+ end
12
+
13
+ add_index :users, :uid, :unique => true
14
+ end
15
+
16
+ def self.down
17
+ drop_table :users
18
+ end
19
+ end
data/db/schema.rb ADDED
@@ -0,0 +1,27 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # Note that this schema.rb definition is the authoritative source for your
6
+ # database schema. If you need to create the application database on another
7
+ # system, you should be using db:schema:load, not running all the migrations
8
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
10
+ #
11
+ # It's strongly recommended to check this file into your version control system.
12
+
13
+ ActiveRecord::Schema.define(:version => 20110111224543) do
14
+
15
+ create_table "users", :force => true do |t|
16
+ t.string "provider"
17
+ t.string "uid"
18
+ t.string "first_name"
19
+ t.string "last_name"
20
+ t.boolean "approved", :default => false
21
+ t.datetime "created_at"
22
+ t.datetime "updated_at"
23
+ end
24
+
25
+ add_index "users", ["uid"], :name => "index_users_on_uid", :unique => true
26
+
27
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'velir_identity_engine'
@@ -0,0 +1,41 @@
1
+ require 'diesel/generators/install_base'
2
+
3
+ module VelirIdentityEngine
4
+ module Generators
5
+ class InstallGenerator < Diesel::Generators::InstallBase
6
+ def install
7
+ template "velir_identity_engine.rb", "config/initializers/velir_identity_engine.rb"
8
+
9
+ inject_into_class "app/controllers/application_controller.rb", ApplicationController do
10
+ " include VelirIdentityEngine::Authentication\n"
11
+ end
12
+
13
+ user_model = "app/models/user.rb"
14
+ if File.exists? user_model
15
+ inject_into_class user_model, User do
16
+ "include VelirIdentityEngine::User\n"
17
+ end
18
+ else
19
+ template "user.rb", user_model
20
+ end
21
+
22
+ readme "README"
23
+ end
24
+
25
+ private
26
+
27
+ def migrations
28
+ if users_table_exists?
29
+ super.reject { |name| name.include?("create") } + ["db/migrate/update_users_to_identity.rb"]
30
+ else
31
+ super
32
+ end
33
+ end
34
+
35
+ def users_table_exists?
36
+ ActiveRecord::Base.connection.table_exists?(:users)
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,23 @@
1
+ *******************************************************************************
2
+
3
+ Next steps:
4
+
5
+ 1. Configure the initializer:
6
+
7
+ # config/initialzers/velir_identity_engine.rb
8
+ Rails.application.config.middleware.use OmniAuth::Builder do
9
+ provider :velir, '<ID>', '<SECRET>'
10
+ end
11
+
12
+ This should be the id and secret provided by velir.authorizely.com
13
+
14
+ 2. Migrate:
15
+
16
+ rake db:migrate
17
+
18
+ 3. Configure a root_url
19
+
20
+ # config/routes.rb
21
+ root :to => "home#index"
22
+
23
+ *******************************************************************************
@@ -0,0 +1,39 @@
1
+ class UpdateUsersToIdentity < ActiveRecord::Migration
2
+ def self.up
3
+ <%
4
+ existing_columns = ActiveRecord::Base.connection.columns(:users).collect { |each| each.name }
5
+ columns = [
6
+ [:provider, 't.string :provider'],
7
+ [:uid, 't.string :uid'],
8
+ [:first_name, 't.string :first_name'],
9
+ [:last_name, 't.string :last_name'],
10
+ [:approved, 't.boolean :approved, :default => false']
11
+ ].delete_if {|c| existing_columns.include?(c.first.to_s)}
12
+ -%>
13
+ change_table(:users) do |t|
14
+ <% columns.each do |c| -%>
15
+ <%= c.last %>
16
+ <% end -%>
17
+ end
18
+
19
+ <%
20
+ existing_indexes = ActiveRecord::Base.connection.indexes(:users)
21
+ index_names = existing_indexes.collect { |each| each.name }
22
+ new_indexes = [
23
+ [:index_users_on_uid, 'add_index :users, :uid, :unique => true'],
24
+ ].delete_if { |each| index_names.include?(each.first.to_s) }
25
+ -%>
26
+ <% new_indexes.each do |each| -%>
27
+ <%= each.last %>
28
+ <% end -%>
29
+
30
+ end
31
+
32
+ def self.down
33
+ change_table(:users) do |t|
34
+ <% unless columns.empty? -%>
35
+ t.remove <%= columns.collect { |each| ":#{each.first}" }.join(',') %>
36
+ <% end -%>
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ include VelirIdentityEngine::User
3
+ end
@@ -0,0 +1,3 @@
1
+ Rails.application.config.middleware.use OmniAuth::Builder do
2
+ provider :velir, '<ID>', '<SECRET>'
3
+ end
@@ -0,0 +1,15 @@
1
+ require 'velir_identity_engine/user'
2
+ require 'velir_identity_engine/authentication'
3
+
4
+ require 'velir_identity_engine/engine'
5
+
6
+ #
7
+ # Velir Identity Engine provides a super integrated
8
+ # authorization/authentication system for a new Rails app
9
+ # that plans to make use of only the Velir Identity OAuth
10
+ # provider.
11
+ #
12
+ # @author Patrick Robertson
13
+ #
14
+ module VelirIdentityEngine
15
+ end
@@ -0,0 +1,34 @@
1
+ #
2
+ # Authentication provides helper methods for managing
3
+ # the currently authenticated user in the session.
4
+ #
5
+ # @author Patrick Robertson
6
+ #
7
+ module VelirIdentityEngine
8
+ module Authentication
9
+ extend ActiveSupport::Concern
10
+
11
+ included do
12
+ helper_method :current_user
13
+ end
14
+
15
+ def current_user
16
+ @current_user ||= ::User.find(session[:user_id]) if session[:user_id]
17
+ end
18
+
19
+ protected
20
+
21
+ def approved_user
22
+ current_user && current_user.approved?
23
+ end
24
+
25
+ def require_user
26
+ unless approved_user
27
+ flash[:notice] = "You must be an approved user in order to access this page"
28
+ redirect_to root_url
29
+ return false
30
+ end
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,10 @@
1
+ require 'velir_identity_engine'
2
+ require 'rails'
3
+
4
+ module VelirIdentityEngine
5
+ class Engine < Rails::Engine
6
+ initializer "identity.filter" do |app|
7
+ app.config.filter_parameters += [:uid]
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,78 @@
1
+ #
2
+ # User provides methods for managing and querying users.
3
+ #
4
+ # @author Patrick Robertson
5
+ module VelirIdentityEngine
6
+ module User
7
+ extend ActiveSupport::Concern
8
+
9
+ #
10
+ # Hook for all VelirIdentityEngine::User modules
11
+ #
12
+ # This is where you can easily extend behavior.
13
+ # @example
14
+ # include SecureMethods
15
+ #
16
+ included do
17
+ attr_protected :approved, :provider, :uid
18
+
19
+ include Validations
20
+ end
21
+
22
+ module ClassMethods
23
+
24
+ #
25
+ # Creates a valid record given an OmniAuth hash.
26
+ #
27
+ # @param [Hash] auth Omniauth hash
28
+ # @return [User] Returns a user or raises an error.
29
+ #
30
+ def create_with_omniauth(auth)
31
+ user = self.new
32
+ user.provider = auth["provider"]
33
+ user.uid = auth["uid"]
34
+ user.first_name = auth["user_info"]["name"].split(" ")[0]
35
+ user.last_name = auth["user_info"]["name"].split(" ")[1]
36
+ user.save!
37
+ user
38
+ end
39
+
40
+ def approved_users ; where(:approved => true) end
41
+ def unapproved_users ; where(:approved => false) end
42
+ end
43
+
44
+ module Validations
45
+ extend ActiveSupport::Concern
46
+
47
+ #
48
+ # Hook for validations.
49
+ #
50
+ # :provider & :uid bmust be present
51
+ # :uid must be unique and is backed by a uniq db index
52
+ #
53
+ included do
54
+ validates_presence_of :provider
55
+ validates_presence_of :uid
56
+ validates_uniqueness_of :uid
57
+ end
58
+ end
59
+
60
+ def approve!
61
+ return false if self.approved?
62
+
63
+ self.approved = true
64
+ self.save!
65
+ end
66
+
67
+ def name
68
+ "#{self.first_name} #{self.last_name}"
69
+ end
70
+
71
+ def unapprove!
72
+ return false unless self.approved?
73
+
74
+ self.approved = false
75
+ self.save!
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe VelirIdentityEngine::SessionsController do
4
+ describe "POST 'create'" do
5
+ before do
6
+ @user = Factory(:user)
7
+ request.env["omniauth.auth"] = {}
8
+ request.env["omniauth.auth"]["provider"] = @user.provider
9
+ request.env["omniauth.auth"]["uid"] = @user.uid
10
+ post :create
11
+ end
12
+
13
+ it { should respond_with(:redirect) }
14
+ it { should redirect_to root_url }
15
+ it { should set_the_flash.to(/Signed in!/i) }
16
+ it { should assign_to(:omniauth) }
17
+ end
18
+
19
+ describe "DELETE 'delete'" do
20
+ before do
21
+ delete :destroy
22
+ end
23
+
24
+ it { should respond_with(:redirect) }
25
+ it { should redirect_to root_url }
26
+ it { should set_the_flash.to(/Signed out!/i) }
27
+ it { should_not assign_to(:omniauth) }
28
+ end
29
+ end
data/spec/factories.rb ADDED
@@ -0,0 +1,10 @@
1
+ Factory.sequence :uid do |n|
2
+ "#{n}"
3
+ end
4
+
5
+ Factory.define :user, :class => "User" do |user|
6
+ user.first_name { "User" }
7
+ user.last_name { "McUserson" }
8
+ user.provider { "velir" }
9
+ user.uid { Factory.next :uid }
10
+ end
@@ -0,0 +1,92 @@
1
+ require 'spec_helper'
2
+
3
+ describe User do
4
+ it { should have_db_index(:uid).unique(true) }
5
+
6
+ it {should_not allow_mass_assignment_of :approved }
7
+ it {should_not allow_mass_assignment_of :provider }
8
+ it {should_not allow_mass_assignment_of :uid }
9
+ it {should allow_mass_assignment_of :first_name }
10
+ it {should allow_mass_assignment_of :last_name }
11
+
12
+ describe "When signing up" do
13
+ it { should validate_presence_of :uid }
14
+ it { should validate_presence_of :provider }
15
+ it { should_not validate_presence_of :first_name }
16
+ it { should_not validate_presence_of :last_name }
17
+
18
+ describe "When multiple users have signed up" do
19
+ before { Factory(:user)}
20
+ it { should validate_uniqueness_of :uid }
21
+ end
22
+
23
+ describe "should create a valid record given an omniauth hash" do
24
+ before do
25
+ @bob = User.create_with_omniauth({
26
+ "user_info" => {"name" => "Pat Robertson"},
27
+ "uid" => "1243",
28
+ "provider" => "velir"
29
+ }
30
+ )
31
+ end
32
+
33
+ it { @bob.should be_valid }
34
+ it { @bob.should_not be_a_new(User) }
35
+ it "should assign the proper first name" do
36
+ @bob.first_name.should eq("Pat")
37
+ end
38
+ it "should assign the proper last name" do
39
+ @bob.last_name.should eq("Robertson")
40
+ end
41
+ end
42
+ end
43
+
44
+ describe "approve!" do
45
+ before do
46
+ @user = Factory(:user)
47
+ end
48
+
49
+ describe "approved should initialize to false" do
50
+ it { @user.approved.should be_false }
51
+ it { @user.approved?.should be_false }
52
+ end
53
+
54
+ describe "should set approved to true" do
55
+ before do
56
+ @user.approve!
57
+ end
58
+
59
+ it { @user.approved.should be_true }
60
+ it { @user.approved?.should be_true }
61
+
62
+ it "shouldn't return true if the user is approved" do
63
+ @user.approve!.should be_false
64
+ end
65
+ end
66
+
67
+
68
+ end
69
+
70
+ describe "unapprove!" do
71
+ before do
72
+ @user = Factory(:user)
73
+ @user.approve!
74
+ end
75
+
76
+ describe "should set approved to false" do
77
+ before do
78
+ @user.unapprove!
79
+ end
80
+
81
+ it { @user.approved.should be_false }
82
+ it { @user.approved?.should be_false }
83
+
84
+ it "shouldn't return true if the user isn't approved" do
85
+ @user.unapprove!.should be_false
86
+ end
87
+ end
88
+
89
+ end
90
+
91
+ after(:all) {User.destroy_all}
92
+ end
@@ -0,0 +1,29 @@
1
+ ENV["RAILS_ENV"] ||= "test"
2
+
3
+ PROJECT_ROOT = File.expand_path("../..", __FILE__)
4
+ $LOAD_PATH << File.join(PROJECT_ROOT, "lib")
5
+
6
+ require 'rails/all'
7
+ Bundler.require(:default, :development)
8
+
9
+ require 'diesel/testing'
10
+ require 'rspec/rails'
11
+ require 'velir_identity_engine'
12
+
13
+
14
+ class ApplicationController < ActionController::Base
15
+ include VelirIdentityEngine::Authentication
16
+ end
17
+
18
+ class User < ActiveRecord::Base
19
+ include VelirIdentityEngine::User
20
+ end
21
+
22
+ # Requires supporting files with custom matchers and macros, etc,
23
+ # in ./support/ and its subdirectories.
24
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
25
+
26
+ RSpec.configure do |config|
27
+ config.use_transactional_fixtures = true
28
+ config.backtrace_clean_patterns << %r{gems/}
29
+ end
@@ -0,0 +1,102 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{velir_identity_engine}
8
+ s.version = "0.1.5"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["patricksrobertson"]
12
+ s.date = %q{2011-05-25}
13
+ s.description = %q{Instant auth/authz engine for Velir Identity client apps}
14
+ s.email = %q{patrick.robertson@velir.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "app/controllers/velir_identity_engine/sessions_controller.rb",
29
+ "config/routes.rb",
30
+ "db/migrate/20110111224543_create_identity_users.rb",
31
+ "db/schema.rb",
32
+ "init.rb",
33
+ "lib/generators/velir_identity_engine/install/install_generator.rb",
34
+ "lib/generators/velir_identity_engine/install/templates/README",
35
+ "lib/generators/velir_identity_engine/install/templates/db/migrate/update_users_to_identity.rb",
36
+ "lib/generators/velir_identity_engine/install/templates/user.rb",
37
+ "lib/generators/velir_identity_engine/install/templates/velir_identity_engine.rb",
38
+ "lib/velir_identity_engine.rb",
39
+ "lib/velir_identity_engine/authentication.rb",
40
+ "lib/velir_identity_engine/engine.rb",
41
+ "lib/velir_identity_engine/user.rb",
42
+ "spec/controllers/sessions_controller_spec.rb",
43
+ "spec/factories.rb",
44
+ "spec/models/user_spec.rb",
45
+ "spec/spec_helper.rb",
46
+ "velir_identity_engine.gemspec"
47
+ ]
48
+ s.homepage = %q{http://github.com/Velir/velir_identity_engine}
49
+ s.licenses = ["MIT"]
50
+ s.require_paths = ["lib"]
51
+ s.rubygems_version = %q{1.6.2}
52
+ s.summary = %q{Instant auth/authz engine for Velir Identity client apps}
53
+
54
+ if s.respond_to? :specification_version then
55
+ s.specification_version = 3
56
+
57
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
58
+ s.add_runtime_dependency(%q<omniauth>, [">= 0"])
59
+ s.add_runtime_dependency(%q<diesel>, ["~> 0.1"])
60
+ s.add_runtime_dependency(%q<rake>, ["= 0.8.7"])
61
+ s.add_runtime_dependency(%q<rails>, ["~> 3.0"])
62
+ s.add_development_dependency(%q<rspec>, ["~> 2.6.0"])
63
+ s.add_development_dependency(%q<rspec-rails>, ["~> 2.6.0"])
64
+ s.add_development_dependency(%q<shoulda-matchers>, [">= 0"])
65
+ s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
66
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
67
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
68
+ s.add_development_dependency(%q<rcov>, [">= 0"])
69
+ s.add_development_dependency(%q<sqlite3>, [">= 0"])
70
+ s.add_development_dependency(%q<factory_girl_rails>, [">= 0"])
71
+ else
72
+ s.add_dependency(%q<omniauth>, [">= 0"])
73
+ s.add_dependency(%q<diesel>, ["~> 0.1"])
74
+ s.add_dependency(%q<rake>, ["= 0.8.7"])
75
+ s.add_dependency(%q<rails>, ["~> 3.0"])
76
+ s.add_dependency(%q<rspec>, ["~> 2.6.0"])
77
+ s.add_dependency(%q<rspec-rails>, ["~> 2.6.0"])
78
+ s.add_dependency(%q<shoulda-matchers>, [">= 0"])
79
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
80
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
81
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
82
+ s.add_dependency(%q<rcov>, [">= 0"])
83
+ s.add_dependency(%q<sqlite3>, [">= 0"])
84
+ s.add_dependency(%q<factory_girl_rails>, [">= 0"])
85
+ end
86
+ else
87
+ s.add_dependency(%q<omniauth>, [">= 0"])
88
+ s.add_dependency(%q<diesel>, ["~> 0.1"])
89
+ s.add_dependency(%q<rake>, ["= 0.8.7"])
90
+ s.add_dependency(%q<rails>, ["~> 3.0"])
91
+ s.add_dependency(%q<rspec>, ["~> 2.6.0"])
92
+ s.add_dependency(%q<rspec-rails>, ["~> 2.6.0"])
93
+ s.add_dependency(%q<shoulda-matchers>, [">= 0"])
94
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
95
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
96
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
97
+ s.add_dependency(%q<rcov>, [">= 0"])
98
+ s.add_dependency(%q<sqlite3>, [">= 0"])
99
+ s.add_dependency(%q<factory_girl_rails>, [">= 0"])
100
+ end
101
+ end
102
+
metadata ADDED
@@ -0,0 +1,225 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: velir_identity_engine
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.5
6
+ platform: ruby
7
+ authors:
8
+ - patricksrobertson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-25 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: omniauth
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: diesel
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: "0.1"
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: rake
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - "="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.8.7
47
+ type: :runtime
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: rails
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ version: "3.0"
58
+ type: :runtime
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: rspec
62
+ prerelease: false
63
+ requirement: &id005 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 2.6.0
69
+ type: :development
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: rspec-rails
73
+ prerelease: false
74
+ requirement: &id006 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ~>
78
+ - !ruby/object:Gem::Version
79
+ version: 2.6.0
80
+ type: :development
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: shoulda-matchers
84
+ prerelease: false
85
+ requirement: &id007 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: "0"
91
+ type: :development
92
+ version_requirements: *id007
93
+ - !ruby/object:Gem::Dependency
94
+ name: yard
95
+ prerelease: false
96
+ requirement: &id008 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 0.6.0
102
+ type: :development
103
+ version_requirements: *id008
104
+ - !ruby/object:Gem::Dependency
105
+ name: bundler
106
+ prerelease: false
107
+ requirement: &id009 !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ~>
111
+ - !ruby/object:Gem::Version
112
+ version: 1.0.0
113
+ type: :development
114
+ version_requirements: *id009
115
+ - !ruby/object:Gem::Dependency
116
+ name: jeweler
117
+ prerelease: false
118
+ requirement: &id010 !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ~>
122
+ - !ruby/object:Gem::Version
123
+ version: 1.6.0
124
+ type: :development
125
+ version_requirements: *id010
126
+ - !ruby/object:Gem::Dependency
127
+ name: rcov
128
+ prerelease: false
129
+ requirement: &id011 !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: "0"
135
+ type: :development
136
+ version_requirements: *id011
137
+ - !ruby/object:Gem::Dependency
138
+ name: sqlite3
139
+ prerelease: false
140
+ requirement: &id012 !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: "0"
146
+ type: :development
147
+ version_requirements: *id012
148
+ - !ruby/object:Gem::Dependency
149
+ name: factory_girl_rails
150
+ prerelease: false
151
+ requirement: &id013 !ruby/object:Gem::Requirement
152
+ none: false
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: "0"
157
+ type: :development
158
+ version_requirements: *id013
159
+ description: Instant auth/authz engine for Velir Identity client apps
160
+ email: patrick.robertson@velir.com
161
+ executables: []
162
+
163
+ extensions: []
164
+
165
+ extra_rdoc_files:
166
+ - LICENSE.txt
167
+ - README.md
168
+ files:
169
+ - .document
170
+ - .rspec
171
+ - Gemfile
172
+ - Gemfile.lock
173
+ - LICENSE.txt
174
+ - README.md
175
+ - Rakefile
176
+ - VERSION
177
+ - app/controllers/velir_identity_engine/sessions_controller.rb
178
+ - config/routes.rb
179
+ - db/migrate/20110111224543_create_identity_users.rb
180
+ - db/schema.rb
181
+ - init.rb
182
+ - lib/generators/velir_identity_engine/install/install_generator.rb
183
+ - lib/generators/velir_identity_engine/install/templates/README
184
+ - lib/generators/velir_identity_engine/install/templates/db/migrate/update_users_to_identity.rb
185
+ - lib/generators/velir_identity_engine/install/templates/user.rb
186
+ - lib/generators/velir_identity_engine/install/templates/velir_identity_engine.rb
187
+ - lib/velir_identity_engine.rb
188
+ - lib/velir_identity_engine/authentication.rb
189
+ - lib/velir_identity_engine/engine.rb
190
+ - lib/velir_identity_engine/user.rb
191
+ - spec/controllers/sessions_controller_spec.rb
192
+ - spec/factories.rb
193
+ - spec/models/user_spec.rb
194
+ - spec/spec_helper.rb
195
+ - velir_identity_engine.gemspec
196
+ has_rdoc: true
197
+ homepage: http://github.com/Velir/velir_identity_engine
198
+ licenses:
199
+ - MIT
200
+ post_install_message:
201
+ rdoc_options: []
202
+
203
+ require_paths:
204
+ - lib
205
+ required_ruby_version: !ruby/object:Gem::Requirement
206
+ none: false
207
+ requirements:
208
+ - - ">="
209
+ - !ruby/object:Gem::Version
210
+ version: "0"
211
+ required_rubygems_version: !ruby/object:Gem::Requirement
212
+ none: false
213
+ requirements:
214
+ - - ">="
215
+ - !ruby/object:Gem::Version
216
+ version: "0"
217
+ requirements: []
218
+
219
+ rubyforge_project:
220
+ rubygems_version: 1.6.2
221
+ signing_key:
222
+ specification_version: 3
223
+ summary: Instant auth/authz engine for Velir Identity client apps
224
+ test_files: []
225
+