omniauth-openam 1.0.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 71ed832328a1df617f419bf5f5e0e23adf8b0ed1
4
+ data.tar.gz: c236892a2cf3462468d01e6991f870bcc97d3144
5
+ SHA512:
6
+ metadata.gz: 6d72000930d6641e04406d708a7ee5dceda5d0b1609dc370bc98b61b598b3f8d26316af21b94a8632f1e7bd6b80cc0c2239ce5fbc24460526743a9847ce84ac8
7
+ data.tar.gz: cfc6ba82cedada1ba53148c53c610920df925e933478e08889e6f033691e17891f8466d975c4c737de365feed040a88c7cbc7e30bedb7e966429963571a26e1b
@@ -0,0 +1,44 @@
1
+ .ruby-version
2
+ .ruby-gemset
3
+ # rcov generated
4
+ coverage
5
+
6
+ # rdoc generated
7
+ rdoc
8
+
9
+ # yard generated
10
+ doc
11
+ .yardoc
12
+
13
+ # bundler
14
+ .bundle
15
+
16
+ # jeweler generated
17
+ pkg
18
+
19
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
20
+ #
21
+ # * Create a file at ~/.gitignore
22
+ # * Include files you want ignored
23
+ # * Run: git config --global core.excludesfile ~/.gitignore
24
+ #
25
+ # After doing this, these files will be ignored in all your git projects,
26
+ # saving you from having to 'pollute' every project you touch with them
27
+ #
28
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
29
+ #
30
+ # For MacOS:
31
+ #
32
+ #.DS_Store
33
+ #
34
+ # For TextMate
35
+ #*.tmproj
36
+ #tmtags
37
+ #
38
+ # For emacs:
39
+ #*~
40
+ #\#*
41
+ #.\#*
42
+ #
43
+ # For vim:
44
+ *.swp
@@ -0,0 +1,4 @@
1
+ rvm:
2
+ - 2.0.0
3
+ - 2.1.0
4
+ - ruby-head
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-github.gemspec
4
+ gemspec
@@ -0,0 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ omniauth-openam (1.0.0)
5
+ faraday
6
+ omniauth (~> 1.0)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ addressable (2.3.5)
12
+ crack (0.4.2)
13
+ safe_yaml (~> 1.0.0)
14
+ diff-lcs (1.2.5)
15
+ docile (1.1.2)
16
+ faraday (0.9.2)
17
+ multipart-post (>= 1.2, < 3)
18
+ hashie (3.4.3)
19
+ multi_json (1.8.4)
20
+ multipart-post (2.0.0)
21
+ omniauth (1.2.2)
22
+ hashie (>= 1.2, < 4)
23
+ rack (~> 1.0)
24
+ rack (1.5.2)
25
+ rack-test (0.6.2)
26
+ rack (>= 1.0)
27
+ rspec (2.14.1)
28
+ rspec-core (~> 2.14.0)
29
+ rspec-expectations (~> 2.14.0)
30
+ rspec-mocks (~> 2.14.0)
31
+ rspec-core (2.14.7)
32
+ rspec-expectations (2.14.5)
33
+ diff-lcs (>= 1.1.3, < 2.0)
34
+ rspec-mocks (2.14.5)
35
+ safe_yaml (1.0.1)
36
+ simplecov (0.8.2)
37
+ docile (~> 1.1.0)
38
+ multi_json
39
+ simplecov-html (~> 0.8.0)
40
+ simplecov-html (0.8.0)
41
+ webmock (1.17.2)
42
+ addressable (>= 2.2.7)
43
+ crack (>= 0.3.2)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ omniauth-openam!
50
+ rack-test
51
+ rspec (~> 2.7)
52
+ simplecov
53
+ webmock
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Rahul Ghose, 2015 MAK IT
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.
@@ -0,0 +1,58 @@
1
+ # OmniAuth OpenAM
2
+
3
+ [![Continuous Integration status](https://secure.travis-ci.org/mak-it/omniauth-openam.png)](http://travis-ci.org/mak-it/omniauth-openam)
4
+
5
+ OmniAuth strategy for authenticating to [OpenAM](https://www.forgerock.com/products/access-management/).
6
+
7
+ ## Installation
8
+
9
+ Add to your `Gemfile`:
10
+
11
+ ```ruby
12
+ gem 'omniauth-openam'
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ Here's a quick example, adding the middleware to a Rails app
18
+ in `config/initializers/omniauth.rb`:
19
+
20
+ ```ruby
21
+ Rails.application.config.middleware.use OmniAuth::Builder do
22
+ provider :openam, 'https://example.com/opensso'
23
+ end
24
+ ```
25
+
26
+ ## Auth Hash
27
+
28
+ Here's an example Auth Hash available in `request.env['omniauth.auth']`:
29
+
30
+ ```ruby
31
+ {
32
+ provider: "openam",
33
+ uid: "bjensen",
34
+ info: {
35
+ email: "bjensen@example.com",
36
+ first_name: "Barbara",
37
+ last_name: "Jensen",
38
+ name: "Babs Jensen",
39
+ username: "bjensen",
40
+ },
41
+ credentials: {
42
+ token: "AQIC5wM2LY4SfcxuxIP0VnP2lVjs7ypEM6VDx6srk56CN1Q.*AAJTSQACMDE.*"
43
+ },
44
+ extra: {
45
+ raw_info: {
46
+ token: "AQIC5wM2LY4SfcxuxIP0VnP2lVjs7ypEM6VDx6srk56CN1Q.*AAJTSQACMDE.*",
47
+ cn: ["Babs Jensen", "Barbara Jensen"],
48
+ dn: ["uid=bjensen,ou=people,dc=example,dc=com"],
49
+ givenname: ["Barbara"],
50
+ mail: ["bjensen@example.com"],
51
+ objectclass: ["organizationalPerson", "person", "inetOrgPerson", "top"],
52
+ sn: ["Jensen"],
53
+ telephonenumber: ["+1 408 555 1862"],
54
+ uid: ["bjensen"]
55
+ }
56
+ }
57
+ }
58
+ ```
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ desc 'Default: run specs.'
6
+ task :default => :spec
7
+
8
+ desc 'Run specs'
9
+ task :default => :spec
@@ -0,0 +1 @@
1
+ require 'omniauth/strategies/openam'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Openam
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,92 @@
1
+ require 'omniauth'
2
+ require 'faraday'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class OpenAM
7
+ include OmniAuth::Strategy
8
+
9
+ option :cookie_name, 'iPlanetDirectoryPro'
10
+
11
+ args [:auth_url]
12
+
13
+ attr_reader :token
14
+
15
+ uid do
16
+ raw_info['uid'][0]
17
+ end
18
+
19
+ info do
20
+ {
21
+ username: raw_info['uid'][0],
22
+ email: raw_info['mail'][0],
23
+ first_name: raw_info['givenname'][0],
24
+ last_name: raw_info['sn'][0],
25
+ name: raw_info['cn'][0]
26
+ }
27
+ end
28
+
29
+ credentials do
30
+ {
31
+ token: token
32
+ }
33
+ end
34
+
35
+ extra do
36
+ {
37
+ raw_info: raw_info
38
+ }
39
+ end
40
+
41
+ protected
42
+
43
+ def request_phase
44
+ redirect "#{options[:auth_url]}?goto=#{callback_url}"
45
+ end
46
+
47
+ def callback_phase
48
+ @token = request.cookies[options[:cookie_name]]
49
+ if token.nil?
50
+ e = RuntimeError.new("#{options[:cookie_name]} cookie is missing")
51
+ return fail!(:invalid_credentials, e)
52
+ end
53
+ if raw_info.empty?
54
+ e = RuntimeError.new("Identity attributes are empty")
55
+ return fail!(:invalid_credentials, e)
56
+ end
57
+ super
58
+ end
59
+
60
+ def raw_info
61
+ @raw_info ||= begin
62
+ conn = Faraday.new(url: options[:auth_url]) do |faraday|
63
+ faraday.request :url_encoded
64
+ faraday.response :logger, OmniAuth.logger
65
+ faraday.adapter Faraday.default_adapter
66
+ end
67
+ response = conn.post(
68
+ "#{URI(options[:auth_url]).path}/identity/attributes",
69
+ subjectid: token
70
+ )
71
+ attributes = Hash.new{ |h,k| h[k] = [] }
72
+ name = nil
73
+ lines = response.body.split("\n")
74
+ lines.each do |line|
75
+ key, value = line.split("=", 2)
76
+ case key
77
+ when 'userdetails.token.id'
78
+ attributes['token'] = value
79
+ when 'userdetails.attribute.name'
80
+ name = value
81
+ when 'userdetails.attribute.value'
82
+ attributes[name] << value
83
+ end
84
+ end
85
+ attributes
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+
92
+ OmniAuth.config.add_camelization 'openam', 'OpenAM'
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth-openam/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Edgars Beigarts"]
6
+ gem.email = ["edgars.beigarts@gmail.com"]
7
+ gem.description = "This is an OmniAuth provider for OpenAM's REST API"
8
+ gem.summary = "An OmniAuth provider for OpenAM REST API"
9
+ gem.homepage = "https://github.com/mak-it/omniauth-openam"
10
+ gem.license = "MIT"
11
+
12
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ gem.name = "omniauth-openam"
16
+ gem.require_paths = ["lib"]
17
+ gem.version = OmniAuth::Openam::VERSION
18
+
19
+ gem.add_dependency 'omniauth', '~> 1.0'
20
+ gem.add_dependency 'faraday'
21
+
22
+ gem.add_development_dependency 'rspec', '~> 2.7'
23
+ gem.add_development_dependency 'rack-test'
24
+ gem.add_development_dependency 'simplecov'
25
+ gem.add_development_dependency 'webmock'
26
+ end
@@ -0,0 +1,21 @@
1
+ userdetails.token.id=AQIC5wM2LY4SfcxuxIP0VnP2lVjs7ypEM6VDx6srk56CN1Q.*AAJTSQACMDE.*
2
+ userdetails.attribute.name=uid
3
+ userdetails.attribute.value=bjensen
4
+ userdetails.attribute.name=mail
5
+ userdetails.attribute.value=bjensen@example.com
6
+ userdetails.attribute.name=sn
7
+ userdetails.attribute.value=Jensen
8
+ userdetails.attribute.name=cn
9
+ userdetails.attribute.value=Babs Jensen
10
+ userdetails.attribute.value=Barbara Jensen
11
+ userdetails.attribute.name=givenname
12
+ userdetails.attribute.value=Barbara
13
+ userdetails.attribute.name=dn
14
+ userdetails.attribute.value=uid=bjensen,ou=people,dc=example,dc=com
15
+ userdetails.attribute.name=telephonenumber
16
+ userdetails.attribute.value=+1 408 555 1862
17
+ userdetails.attribute.name=objectclass
18
+ userdetails.attribute.value=organizationalPerson
19
+ userdetails.attribute.value=person
20
+ userdetails.attribute.value=inetOrgPerson
21
+ userdetails.attribute.value=top
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe OmniAuth::Strategies::OpenAM, type: :strategy do
4
+ include OmniAuth::Test::StrategyTestCase
5
+
6
+ let :token do
7
+ "AQIC5wM2LY4SfcxuxIP0VnP2lVjs7ypEM6VDx6srk56CN1Q.*AAJTSQACMDE.*"
8
+ end
9
+
10
+ def strategy
11
+ [OmniAuth::Strategies::OpenAM, "https://example.com/opensso"]
12
+ end
13
+
14
+ describe '/auth/openam' do
15
+ it 'redirects to OpenAM login page' do
16
+ get '/auth/openam'
17
+ expect(last_response).to be_redirect
18
+ expect(last_response.headers['Location']).to \
19
+ eq(
20
+ 'https://example.com/opensso'\
21
+ '?goto=http://example.org/auth/openam/callback'
22
+ )
23
+ end
24
+ end
25
+
26
+ describe '/auth/openam/callback' do
27
+ before do
28
+ stub_request(:post, "https://example.com/opensso/identity/attributes").
29
+ with(body: { subjectid: token }).
30
+ to_return(body: File.read(
31
+ File.expand_path(
32
+ '../../../fixtures/identity_attributes.txt', __FILE__
33
+ )
34
+ )
35
+ )
36
+ end
37
+
38
+ it 'retrieves identity attributes' do
39
+ get '/auth/openam/callback',
40
+ {},
41
+ { "HTTP_COOKIE" => "iPlanetDirectoryPro=#{token}" }
42
+ auth = last_request.env['omniauth.auth']
43
+ puts auth.inspect
44
+ expect(auth[:credentials][:token]).to eq(token)
45
+ expect(auth[:uid]).to eq('bjensen')
46
+ expect(auth[:info][:email]).to eq('bjensen@example.com')
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,14 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'rspec'
5
+ require 'rack/test'
6
+ require 'webmock/rspec'
7
+ require 'omniauth'
8
+ require 'omniauth-openam'
9
+
10
+ RSpec.configure do |config|
11
+ config.include WebMock::API
12
+ config.include Rack::Test::Methods
13
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
14
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-openam
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Edgars Beigarts
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack-test
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: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: This is an OmniAuth provider for OpenAM's REST API
98
+ email:
99
+ - edgars.beigarts@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".travis.yml"
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - lib/omniauth-openam.rb
112
+ - lib/omniauth-openam/version.rb
113
+ - lib/omniauth/strategies/openam.rb
114
+ - omniauth-openam.gemspec
115
+ - spec/fixtures/identity_attributes.txt
116
+ - spec/omniauth/strategies/openam_spec.rb
117
+ - spec/spec_helper.rb
118
+ homepage: https://github.com/mak-it/omniauth-openam
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.2.2
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: An OmniAuth provider for OpenAM REST API
142
+ test_files:
143
+ - spec/fixtures/identity_attributes.txt
144
+ - spec/omniauth/strategies/openam_spec.rb
145
+ - spec/spec_helper.rb