activeresource_bearer_authentication 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/Guardfile +24 -0
- data/LICENSE +22 -0
- data/README.md +52 -0
- data/Rakefile +7 -0
- data/activeresource_bearer_authentication.gemspec +25 -0
- data/lib/active_resource/bearer_authentication/base.rb +24 -0
- data/lib/active_resource/bearer_authentication/connection.rb +26 -0
- data/lib/active_resource/bearer_authentication/version.rb +5 -0
- data/lib/active_resource/bearer_authentication.rb +13 -0
- data/lib/activeresource_bearer_authentication.rb +1 -0
- data/spec/bearer_authentication_spec.rb +46 -0
- data/spec/spec_helper.rb +19 -0
- metadata +159 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec', :version => 2 do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
|
9
|
+
# Rails example
|
10
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
11
|
+
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
12
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
13
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
14
|
+
watch('config/routes.rb') { "spec/routing" }
|
15
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
16
|
+
|
17
|
+
# Capybara request specs
|
18
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
|
19
|
+
|
20
|
+
# Turnip features and steps
|
21
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
22
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
23
|
+
end
|
24
|
+
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Thomas Hollstegge
|
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,52 @@
|
|
1
|
+
# ActiveResource::BearerAuthentication
|
2
|
+
|
3
|
+
Bearer authentication support for [ActiveResource](https://github.com/rails/activeresource).
|
4
|
+
|
5
|
+
[![Build Status](https://secure.travis-ci.org/Tho85/activeresource_bearer_authentication.png)](http://travis-ci.org/Tho85/activeresource_bearer_authentication) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/Tho85/activeresource_bearer_authentication)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'activeresource_bearer_authentication'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install activeresource_bearer_authentication
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Set authentication type and token directly:
|
24
|
+
```ruby
|
25
|
+
class MyResource < ActiveResource::Base
|
26
|
+
self.auth_type = :bearer
|
27
|
+
self.token = 'my_token'
|
28
|
+
|
29
|
+
# ...
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
Alternative: Set token in a block
|
34
|
+
```ruby
|
35
|
+
class MyResource < ActiveResource::Base
|
36
|
+
self.auth_type = :bearer
|
37
|
+
self.token do
|
38
|
+
# Magic happens...
|
39
|
+
SomeTokenGenerator.get_fresh_token
|
40
|
+
end
|
41
|
+
|
42
|
+
# ...
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
1. Fork it
|
49
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
51
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
52
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/active_resource/bearer_authentication/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Thomas Hollstegge"]
|
6
|
+
gem.email = ["thomas.hollstegge@zweitag.de"]
|
7
|
+
gem.description = %q{Bearer authentication support for ActiveResource}
|
8
|
+
gem.summary = %q{Adds bearer authentication to ActiveResource}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "activeresource_bearer_authentication"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = ActiveResource::BearerAuthentication::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'activesupport', '~> 3.2.8'
|
19
|
+
gem.add_dependency 'activeresource', '~> 3.2.8'
|
20
|
+
|
21
|
+
gem.add_development_dependency 'rake'
|
22
|
+
gem.add_development_dependency 'rspec', '~> 2.11.0'
|
23
|
+
gem.add_development_dependency 'guard-rspec'
|
24
|
+
gem.add_development_dependency 'pry'
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module ActiveResource
|
4
|
+
module BearerAuthentication
|
5
|
+
module Base
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def token=(value)
|
10
|
+
self.password = value
|
11
|
+
end
|
12
|
+
|
13
|
+
def token(&block)
|
14
|
+
if block_given?
|
15
|
+
self.password = block
|
16
|
+
else
|
17
|
+
@password.is_a?(Proc) ? @password.call : @password
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module ActiveResource
|
4
|
+
module BearerAuthentication
|
5
|
+
module Connection
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
alias authorization_header_without_bearer authorization_header
|
10
|
+
|
11
|
+
def authorization_header(http_method, uri)
|
12
|
+
if @password && auth_type == :bearer
|
13
|
+
token = @password.is_a?(Proc) ? @password.call : @password
|
14
|
+
{ 'Authorization' => "Bearer #{token}" }
|
15
|
+
else
|
16
|
+
authorization_header_without_bearer(http_method, uri)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def legitimize_auth_type(auth_type)
|
21
|
+
[:basic, :digest, :bearer].include?(auth_type) ? auth_type : :basic
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'active_resource'
|
2
|
+
|
3
|
+
module ActiveResource
|
4
|
+
module BearerAuthentication
|
5
|
+
autoload :Base, 'active_resource/bearer_authentication/base'
|
6
|
+
autoload :Connection, 'active_resource/bearer_authentication/connection'
|
7
|
+
|
8
|
+
autoload :Version, 'active_resource/bearer_authentication/version'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
ActiveResource::Base.send :include, ActiveResource::BearerAuthentication::Base
|
13
|
+
ActiveResource::Connection.send :include, ActiveResource::BearerAuthentication::Connection
|
@@ -0,0 +1 @@
|
|
1
|
+
require "active_resource/bearer_authentication"
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'bearer authentication' do
|
4
|
+
context 'bearer' do
|
5
|
+
before(:each) do
|
6
|
+
class MyResource < ActiveResource::Base
|
7
|
+
self.auth_type = :bearer
|
8
|
+
|
9
|
+
self.site = 'http://spec.invalid/'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'sets bearer token' do
|
14
|
+
MyResource.token = 'spoken'
|
15
|
+
|
16
|
+
MyResource.connection.send(:authorization_header, :get, '/my_uri').should == { 'Authorization' => 'Bearer spoken' }
|
17
|
+
MyResource.token.should == 'spoken'
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'sets bearer token lazily' do
|
21
|
+
MyResource.token do
|
22
|
+
"JRR_Token"
|
23
|
+
end
|
24
|
+
|
25
|
+
MyResource.connection.send(:authorization_header, :get, '/my_uri').should == { 'Authorization' => 'Bearer JRR_Token' }
|
26
|
+
MyResource.token.should == 'JRR_Token'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'passthrough' do
|
31
|
+
before(:each) do
|
32
|
+
class MyPassthroughResource < ActiveResource::Base
|
33
|
+
self.auth_type = :basic
|
34
|
+
|
35
|
+
self.site = 'http://user:pass@spec.invalid'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'still accepts other auths' do
|
40
|
+
MyPassthroughResource.connection.should_receive(:authorization_header_without_bearer).with(:get, '/my_uri')
|
41
|
+
|
42
|
+
MyPassthroughResource.connection.send(:authorization_header, :get, '/my_uri')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
require 'activeresource_bearer_authentication'
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
11
|
+
config.run_all_when_everything_filtered = true
|
12
|
+
config.filter_run :focus
|
13
|
+
|
14
|
+
# Run specs in random order to surface order dependencies. If you find an
|
15
|
+
# order dependency and want to debug it, you can fix the order by providing
|
16
|
+
# the seed, which is printed after each run.
|
17
|
+
# --seed 1234
|
18
|
+
config.order = 'random'
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activeresource_bearer_authentication
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Thomas Hollstegge
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.2.8
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.2.8
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: activeresource
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 3.2.8
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 3.2.8
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.11.0
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 2.11.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: guard-rspec
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: pry
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: Bearer authentication support for ActiveResource
|
111
|
+
email:
|
112
|
+
- thomas.hollstegge@zweitag.de
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- .gitignore
|
118
|
+
- .rspec
|
119
|
+
- .travis.yml
|
120
|
+
- Gemfile
|
121
|
+
- Guardfile
|
122
|
+
- LICENSE
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- activeresource_bearer_authentication.gemspec
|
126
|
+
- lib/active_resource/bearer_authentication.rb
|
127
|
+
- lib/active_resource/bearer_authentication/base.rb
|
128
|
+
- lib/active_resource/bearer_authentication/connection.rb
|
129
|
+
- lib/active_resource/bearer_authentication/version.rb
|
130
|
+
- lib/activeresource_bearer_authentication.rb
|
131
|
+
- spec/bearer_authentication_spec.rb
|
132
|
+
- spec/spec_helper.rb
|
133
|
+
homepage: ''
|
134
|
+
licenses: []
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
none: false
|
141
|
+
requirements:
|
142
|
+
- - ! '>='
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
none: false
|
147
|
+
requirements:
|
148
|
+
- - ! '>='
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 1.8.21
|
154
|
+
signing_key:
|
155
|
+
specification_version: 3
|
156
|
+
summary: Adds bearer authentication to ActiveResource
|
157
|
+
test_files:
|
158
|
+
- spec/bearer_authentication_spec.rb
|
159
|
+
- spec/spec_helper.rb
|