omniauth-pam 1.3.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/omniauth-pam/version.rb +1 -1
- data/lib/omniauth/pam.rb +1 -2
- data/lib/omniauth/strategies/pam.rb +19 -26
- data/omniauth-pam.gemspec +2 -3
- data/spec/omniauth/strategies/pam_spec.rb +14 -19
- metadata +5 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42f231c42e7642db6d111c52d4eafce71b8e68e973da9de38ac34ca1a9334cf5
|
4
|
+
data.tar.gz: ecaef201a88402649d3328dd15cfd9f4cc2415387f540802d9dcd5464eaff1c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb5789493f26df5653c0b6a60ac707919230ea5b3a430145f07c504e3624d97dc8e4970294f6a2ed678a61f414c4732e443d4a78daa3e4ff60e005dd27ca44f2
|
7
|
+
data.tar.gz: 05d8e2414f63dd6689c759e745a1dcb197964d91c9321c599feb23fda6392f92ea395110e375ae1c5c05642cd862a6058024a4d76d7b10515b189c6779e4495a
|
data/CHANGELOG.md
CHANGED
data/lib/omniauth-pam/version.rb
CHANGED
data/lib/omniauth/pam.rb
CHANGED
@@ -6,16 +6,17 @@ module OmniAuth
|
|
6
6
|
option :name, 'pam'
|
7
7
|
option :fields, [:username]
|
8
8
|
option :uid_field, :username
|
9
|
-
|
10
|
-
# this
|
11
|
-
option :
|
12
|
-
#
|
13
|
-
#
|
9
|
+
# if provided, info.email is build using uid@email_domain
|
10
|
+
# this is used if :email is not found in pam environment
|
11
|
+
option :email_domain, nil
|
12
|
+
# pam service name passed to rpam2 (/etc/pam.d/service_name)
|
13
|
+
# if not provided rpam2 uses 'rpam'
|
14
|
+
option :service, nil
|
14
15
|
|
15
16
|
def request_phase
|
16
17
|
OmniAuth::Form.build(
|
17
|
-
:
|
18
|
-
:
|
18
|
+
title: (options[:title] || "Authenticate"),
|
19
|
+
url: callback_path,
|
19
20
|
) do |field|
|
20
21
|
field.text_field 'Username', 'username'
|
21
22
|
field.password_field 'Password', 'password'
|
@@ -23,13 +24,9 @@ module OmniAuth
|
|
23
24
|
end
|
24
25
|
|
25
26
|
def callback_phase
|
26
|
-
|
27
|
-
rpam_opts[:service] = options[:service] unless options[:service].nil?
|
28
|
-
|
29
|
-
unless Rpam.auth(request['username'], request['password'], rpam_opts)
|
27
|
+
unless Rpam2.auth(options[:service], uid, request["password"])
|
30
28
|
return fail!(:invalid_credentials)
|
31
29
|
end
|
32
|
-
|
33
30
|
super
|
34
31
|
end
|
35
32
|
|
@@ -38,21 +35,17 @@ module OmniAuth
|
|
38
35
|
end
|
39
36
|
|
40
37
|
info do
|
41
|
-
info = { :
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
begin
|
51
|
-
gecos = Etc.getpwnam(uid).gecos.split(',')
|
52
|
-
Hash[options[:gecos_map].zip(gecos)].delete_if { |k, v| v.nil? || v.empty? }
|
53
|
-
rescue
|
54
|
-
end
|
38
|
+
info = { nickname: uid, name: uid }
|
39
|
+
rpam_env = Rpam2.listenv(options[:service], uid, request["password"])
|
40
|
+
# if authentication fails fall back to empty dictionary
|
41
|
+
info.merge!(rpam_env || {})
|
42
|
+
# info should contain now email if email in pam environment
|
43
|
+
# and authentication successful
|
44
|
+
# fallback if email is not in listenv
|
45
|
+
if info[:email].nil? && !options[:email_domain].nil?
|
46
|
+
info[:email] = "#{uid}@#{options[:email_domain]}"
|
55
47
|
end
|
48
|
+
info
|
56
49
|
end
|
57
50
|
end
|
58
51
|
end
|
data/omniauth-pam.gemspec
CHANGED
@@ -18,9 +18,8 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.test_files = s.files.grep(/^(test|spec|features)/)
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
s.add_runtime_dependency
|
22
|
-
s.add_runtime_dependency '
|
23
|
-
s.add_runtime_dependency 'etc'
|
21
|
+
s.add_runtime_dependency 'omniauth', '~> 1.5'
|
22
|
+
s.add_runtime_dependency 'rpam2', '~> 4.0'
|
24
23
|
|
25
24
|
s.add_development_dependency "pry"
|
26
25
|
s.add_development_dependency "rack-test"
|
@@ -1,6 +1,20 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe OmniAuth::Strategies::PAM do
|
4
|
+
before(:all) do
|
5
|
+
Rpam2.fake_data =
|
6
|
+
{
|
7
|
+
usernames: Set["authur"],
|
8
|
+
servicenames: Set["rpam", nil],
|
9
|
+
password: "a_password",
|
10
|
+
env:
|
11
|
+
{
|
12
|
+
email: "me@example.com",
|
13
|
+
name: "Authur Dent",
|
14
|
+
},
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
4
18
|
describe "#request_phase" do
|
5
19
|
it "displays a form" do
|
6
20
|
get "/auth/pam"
|
@@ -12,21 +26,17 @@ describe OmniAuth::Strategies::PAM do
|
|
12
26
|
describe "#callback_phase" do
|
13
27
|
context "with valid credentials" do
|
14
28
|
it "populates the auth hash" do
|
15
|
-
mock_rpam(valid_credentials.merge(opts: {})).and_return(true)
|
16
|
-
mock_etc
|
17
29
|
|
18
30
|
post "/auth/pam/callback", valid_credentials
|
19
31
|
|
20
32
|
expect(auth_hash["provider"]).to eq("pam")
|
21
33
|
expect(auth_hash["uid"]).to eq("authur")
|
22
34
|
expect(auth_hash["info"]["name"]).to eq("Authur Dent")
|
23
|
-
expect_rpam_to_be_called(valid_credentials.merge(opts: {}))
|
24
35
|
end
|
25
36
|
end
|
26
37
|
|
27
38
|
context "with invalid credentials" do
|
28
39
|
it "redirects to /auth/failure" do
|
29
|
-
mock_rpam(invalid_credentials.merge(opts: {}))
|
30
40
|
|
31
41
|
post "/auth/pam/callback", invalid_credentials
|
32
42
|
|
@@ -34,7 +44,6 @@ describe OmniAuth::Strategies::PAM do
|
|
34
44
|
expect(last_response.headers["Location"]).to eq(
|
35
45
|
"/auth/failure?message=invalid_credentials&strategy=pam",
|
36
46
|
)
|
37
|
-
expect_rpam_to_be_called(invalid_credentials.merge(opts: {}))
|
38
47
|
end
|
39
48
|
end
|
40
49
|
end
|
@@ -62,18 +71,4 @@ describe OmniAuth::Strategies::PAM do
|
|
62
71
|
{ username: "not_a_valid_user", password: "not_a_valid_password" }
|
63
72
|
end
|
64
73
|
|
65
|
-
def mock_rpam(username:, password:, opts:)
|
66
|
-
allow(Rpam).to receive(:auth).with(username, password, opts)
|
67
|
-
end
|
68
|
-
|
69
|
-
def expect_rpam_to_be_called(username:, password:, opts: {})
|
70
|
-
expect(Rpam).to have_received(:auth).with(username, password, opts)
|
71
|
-
end
|
72
|
-
|
73
|
-
def mock_etc
|
74
|
-
etc_struct = Etc::Passwd.new
|
75
|
-
etc_struct.gecos = "Authur Dent,,"
|
76
|
-
|
77
|
-
expect(Etc).to receive(:getpwnam).with("authur").and_return(etc_struct)
|
78
|
-
end
|
79
74
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-pam
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Charlton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: omniauth
|
@@ -25,33 +25,19 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rpam2
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '4.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: etc
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
40
|
+
version: '4.0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: pry
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|