devise-basecamper 0.0.6
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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +120 -0
- data/Rakefile +2 -0
- data/devise-basecamper.gemspec +20 -0
- data/lib/devise-basecamper.rb +10 -0
- data/lib/devise-basecamper/devise/models/authenticatable.rb +12 -0
- data/lib/devise-basecamper/model.rb +33 -0
- data/lib/devise-basecamper/version.rb +5 -0
- metadata +89 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 JD Hendrickson
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
# Devise::Basecamper
|
2
|
+
|
3
|
+
Devise-Basecamper was built to allow users of [Devise](https://github.com/plataformatec/devise) to implement "Basecamp" style subdomain scoped authentication with
|
4
|
+
support for multiple users. There are a lot of [great tutorials](https://github.com/RailsApps/rails3-subdomains) out
|
5
|
+
there on doing subdomain authentication with devise, but none of them seemed to fit my particular use cases. So I took
|
6
|
+
a stab at extending the functionality of [Devise](https://github.com/plataformatec/devise), which has been a great
|
7
|
+
Gem, and community, to work with.
|
8
|
+
|
9
|
+
### Use Case
|
10
|
+
User authentication that is scoped to an account, which is identified by the subdomain of the URL. This allows for better
|
11
|
+
multi-tenancy, as well as for re-use of usernames under different accounts.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
gem 'devise-basecamper'
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install devise-basecamper
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
To make Devise-Basecamper work properly, there are several steps that need to be taken to adjust the "out-of-the-box"
|
30
|
+
behavior of Devise. None of the changes require doing any "hacking" of Devise, as they are all steps/actions and
|
31
|
+
configuration options that are already a part of Devise itself.
|
32
|
+
|
33
|
+
### Devise Configuration
|
34
|
+
Open the Devise initializer file, which can be found in `config/initializers/devise.rb`. Add `:subdomain` to the
|
35
|
+
`config.request_keys` array like below.
|
36
|
+
|
37
|
+
config.request_keys = [:subdomain]
|
38
|
+
|
39
|
+
This will make sure to pass the subdomain value from the request to the appropriate Devise methods.
|
40
|
+
|
41
|
+
### Configuring models
|
42
|
+
|
43
|
+
Which ever model you would like to have subdomain based authentication scoping on, just add `:basecamper` to your
|
44
|
+
included devise modules.
|
45
|
+
|
46
|
+
```
|
47
|
+
class User
|
48
|
+
include Mongoid::Document
|
49
|
+
include Mongoid::Timestamps
|
50
|
+
|
51
|
+
devise :database_authenticatable,
|
52
|
+
:recoverable,
|
53
|
+
:trackable,
|
54
|
+
:validatable,
|
55
|
+
:basecamper
|
56
|
+
|
57
|
+
...
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
By default, Devise-Basecamper assumes that your devise model "belongs to" an Account and has a field called `account_id`
|
62
|
+
as the foreign key to that table. Devise-Basecamper also assumes that the subdomain field exists in your Account model
|
63
|
+
and is called `subdomain`. Now that's a lot of assumptions, but never fear...they can be changed.
|
64
|
+
|
65
|
+
If you need to change any of these assumptions, you can do so by calling the `devise_basecamper` method in your devise
|
66
|
+
model.
|
67
|
+
|
68
|
+
```
|
69
|
+
class User
|
70
|
+
include Mongoid::Document
|
71
|
+
include Mongoid::Timestamps
|
72
|
+
|
73
|
+
devise :database_authenticatable,
|
74
|
+
:recoverable,
|
75
|
+
:trackable,
|
76
|
+
:validatable,
|
77
|
+
:basecamper
|
78
|
+
|
79
|
+
devise_basecamper :subdomain_class => :my_parent_class,
|
80
|
+
:subdomain_field => :my_field_name,
|
81
|
+
:scope_field => :field_to_scope_against
|
82
|
+
|
83
|
+
...
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
The `devise_basecamper` method has 3 options that can be set: subdomain_class, subdomain_field and scope_field.
|
88
|
+
|
89
|
+
**subdomain_class**
|
90
|
+
|
91
|
+
This option allows you to specify which model your subdomains are defined in. By default, devise_basecamper assumes this
|
92
|
+
to be an `Account` object.
|
93
|
+
|
94
|
+
**subdomain_field**
|
95
|
+
|
96
|
+
This option allows you to specify the name of the field within the `subdomain_class` that the subdomain string is stored
|
97
|
+
in. By default, devise_basecamper assumes this to be `subdomain`.
|
98
|
+
|
99
|
+
**scope_field**
|
100
|
+
|
101
|
+
This option allows you to specify the name of the field within the devise model (e.g. - User) stores the ID of the account
|
102
|
+
you want to create a scope against. By default, devise_basecamper assumes that this is a field called `account_id`.
|
103
|
+
|
104
|
+
If your application follows the assumptions, you DO NOT need to define any of these options.
|
105
|
+
|
106
|
+
### Configuring multiple models
|
107
|
+
|
108
|
+
You can configure multiple models accordingly just as you can in Devise. If you have a Devise model that does not need
|
109
|
+
the additional features offered by Devise-Basecamper, simple do not include the module. Devise will work just as expected.
|
110
|
+
|
111
|
+
### ORM Compatability
|
112
|
+
|
113
|
+
Devise-Basecamper has very minimal interaction with your data layer, however it uses the same `orm_adapter` gem as Devise
|
114
|
+
and should work just fine with all of the ORM's supported by Devise.
|
115
|
+
|
116
|
+
MORE TO COME
|
117
|
+
|
118
|
+
## License
|
119
|
+
|
120
|
+
MIT License. Copyright © 2012 Digital Opera, LLC. [www.digitalopera.com](http://www.digitalopera.com/ "Digital Opera, LLC")
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/devise-basecamper/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["JD Hendrickson"]
|
6
|
+
gem.email = ["jd@digitalopera.com"]
|
7
|
+
gem.description = %q{Implement basecamp style subdomain authentication with support for multiple users under a single subdomain scoped account.}
|
8
|
+
gem.summary = %q{Implement basecamp style subdomain authentication}
|
9
|
+
gem.homepage = "https://github.com/digitalopera/devise-basecamper"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "devise-basecamper"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Devise::Basecamper::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency('orm_adapter', '~> 0.0.7')
|
19
|
+
gem.add_dependency('devise', '~> 2.0.4')
|
20
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'devise'
|
2
|
+
require 'devise-basecamper/version'
|
3
|
+
require 'devise-basecamper/devise/models/authenticatable'
|
4
|
+
|
5
|
+
Devise.add_module(:basecamper,
|
6
|
+
:strategy => false,
|
7
|
+
:route => :session,
|
8
|
+
:controller => :sessions,
|
9
|
+
:model => 'devise-basecamper/model'
|
10
|
+
)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Devise
|
2
|
+
module Models
|
3
|
+
module Basecamper
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
def devise_basecamper(opts={})
|
8
|
+
defaults = {
|
9
|
+
:subdomain_class => :account,
|
10
|
+
:subdomain_field => :subdomain,
|
11
|
+
:scope_field => :account_id
|
12
|
+
}
|
13
|
+
@devise_basecamper_settings = defaults.merge(opts)
|
14
|
+
end
|
15
|
+
|
16
|
+
def basecamper
|
17
|
+
self.devise_basecamper if @devise_basecamper_settings.nil?
|
18
|
+
return @devise_basecamper_settings
|
19
|
+
end
|
20
|
+
|
21
|
+
def find_for_authentication(conditions={})
|
22
|
+
if conditions[:subdomain].present?
|
23
|
+
resource = self.basecamper[:subdomain_class].to_s.camelize.constantize
|
24
|
+
subdomain_source = resource.to_adapter.find_first(self.basecamper[:subdomain_field] => conditions[:subdomain])
|
25
|
+
conditions[self.basecamper[:scope_field]] = (subdomain_source.nil?) ? nil : subdomain_source.id
|
26
|
+
conditions.delete(self.basecamper[:subdomain_field])
|
27
|
+
end
|
28
|
+
super
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: devise-basecamper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.6
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- JD Hendrickson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: orm_adapter
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.0.7
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.0.7
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: devise
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.0.4
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.0.4
|
46
|
+
description: Implement basecamp style subdomain authentication with support for multiple
|
47
|
+
users under a single subdomain scoped account.
|
48
|
+
email:
|
49
|
+
- jd@digitalopera.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- devise-basecamper.gemspec
|
60
|
+
- lib/devise-basecamper.rb
|
61
|
+
- lib/devise-basecamper/devise/models/authenticatable.rb
|
62
|
+
- lib/devise-basecamper/model.rb
|
63
|
+
- lib/devise-basecamper/version.rb
|
64
|
+
homepage: https://github.com/digitalopera/devise-basecamper
|
65
|
+
licenses: []
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.8.21
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Implement basecamp style subdomain authentication
|
88
|
+
test_files: []
|
89
|
+
has_rdoc:
|