omniauth-owa 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 815d361335614c9a79882212cb02a1ad4da2a59d
4
+ data.tar.gz: ef1129aca4e8b757031e7c4c7c56f6921d8a6f88
5
+ SHA512:
6
+ metadata.gz: 6961e2cb38bfc73d3e1844f315e714bd2f492c1cb28bf6051e5366a234005f5d232095c6fc17bba0ddec7016dc163d77849798faddf789963020ef0dcf71c25d
7
+ data.tar.gz: 286d4af7a081abb918de73a825b783743e64694a8d8c803f6963fc78be31cce6bc42520e4ad610a7504bb99d730d6a9b5453cdb17a7b8fac0823bc66cb5aaef5
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ Gemfile.lock
2
+ .rvmrc
3
+ omniauth-owa-0.0.1.gem
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ ruby "2.1.0"
4
+
5
+ gemspec
@@ -0,0 +1 @@
1
+ require_relative "omniauth/strategies/owa"
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Owa
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,47 @@
1
+ require "omniauth"
2
+ require "faraday"
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class OWA
7
+ include OmniAuth::Strategy
8
+ OmniAuth.config.add_camelization "owa", "OWA"
9
+
10
+ def request_phase
11
+ form = OmniAuth::Form.new url: callback_path
12
+ form.text_field "Username", :uid
13
+ form.password_field "Password", :password
14
+ form.button "Log in"
15
+ form.to_response
16
+ end
17
+
18
+ def callback_phase
19
+ uid, password = request.params.values_at "uid", "password"
20
+
21
+ conn = Faraday.new url: options.base_url
22
+ conn.basic_auth uid, password
23
+
24
+ search_results = conn.get("/owa/?ae=Dialog&t=AddressBook&ctx=1&sch=#{uid}").body
25
+ id = search_results.match(/<h1><a href="#" id="([^"]+)"/)[1]
26
+ details = conn.get("/owa/?ae=Item&t=AD.RecipientType.User&id=#{CGI.escape id}").body
27
+
28
+ @first_name = details.match(/<td[^>]*>First name<\/td><td[^>]*>([^<]*)/)[1]
29
+ @last_name = details.match(/<td[^>]*>Last name<\/td><td[^>]*>([^<]*)/)[1]
30
+ @name = "#{@first_name} #{@last_name}"
31
+ super
32
+ end
33
+
34
+ uid do
35
+ request.params.fetch "uid"
36
+ end
37
+
38
+ info do
39
+ {
40
+ name: @name,
41
+ first_name: @first_name,
42
+ last_name: @last_name,
43
+ }
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/omniauth-owa/version", __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.add_runtime_dependency "omniauth", "~> 1.0"
6
+ gem.add_runtime_dependency "faraday", "~> 0.9"
7
+
8
+ gem.add_development_dependency "nokogiri", "~> 1.6"
9
+ gem.add_development_dependency "rake", "~> 10.0"
10
+ gem.add_development_dependency "rack-test", "~> 0.6"
11
+ gem.add_development_dependency "rspec", "~> 2.14"
12
+ gem.add_development_dependency "webmock", "~> 1.17"
13
+
14
+ gem.name = "omniauth-owa"
15
+ gem.version = OmniAuth::Owa::VERSION
16
+ gem.description = "Omniauth strategy to authenticate against an Outlook Web Access server."
17
+ gem.summary = gem.description
18
+ gem.email = ["kerryjbuckley@gmail.com"]
19
+ gem.homepage = "http://github.com/kerryb/omniauth-owa"
20
+ gem.authors = ["Kerry Buckley"]
21
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
22
+ gem.files = `git ls-files`.split("\n")
23
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
+ gem.require_paths = ["lib"]
25
+ gem.required_rubygems_version = Gem::Requirement.new(">= 1.3.6") if gem.respond_to? :required_rubygems_version=
26
+ end
@@ -0,0 +1,88 @@
1
+ require "rack/test"
2
+ require "nokogiri"
3
+ require "omniauth/test"
4
+ require "webmock/rspec"
5
+
6
+ require "omniauth/strategies/owa"
7
+ require "omniauth/strategies/owa"
8
+
9
+ describe OmniAuth::Strategies::OWA do
10
+ include Rack::Test::Methods
11
+
12
+ let(:app) do
13
+ Rack::Builder.new do |b|
14
+ b.use Rack::Session::Cookie, :secret => "secret"
15
+ b.use OmniAuth::Strategies::OWA, base_url: "https://mail.example.com"
16
+ b.run ->(_env) { [200, {}, [""]] }
17
+ end.to_app
18
+ end
19
+
20
+ it "camelizes itself to 'OWA'" do
21
+ expect(OmniAuth::Utils.camelize"owa").to eq "OWA"
22
+ end
23
+
24
+ describe "request phase" do
25
+ let(:html) { Nokogiri::HTML last_response.body }
26
+
27
+ before { get "/auth/owa" }
28
+
29
+ it "displays a form with the callback path" do
30
+ expect(html.xpath("//form/@action").text).to eq "/auth/owa/callback"
31
+ end
32
+
33
+ it "displays a uid field" do
34
+ expect(html.xpath("//form/input[@type='text'][@name='uid']")).not_to be_empty
35
+ end
36
+
37
+ it "displays a password field" do
38
+ expect(html.xpath("//form/input[@type='password'][@name='password']")).not_to be_empty
39
+ end
40
+
41
+ it "displays a 'Log in' button" do
42
+ expect(html.xpath("//form/button[@type='submit']/text()").text).to eq "Log in"
43
+ end
44
+ end
45
+
46
+ describe "callback phase" do
47
+ let(:auth_hash) { last_request.env["omniauth.auth"] }
48
+
49
+ before do
50
+ stub_request(:get, "https://fred:secret@mail.example.com/owa/?ae=Dialog&t=AddressBook&ctx=1&sch=fred").
51
+ to_return body: <<-EOF
52
+ Blah blah
53
+ <h1><a href=\"#\" id=\"an=id\" onClick=\"return onClkRcpt(this, 1);\">Fred Bloggs</a></h1>
54
+ blah
55
+ EOF
56
+
57
+ stub_request(:get, "https://fred:secret@mail.example.com/owa/?ae=Item&t=AD.RecipientType.User&id=an%3Did").
58
+ to_return body: <<-EOF
59
+ Blah blah
60
+ <tr><td class="lbl lp" nowrap>First name</td><td class="txvl">Fred</td></tr>
61
+ <tr><td class="lbl lp" nowrap>Last name</td><td class="txvl">Bloggs</td></tr>
62
+ blah
63
+ EOF
64
+
65
+ post "/auth/owa/callback", uid: "fred", password: "secret"
66
+ end
67
+
68
+ it "sets the uid to the value submitted" do
69
+ expect(auth_hash.uid).to eq "fred"
70
+ end
71
+
72
+ it "sets the name in the auth hash" do
73
+ expect(auth_hash.info.name).to eq("Fred Bloggs")
74
+ end
75
+
76
+ it "sets the first name in the auth hash" do
77
+ expect(auth_hash.info.first_name).to eq("Fred")
78
+ end
79
+
80
+ it "sets the last name in the auth hash" do
81
+ expect(auth_hash.info.last_name).to eq("Bloggs")
82
+ end
83
+
84
+ context "when authentication fails" do
85
+ it "does something..."
86
+ end
87
+ end
88
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-owa
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kerry Buckley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-20 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.9'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.14'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.14'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.17'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.17'
111
+ description: Omniauth strategy to authenticate against an Outlook Web Access server.
112
+ email:
113
+ - kerryjbuckley@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - Gemfile
120
+ - lib/omniauth-owa.rb
121
+ - lib/omniauth-owa/version.rb
122
+ - lib/omniauth/strategies/owa.rb
123
+ - omniauth-owa.gemspec
124
+ - spec/omniauth/strategies/owa_spec.rb
125
+ homepage: http://github.com/kerryb/omniauth-owa
126
+ licenses: []
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: 1.3.6
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.2.0.rc.1
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Omniauth strategy to authenticate against an Outlook Web Access server.
148
+ test_files:
149
+ - spec/omniauth/strategies/owa_spec.rb