gris-toko_ohno 0.1.0

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: 0b7749099abd8b57f057eb2b28ad45c394e731f2
4
+ data.tar.gz: 4e4785e71bab5cea1344834de7169bab47bcd76c
5
+ SHA512:
6
+ metadata.gz: 477b9d92f3c8ea3188e9156268c213f13c680f189aaad71e14b747da33f8ba24258f10c390318e4e7530ead2911e17aea5646eb1bb4624e7efa5749f53e11b65
7
+ data.tar.gz: fa82b978b7b28e79a42094d20d5660ae3363396d7d859b292eff6897f814d076acac71368310a5c61368a37996294baa3e3c8bea6bcd6fabb0b092c7ef422106
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gris-toko_ohno.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Dylan Fareed
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,123 @@
1
+ # Gris::TokoOhno
2
+
3
+ [Gris::TokoOhno](https://github.com/dylanfareed/gris-toko_ohno) is a simple helper providing token authentication via headers or params in your [Gris](https://github.com/artsy/gris) app's Grape endpoints.
4
+
5
+ Conveniently, Gris::TokoOhno is tied to `Gris.secrets` so that you can ensure that requests match values set in your ENV.
6
+
7
+ ---
8
+
9
+ ### Installation
10
+
11
+ Gris::TokoOhno is [available as a gem on rubygems](https://github.com/dylanfareed/gris-toko_ohno), to install it run:
12
+
13
+ ```
14
+ gem install gris-toko_ohno
15
+ ```
16
+
17
+ Otherwise, if your project uses [Bundler](http://bundler.io/), add gris-toko_ohno to your Gemfile:
18
+
19
+ ```
20
+ gem 'gris-toko_ohno'
21
+ ```
22
+
23
+ And run:
24
+
25
+ ```
26
+ $ bundle install
27
+ ```
28
+
29
+ ---
30
+
31
+ ### Usage
32
+
33
+ Once you have installed or bundled gris-toko_ohno with your Gris app, using it is a two-step process. You must set the Gris.secrets for your permitted tokens as environment variables and then add the token_authenticate! helper in your endpoints.
34
+
35
+ ##### Set the ENV value
36
+
37
+ By default, Gris::TokoOhno will verify inbound requests against values set in `Gris.secrets.permitted_tokens`. To set a value for `permitted_tokens`, simply add it to your Gris config/secrets.yml file.
38
+
39
+ ```
40
+ default: &default
41
+ service_name: my_secure_service
42
+ permitted_tokens: <%= ENV['PERMITTED_TOKENS'] %>
43
+ base_url: <%= ENV['BASE_URL'] || 'http://localhost:9292' %>
44
+ ```
45
+
46
+ The value set in your environment should be a string and may be separated by comma(s).
47
+
48
+ You can also use custom secret names (if you wanted to provide multiple checks with different tokens over different endpoints, for example) by simply defining a different secret value.
49
+
50
+ ```
51
+ default: &default
52
+ service_name: my_secure_service
53
+ other_tokens: <%= ENV['OTHER_TOKENS'] %>
54
+ base_url: <%= ENV['BASE_URL'] || 'http://localhost:9292' %>
55
+ ```
56
+
57
+ You would then have to specify the custom secret when you call token_authenticate! per the instructions below.
58
+
59
+ ##### Add token_authenticate! to your endpoints
60
+
61
+ To authenticate a particular endpoint:
62
+
63
+ ```ruby
64
+ class ApplicationEndpoint < Grape::API
65
+ # Authenticated
66
+ get do
67
+ token_authentication!
68
+ present self, with: RootPresenter
69
+ end
70
+
71
+ # Not authenticated
72
+ get '/hello' do
73
+ present self, with: RootPresenter
74
+ end
75
+ end
76
+ ```
77
+
78
+ You can also authenticate all endpoints in an API using Grape helpers.
79
+
80
+ ```ruby
81
+ class ApplicationEndpoint < Grape::API
82
+ before do
83
+ token_authentication!
84
+ end
85
+
86
+ # Authenticated
87
+ get do
88
+ present self, with: RootPresenter
89
+ end
90
+
91
+ # Authenticated
92
+ get '/hello' do
93
+ present self, with: RootPresenter
94
+ end
95
+ end
96
+ ```
97
+
98
+ The helper will check against `Gris.secrets.permitted_tokens` by default, but you can also choose to specify a custom Gris.secrets value.
99
+
100
+ To verify that a request provides token or header credentials that match `Gris.secrets.other_tokens` (for example):
101
+
102
+ ```ruby
103
+ class ApplicationEndpoint < Grape::API
104
+ get do
105
+ token_authentication! :other_tokens
106
+ present self, with: RootPresenter
107
+ end
108
+ end
109
+ ```
110
+
111
+ ## Contributing
112
+
113
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dylanfareed/gris-toko_ohno. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
114
+
115
+
116
+ ## License
117
+
118
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
119
+
120
+
121
+ ## Context
122
+
123
+ ![yoko-ono-war-is-over-if-you-want-it](https://cloud.githubusercontent.com/assets/197336/9416396/6a91989c-4813-11e5-8541-75946f714ac1.jpg)
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ desc 'Run RuboCop'
10
+ RuboCop::RakeTask.new(:rubocop) do |task|
11
+ task.fail_on_error = true
12
+ task.options = %w(-D --auto-correct)
13
+ end
14
+
15
+ task default: [:rubocop, :spec]
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gris/toko_ohno/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'gris-toko_ohno'
8
+ spec.version = Gris::TokoOhno::VERSION
9
+ spec.authors = ['Dylan Fareed']
10
+ spec.email = ['email@dylanfareed.com']
11
+
12
+ spec.summary = 'Header or token auth for Gris apps.'
13
+ spec.description = 'Header or token auth for Gris apps.'
14
+ spec.homepage = 'https://github.com/dylanfareed/gris-toko_ohno'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`
18
+ .split("\x0")
19
+ .reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_dependency 'gris'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.10'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec'
29
+ spec.add_development_dependency 'rubocop'
30
+ spec.add_development_dependency 'byebug'
31
+ end
@@ -0,0 +1,6 @@
1
+ module Gris
2
+ # Header or token auth for Gris apps.
3
+ module TokoOhno
4
+ VERSION = '0.1.0'
5
+ end
6
+ end
@@ -0,0 +1,32 @@
1
+ require 'gris/toko_ohno/version'
2
+
3
+ module Gris
4
+ # Header or token auth for Gris apps.
5
+ module TokoOhno
6
+ def token_authentication!(key_sym = :permitted_tokens)
7
+ error!('Forbidden', 401) unless permitted?(key_sym)
8
+ end
9
+
10
+ private
11
+
12
+ def permitted?(key_sym)
13
+ permit_by_headers(key_sym) || permit_by_params(key_sym)
14
+ end
15
+
16
+ def permit_by_headers(key_sym)
17
+ return unless request.headers['Http-Authorization']
18
+ permitted_tokens(key_sym).include? request.headers['Http-Authorization']
19
+ end
20
+
21
+ def permit_by_params(key_sym)
22
+ return unless params[:token]
23
+ permitted_tokens(key_sym).include? params[:token]
24
+ end
25
+
26
+ def permitted_tokens(key_sym)
27
+ Gris.secrets.send(key_sym).split(',')
28
+ end
29
+
30
+ Grape::API.send :include, self if defined?(Grape)
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gris-toko_ohno
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dylan Fareed
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gris
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
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: rubocop
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: byebug
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: Header or token auth for Gris apps.
98
+ email:
99
+ - email@dylanfareed.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - CODE_OF_CONDUCT.md
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/setup
112
+ - gris-toko_ohno.gemspec
113
+ - lib/gris/toko_ohno.rb
114
+ - lib/gris/toko_ohno/version.rb
115
+ homepage: https://github.com/dylanfareed/gris-toko_ohno
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.4.8
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Header or token auth for Gris apps.
139
+ test_files: []