noxy 0.3.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 69b63b40aba3c20978bbae0708d1d1c8e5ee59c7
4
+ data.tar.gz: 1790f0cbd28b5569b7f0fe237874cfd00b6dedfc
5
+ SHA512:
6
+ metadata.gz: 5219740c32aa0f43c846e8f642d49b752efb42155704c58359820da9e9279ac0527bbfa5808794e9b4e11da59aabce07201c1742942e4c84168d64b54baa34d3
7
+ data.tar.gz: 25ad93fe3167dbedfb74b45104cccf4a853401c271be7eb2411b3d9ebbd1aae801aa5761b8ba727ba181ba765dfb05306a10259fa5cc4283bdb75b7bf879716b
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /test
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in noxy.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 D.Kainama
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,101 @@
1
+ # Noxy
2
+
3
+ A simple gem for handling Google Domain Authorization.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'noxy'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install noxy
20
+
21
+ ## Usage
22
+
23
+ **WARNING:** You must enable Google Contacts API and Google Plus API when creating client, https://console.developers.google.com.
24
+
25
+
26
+ Pre-Configure Noxy:
27
+
28
+ Noxy.configure do | option |
29
+ option.app = "SoundFruit"
30
+ option.client = "foo"
31
+ option.secret = "bar20oo0)"
32
+ option.session = "some.shared.common.secret"
33
+ option.proxy = -> { check(authorization)}
34
+ end
35
+
36
+ Add Noxy to a Sinara app.
37
+
38
+ class Foo < Sinatra::Base
39
+ register Noxy::Auth
40
+ end
41
+
42
+ Configure Noxy from a Sinara app.
43
+
44
+ class Foo < Sinatra::Base
45
+ ...
46
+ noxy.app = "DogSmash"
47
+ noxy.proxy = -> {
48
+
49
+ # authorization hash is available.
50
+ authorization.info.email
51
+ }
52
+ end
53
+
54
+ Following helpers available
55
+
56
+ class Foo < Sinatra::Base
57
+ ...
58
+ before do
59
+ unless authorized?
60
+ halt 401
61
+ end
62
+ end
63
+
64
+
65
+ get "/hit" do
66
+ "Hit the dog"
67
+ end
68
+ end
69
+
70
+
71
+ To redirect to Google Auth page, visit this link
72
+
73
+ a href=("/auth/google_oauth2") Inloggen
74
+
75
+
76
+ By default the following routes are defined:
77
+
78
+ [GET] /auth/google_oauth2/callback
79
+ [POST] /auth/google_oauth2/callback
80
+
81
+ Both are needed for handling the callback from Google.
82
+ When the callback from Google is completed the `Noxy.proxy` will be called.
83
+
84
+
85
+
86
+ ## Todo (3.1.2)
87
+
88
+ * Make path in cookie configurable (./lib/noxy/sinatra.rb)
89
+ * Clean up test / example Sinatra app for push
90
+ * Write more specs.
91
+
92
+ * Make secreat / client_id readable from custom location
93
+ ,i.e: ~/.secure/app/.
94
+
95
+ ## Contributing
96
+
97
+ 1. Fork it ( https://github.com/amaniak/noxy/fork )
98
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
99
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
100
+ 4. Push to the branch (`git push origin my-new-feature`)
101
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/lib/noxy.rb ADDED
@@ -0,0 +1,51 @@
1
+ # core
2
+ require "rack"
3
+ require "logger"
4
+ require "hashie"
5
+ require "omniauth-google-oauth2"
6
+ require "delegate"
7
+
8
+ # active_support
9
+ require "active_support/core_ext/module/delegation"
10
+
11
+ # version
12
+ require "noxy/version"
13
+
14
+ # configuration
15
+ require "noxy/options"
16
+ require "noxy/configuration"
17
+
18
+ # domain validation
19
+ require "noxy/sinatra"
20
+
21
+
22
+ # Noxy module
23
+
24
+ module Noxy
25
+
26
+ extend self
27
+
28
+ # Logging for module
29
+ # @param body [String] String to send to logger.
30
+
31
+ def self.log(body)
32
+ @logger ||= Logger.new(STDOUT)
33
+ @logger.debug "[Noxy]: #{body}"
34
+ end
35
+
36
+ # Make module configurable
37
+ # @param [block] accepts a optional block
38
+ # @return []
39
+
40
+ def configure
41
+ block_given? ? yield(Noxy::Configuration) : Noxy::Configuration
42
+ end
43
+
44
+ # Delegate all public
45
+ # instance methods from Configuration to Noxy
46
+
47
+ delegate(*(
48
+ Noxy::Configuration.public_instance_methods(false) <<
49
+ { to: Noxy::Configuration }))
50
+
51
+ end
@@ -0,0 +1,28 @@
1
+ module Noxy
2
+ module Configuration
3
+
4
+ LOCK = Mutex.new
5
+
6
+ extend self
7
+ extend Options
8
+
9
+ option :app, default: ""
10
+ option :session, default: ""
11
+ option :client, default: ""
12
+ option :secret, default: ""
13
+ option :proxy, default: -> {}
14
+
15
+ def options=(options)
16
+
17
+ # Mutex for future threaded env.
18
+ LOCK.synchronize do
19
+ if options
20
+ options.each_pair do |option, value|
21
+ send("#{option}=", value)
22
+ end
23
+ end
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,33 @@
1
+ module Noxy
2
+ module Options
3
+
4
+ def defaults
5
+ @defaults ||= {}
6
+ end
7
+
8
+ def option(name, options = {})
9
+ defaults[name] = settings[name] = options[:default]
10
+
11
+ class_eval <<-RUBY
12
+
13
+ def #{name}
14
+ settings[#{name.inspect}]
15
+ end
16
+
17
+ def #{name}=(value)
18
+ settings[#{name.inspect}] = value
19
+ end
20
+
21
+ def #{name}?
22
+ #{name}
23
+ end
24
+
25
+ RUBY
26
+ end
27
+
28
+ def settings
29
+ @settings ||= {}
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,58 @@
1
+ require "noxy"
2
+
3
+ module Noxy
4
+ module Auth
5
+
6
+ # helpers
7
+ module Helpers
8
+
9
+ def authorized?
10
+ session['noxy.authorized']
11
+ end
12
+
13
+ def authorization
14
+ request.env['omniauth.auth']
15
+ end
16
+
17
+ end
18
+
19
+ # After register callback when Noxy
20
+ # is embedded in a Sinatra app.
21
+ # @param app [Hash] Base app.
22
+ # @return [Void]
23
+
24
+ def self.registered(app)
25
+
26
+ # Noxy
27
+ app.set :noxy, Proc.new { Noxy }
28
+
29
+ # Create a session cookie: store
30
+ # auth data securely accross multiple domains.
31
+
32
+ app.use Rack::Session::Cookie,
33
+ key: "#{app.noxy.app}.noxy.session",
34
+ secret: "#{app.noxy.session}",
35
+ path: '/'
36
+
37
+ # plug and play OmniAuth - Google OAuth2
38
+ app.use OmniAuth::Builder do
39
+ provider :google_oauth2, app.noxy.client, app.noxy.secret
40
+ end
41
+
42
+ # define proxy lambda, so the proxy lambda,
43
+ # from Noxy is configurable and
44
+ # is executed on app instance.
45
+
46
+ proxy = -> { self.instance_exec &app.noxy.proxy }
47
+
48
+ # setup, make sure it's handled on GET and POST
49
+ app.get '/auth/:name/callback', &proxy
50
+ app.post '/auth/:name/callback', &proxy
51
+
52
+
53
+ # set module as helper
54
+ app.helpers Helpers
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ module Noxy
2
+ VERSION = "0.3.1"
3
+ end
data/noxy.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'noxy/version'
6
+
7
+ Gem::Specification.new do |gem|
8
+
9
+ gem.name = "noxy"
10
+ gem.version = Noxy::VERSION
11
+ gem.authors = ["DK"]
12
+ gem.email = ["amaniak@noxqs.nl"]
13
+ gem.summary = %q{Google Apps domain authentication}
14
+ gem.description = %q{Basic support for Google Apps authentication}
15
+ gem.homepage = "http://noxqs.nl"
16
+ gem.license = "MIT"
17
+
18
+
19
+ gem.files = `git ls-files -z`.split("\x0")
20
+ gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
22
+ gem.require_paths = ["lib"]
23
+
24
+ gem.add_dependency "hashie"
25
+ gem.add_dependency "sinatra-contrib"
26
+ gem.add_dependency "omniauth-google-oauth2"
27
+ gem.add_dependency "activesupport"
28
+
29
+ gem.add_development_dependency "bundler", "~> 1.7"
30
+ gem.add_development_dependency "rake", "~> 10.0"
31
+ gem.add_development_dependency "pry"
32
+ gem.add_development_dependency "rspec"
33
+ gem.add_development_dependency "rack-test"
34
+ gem.add_development_dependency "yard"
35
+ end
data/spec/noxy_spec.rb ADDED
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+ require 'securerandom'
3
+
4
+ describe Noxy do
5
+
6
+ before do
7
+
8
+ @app = "Tindr"
9
+ @session = SecureRandom.hex(16)
10
+ @client = SecureRandom.hex(16)
11
+ @secret = SecureRandom.hex(16)
12
+ @proxy = lambda {}
13
+
14
+ Noxy.configure do | n |
15
+ n.app = @app
16
+ n.session = @session
17
+ n.client = @client
18
+ n.secret = @secret
19
+ n.proxy = @proxy
20
+ end
21
+ end
22
+
23
+ it "should have a settings object" do
24
+ expect(Noxy.configure).to eq(Noxy::Configuration)
25
+ end
26
+
27
+ it "should have a app property" do
28
+ expect(Noxy.app).to eq(@app)
29
+ end
30
+
31
+ it "should have a session object" do
32
+ expect(Noxy.session).to eq(@session)
33
+ end
34
+
35
+ it "should have a client object" do
36
+ expect(Noxy.client).to eq(@client)
37
+ end
38
+
39
+ it "should have a secret object" do
40
+ expect(Noxy.secret).to eq(@secret)
41
+ end
42
+
43
+ it "should have a proxy object" do
44
+ expect(Noxy.proxy).to eq(@proxy)
45
+ end
46
+
47
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'noxy'
4
+
5
+ RSpec.configure do |config|
6
+ config.color = true
7
+ config.formatter = 'documentation'
8
+ end
metadata ADDED
@@ -0,0 +1,200 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: noxy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1
5
+ platform: ruby
6
+ authors:
7
+ - DK
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hashie
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sinatra-contrib
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: omniauth-google-oauth2
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'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
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: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rack-test
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: yard
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: Basic support for Google Apps authentication
154
+ email:
155
+ - amaniak@noxqs.nl
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - Gemfile
162
+ - LICENSE.txt
163
+ - README.md
164
+ - Rakefile
165
+ - lib/noxy.rb
166
+ - lib/noxy/configuration.rb
167
+ - lib/noxy/options.rb
168
+ - lib/noxy/sinatra.rb
169
+ - lib/noxy/version.rb
170
+ - noxy.gemspec
171
+ - spec/noxy_spec.rb
172
+ - spec/spec_helper.rb
173
+ homepage: http://noxqs.nl
174
+ licenses:
175
+ - MIT
176
+ metadata: {}
177
+ post_install_message:
178
+ rdoc_options: []
179
+ require_paths:
180
+ - lib
181
+ required_ruby_version: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ version: '0'
186
+ required_rubygems_version: !ruby/object:Gem::Requirement
187
+ requirements:
188
+ - - ">="
189
+ - !ruby/object:Gem::Version
190
+ version: '0'
191
+ requirements: []
192
+ rubyforge_project:
193
+ rubygems_version: 2.4.4
194
+ signing_key:
195
+ specification_version: 4
196
+ summary: Google Apps domain authentication
197
+ test_files:
198
+ - spec/noxy_spec.rb
199
+ - spec/spec_helper.rb
200
+ has_rdoc: