rpx_regexp 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +32 -0
- data/Rakefile +12 -0
- data/lib/rpx_regexp.rb +12 -0
- data/lib/rpx_regexp/version.rb +3 -0
- data/rpx_regexp.gemspec +25 -0
- data/test/test_helper.rb +6 -0
- data/test/test_rpx_regexp.rb +37 -0
- metadata +118 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# RPX_Regexp
|
2
|
+
|
3
|
+
Whenever we want to authenticate users on a Rails app, we like to go
|
4
|
+
with [Janrain](http://www.janrain.com/) + [Devise](https://github.com/plataformatec/devise).
|
5
|
+
|
6
|
+
To achieve this we use [this excelent gem](https://github.com/slainer68/devise_rpx_connectable)
|
7
|
+
that just makes everything very easy.
|
8
|
+
|
9
|
+
Sometimes we like to do our own apps where only users in our domain
|
10
|
+
have access, and we use this gem to make sure Janrain and Devise
|
11
|
+
only authenticates our users.
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Add the gem to your Gemfile or require it depending on what you are
|
16
|
+
using.
|
17
|
+
|
18
|
+
Then, just set your email RegExp somewhere on your code:
|
19
|
+
|
20
|
+
RPXNow.email_regexp = /@crowdint.com$/
|
21
|
+
|
22
|
+
For rails, you can put it on an initializer. Since this is
|
23
|
+
authentication code, I usually put it on *initializers/devise.rb*
|
24
|
+
|
25
|
+
# About the Author
|
26
|
+
|
27
|
+
[Crowd Interactive](http://www.crowdint.com) is a Ruby and Rails consultancy firm
|
28
|
+
powered by a team of enthusiast engineers who love programming.
|
29
|
+
We turn your ideas into web applications, and we like challenging projects. We also have
|
30
|
+
a lot of experience in retail, so it doesn't matter if your idea is about
|
31
|
+
something you'd like to sell, we can surely help you.
|
32
|
+
|
data/Rakefile
ADDED
data/lib/rpx_regexp.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rpx_now'
|
2
|
+
|
3
|
+
module RPXNow
|
4
|
+
alias_method :user_data!, :user_data
|
5
|
+
|
6
|
+
attr_accessor :email_regexp
|
7
|
+
|
8
|
+
def user_data(token, options={})
|
9
|
+
result = user_data!(token, options={})
|
10
|
+
result["email"].match(self.email_regexp) ? result : nil
|
11
|
+
end
|
12
|
+
end
|
data/rpx_regexp.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rpx_regexp/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "rpx_regexp"
|
7
|
+
s.version = RpxRegexp::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["David Padilla"]
|
10
|
+
s.email = ["david@crowdint.com"]
|
11
|
+
s.homepage = "https://rubygems.org/gems/rpx_regexp"
|
12
|
+
s.summary = %q{Restrict who authenticates through Janrain with a regexp}
|
13
|
+
s.description = %q{Restrict who authenticates through Janrain with a regexp}
|
14
|
+
|
15
|
+
s.rubyforge_project = "rpx_crowdint"
|
16
|
+
|
17
|
+
s.add_dependency 'rpx_now'
|
18
|
+
s.add_development_dependency 'minitest'
|
19
|
+
s.add_development_dependency 'mocha'
|
20
|
+
|
21
|
+
s.files = `git ls-files`.split("\n")
|
22
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe RPXNow do
|
4
|
+
it "aliases user_data to user_data!" do
|
5
|
+
assert_respond_to RPXNow, :user_data!
|
6
|
+
assert_respond_to RPXNow, :user_data
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "user_data" do
|
10
|
+
before :each do
|
11
|
+
@result = { "email" => "david@crowdint.com" }
|
12
|
+
@token = MiniTest::Mock.new
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "user email matches email_regexp" do
|
16
|
+
before :each do
|
17
|
+
RPXNow.email_regexp = %r{@crowdint.com}
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns the result" do
|
21
|
+
RPXNow.expects(:user_data!).with(@token, {}).returns(@result)
|
22
|
+
assert_equal @result, RPXNow.user_data(@token)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "user email doesn't match email_regexp" do
|
27
|
+
before :each do
|
28
|
+
RPXNow.email_regexp = %r{@google.com}
|
29
|
+
end
|
30
|
+
|
31
|
+
it "returns the result" do
|
32
|
+
RPXNow.expects(:user_data!).with(@token, {}).returns(@result)
|
33
|
+
assert_nil RPXNow.user_data(@token)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rpx_regexp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- David Padilla
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-03-18 00:00:00 -06:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rpx_now
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: minitest
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: mocha
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
63
|
+
description: Restrict who authenticates through Janrain with a regexp
|
64
|
+
email:
|
65
|
+
- david@crowdint.com
|
66
|
+
executables: []
|
67
|
+
|
68
|
+
extensions: []
|
69
|
+
|
70
|
+
extra_rdoc_files: []
|
71
|
+
|
72
|
+
files:
|
73
|
+
- .gitignore
|
74
|
+
- Gemfile
|
75
|
+
- README.md
|
76
|
+
- Rakefile
|
77
|
+
- lib/rpx_regexp.rb
|
78
|
+
- lib/rpx_regexp/version.rb
|
79
|
+
- rpx_regexp.gemspec
|
80
|
+
- test/test_helper.rb
|
81
|
+
- test/test_rpx_regexp.rb
|
82
|
+
has_rdoc: true
|
83
|
+
homepage: https://rubygems.org/gems/rpx_regexp
|
84
|
+
licenses: []
|
85
|
+
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
hash: 3
|
97
|
+
segments:
|
98
|
+
- 0
|
99
|
+
version: "0"
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
hash: 3
|
106
|
+
segments:
|
107
|
+
- 0
|
108
|
+
version: "0"
|
109
|
+
requirements: []
|
110
|
+
|
111
|
+
rubyforge_project: rpx_crowdint
|
112
|
+
rubygems_version: 1.3.7
|
113
|
+
signing_key:
|
114
|
+
specification_version: 3
|
115
|
+
summary: Restrict who authenticates through Janrain with a regexp
|
116
|
+
test_files:
|
117
|
+
- test/test_helper.rb
|
118
|
+
- test/test_rpx_regexp.rb
|