rack-micro_service-signed_request 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +10 -0
- data/README.md +83 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rack/micro_service/signed_request.rb +59 -0
- data/lib/rack/micro_service/signed_request/version.rb +7 -0
- data/rack-micro_service-signed_request.gemspec +29 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9345159dec6b0133d73adb70efb48f806590a1d9
|
4
|
+
data.tar.gz: dfa7e9e0694d10fdeeb5def35adc0ad4735ab689
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 788c806a6d3d7b706f288bad991ffb64cac08bfd5263d76f2673a8010dd4336f79035e333b58b4d19fb343c6074b5cf9e3ea9ebaa11b21fd1e94c12f7d593496
|
7
|
+
data.tar.gz: 49d087f9e11fddcd331ca62b2412cebe5d0fcae3e41212a8ad500c92ea2c396126d063c05528910bbb21cce2d473dbfe561d7763d2def11e52c6e522f44223b7
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
group :test do
|
4
|
+
gem 'json', '>= 1.8.1', :platforms => [:jruby, :ruby_18, :ruby_19]
|
5
|
+
gem 'mime-types', '~> 1.25', :platforms => [:jruby, :ruby_18]
|
6
|
+
gem 'rack-test'
|
7
|
+
end
|
8
|
+
|
9
|
+
# Specify your gem's dependencies in rack-jive-signed_request.gemspec
|
10
|
+
gemspec
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/rack-micro_service-signed_request.svg)](http://badge.fury.io/rb/rack-micro_service-signed_request)
|
2
|
+
[![Build Status](https://travis-ci.org/butchmarshall/rack-micro_service-signed_request.svg?branch=master)](https://travis-ci.org/butchmarshall/rack-micro_service-signed_request)
|
3
|
+
|
4
|
+
# MicroService Signed Request Middleware
|
5
|
+
|
6
|
+
`Rack::MicroService::SignedRequest` provides support for handling `MicroService` signed requests in Rack compatible applications.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'rack-micro_service-signed_request', :require => 'rack-micro_service-signed_request'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install rack-micro_service-signed_request
|
23
|
+
|
24
|
+
# Configuration
|
25
|
+
|
26
|
+
## Rack
|
27
|
+
|
28
|
+
In the `config.ru`
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
use Rack::MicroService::SignedRequest
|
32
|
+
# Your app might support multiple MicroService instances
|
33
|
+
# This block allows you to determine what secret to use based on the Authorization header
|
34
|
+
secret do |auth_header_params|
|
35
|
+
"this_should_be_the_app_secret_for_authentication_header_params"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
## Rails
|
41
|
+
|
42
|
+
In `config/application.rb`
|
43
|
+
```ruby
|
44
|
+
module ExampleApp
|
45
|
+
class Application < Rails::Application
|
46
|
+
config.middleware.use "Rack::MicroService::SignedRequest" do
|
47
|
+
# Your app might support multiple MicroService instances
|
48
|
+
# This block allows you to determine what secret to use based on the Authorization header
|
49
|
+
secret do |auth_header_params|
|
50
|
+
"this_should_be_the_app_secret_for_authentication_header_params"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
# Usage
|
58
|
+
|
59
|
+
`request.env['micro_service.user_id']` will be populated with the authenticated users MicroService ID
|
60
|
+
|
61
|
+
`request.env['micro_service.email']` will be populated with the authenticated users MicroService Email
|
62
|
+
|
63
|
+
`request.env['micro_service.tenant_id']` will be populated with add-ons tenant_id
|
64
|
+
|
65
|
+
`request.env['micro_service.client_id']` will be populated with add-ons client_id
|
66
|
+
|
67
|
+
`request.env['micro_service.errors.signed_request']` will be populated if there was an error authenticating the signed request
|
68
|
+
|
69
|
+
## Development
|
70
|
+
|
71
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
72
|
+
|
73
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
74
|
+
|
75
|
+
## Contributing
|
76
|
+
|
77
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rack-micro_service-signed_request.
|
78
|
+
|
79
|
+
|
80
|
+
## License
|
81
|
+
|
82
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
83
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rack/micro_service/signed_request"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require "rack"
|
2
|
+
require "rack/request"
|
3
|
+
require "rack/micro_service/signed_request/version"
|
4
|
+
|
5
|
+
require "micro_service/signed_request/utils"
|
6
|
+
|
7
|
+
module Rack
|
8
|
+
module MicroService
|
9
|
+
class SignedRequest
|
10
|
+
def initialize(app, opts={}, &block)
|
11
|
+
@app = app
|
12
|
+
|
13
|
+
if block_given?
|
14
|
+
if block.arity == 1
|
15
|
+
block.call(self)
|
16
|
+
else
|
17
|
+
instance_eval(&block)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def call(env)
|
23
|
+
request = Request.new(env)
|
24
|
+
|
25
|
+
# Prefix to look for in Authorization header
|
26
|
+
header_prefix = (!@prefix.nil?) ? @prefix.call() : "MicroService"
|
27
|
+
|
28
|
+
# Only bother authenticating if the request is identifying itself as signed
|
29
|
+
if env["HTTP_X_SHINDIG_AUTHTYPE"] === "signed" || env["HTTP_AUTHORIZATION"].to_s.match(/^#{header_prefix}/)
|
30
|
+
auth_header_params = ::CGI.parse env["HTTP_AUTHORIZATION"].gsub(/^#{header_prefix}\s/,'')
|
31
|
+
|
32
|
+
begin
|
33
|
+
secret = @secret.call(auth_header_params)
|
34
|
+
if ::MicroService::SignedRequest::Utils.validate(env["HTTP_AUTHORIZATION"], secret, header_prefix)
|
35
|
+
env["micro_service.client_id"] = auth_header_params["client_id"].first
|
36
|
+
else
|
37
|
+
env["micro_service.errors.signed_request"] = "AUTHENTICATION_ERROR"
|
38
|
+
end
|
39
|
+
rescue ArgumentError => $e
|
40
|
+
env["micro_service.errors.signed_request"] = $e.message
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
@app.call(env)
|
45
|
+
end
|
46
|
+
|
47
|
+
def secret(&block)
|
48
|
+
@secret = block
|
49
|
+
end
|
50
|
+
|
51
|
+
def prefix(&block)
|
52
|
+
@prefix = block
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class Request < ::Rack::Request
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rack/micro_service/signed_request/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rack-micro_service-signed_request"
|
8
|
+
spec.version = Rack::MicroService::SignedRequest::VERSION
|
9
|
+
spec.authors = ["Butch Marshall"]
|
10
|
+
spec.email = ["butch.a.marshall@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Rack middleware for MicroService signed requests.}
|
13
|
+
spec.description = %q{Authenticates signed server requests from a MicroService and resolves the MicroService.}
|
14
|
+
spec.homepage = "https://github.com/butchmarshall/rack-micro_service-signed_request"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "micro_service-signed_request-utils"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
|
28
|
+
spec.add_runtime_dependency "rack", ">= 1.1"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-micro_service-signed_request
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Butch Marshall
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: micro_service-signed_request-utils
|
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: rack
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.1'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.1'
|
83
|
+
description: Authenticates signed server requests from a MicroService and resolves
|
84
|
+
the MicroService.
|
85
|
+
email:
|
86
|
+
- butch.a.marshall@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- lib/rack/micro_service/signed_request.rb
|
100
|
+
- lib/rack/micro_service/signed_request/version.rb
|
101
|
+
- rack-micro_service-signed_request.gemspec
|
102
|
+
homepage: https://github.com/butchmarshall/rack-micro_service-signed_request
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.4.6
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Rack middleware for MicroService signed requests.
|
126
|
+
test_files: []
|