faraday-digestauth 0.0.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +24 -0
- data/README.md +6 -0
- data/Rakefile +6 -0
- data/faraday-digestauth.gemspec +11 -10
- data/lib/faraday/digestauth.rb +10 -91
- data/lib/faraday/digestauth/connection.rb +19 -0
- data/lib/faraday/digestauth/version.rb +1 -1
- data/lib/faraday/request/digestauth.rb +79 -0
- data/spec/faraday-digestauth_spec.rb +13 -0
- data/spec/spec_helper.rb +10 -0
- metadata +53 -29
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: 5e80cb294f034a9b9e14cb46d063ba8b1e9d466e
|
4
|
+
data.tar.gz: e622418ada1c6d1858d8d26263d35396a803efed
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a057d93c5969e4f9b29af8084712c2c5e2c6c83ec5eddc589ff14318ca890b6d40467c0ba3185a9ec98bd2e71ebc8b856c8b7c247da027c05b317765cddcb475
|
7
|
+
data.tar.gz: 225060eae656de664177c984f392240f0fcdfc369583c24907ad925c33e0b1bebd2d4f2e0d27399e5d5b13f881484f146c13dac2c068cc902d5ce36150b622f5
|
data/.travis.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
language: ruby
|
2
|
+
env:
|
3
|
+
global:
|
4
|
+
- "JRUBY_OPTS=-Xcext.enabled=true"
|
5
|
+
rvm:
|
6
|
+
- 2.1.0
|
7
|
+
- 2.0.0
|
8
|
+
- 1.9.3
|
9
|
+
- 1.9.2
|
10
|
+
- 1.8.7
|
11
|
+
- jruby-18mode
|
12
|
+
- jruby-19mode
|
13
|
+
- rbx
|
14
|
+
- ruby-head
|
15
|
+
- jruby-head
|
16
|
+
- ree
|
17
|
+
matrix:
|
18
|
+
allow_failures:
|
19
|
+
- rvm: 1.8.7
|
20
|
+
- rvm: ree
|
21
|
+
- rvm: jruby-18mode
|
22
|
+
- rvm: jruby-19mode
|
23
|
+
- rvm: jruby-head
|
24
|
+
fast_finish: true
|
data/README.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Faraday::DigestAuth
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/faraday-digestauth.png)](http://badge.fury.io/rb/faraday-digestauth)
|
4
|
+
[![Dependency Status](https://gemnasium.com/bhaberer/faraday-digestauth.png)](https://gemnasium.com/bhaberer/faraday-digestauth)
|
5
|
+
[![Build Status](https://travis-ci.org/bhaberer/faraday-digestauth.png?branch=master)](https://travis-ci.org/bhaberer/faraday-digestauth)
|
6
|
+
[![Coverage Status](https://coveralls.io/repos/bhaberer/faraday-digestauth/badge.png?branch=master)](https://coveralls.io/r/bhaberer/faraday-digestauth?branch=m aster)
|
7
|
+
[![Code Climate](https://codeclimate.com/github/bhaberer/faraday-digestauth.png)](https://codeclimate.com/github/bhaberer/faraday-digestauth)
|
8
|
+
|
3
9
|
This gem started as a direct copy of a gist belonging to @kapkaev
|
4
10
|
|
5
11
|
It is located at https://gist.github.com/kapkaev/5088751
|
data/Rakefile
CHANGED
data/faraday-digestauth.gemspec
CHANGED
@@ -4,23 +4,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'faraday/digestauth/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'faraday-digestauth'
|
8
8
|
spec.version = Faraday::DigestAuth::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Brian Haberer', 'Ildar Kapkaev']
|
10
|
+
spec.email = ['bhaberer@gmail.com', 'kirs.box@gmail.com']
|
11
11
|
spec.description = %q{Faraday extension to enable digest auth}
|
12
12
|
spec.summary = %q{Digest Auth for Faraday}
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
13
|
+
spec.homepage = 'https://github.com/bhaberer/faraday-digestauth'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
20
|
-
|
21
|
-
spec.add_dependency 'faraday'
|
22
|
-
spec.add_dependency 'net-http-digest_auth'
|
19
|
+
spec.require_paths = ['lib']
|
23
20
|
|
21
|
+
spec.add_dependency 'faraday', '~> 0.7'
|
22
|
+
spec.add_dependency 'net-http-digest_auth', '~> 1.4'
|
24
23
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
25
|
-
spec.add_development_dependency 'rake'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3'
|
26
|
+
spec.add_development_dependency 'coveralls', '~> 0.1'
|
26
27
|
end
|
data/lib/faraday/digestauth.rb
CHANGED
@@ -1,96 +1,15 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
+
require 'net/http/digest_auth'
|
2
3
|
require 'faraday'
|
3
4
|
require 'faraday/digestauth/version'
|
4
|
-
require '
|
5
|
-
|
6
|
-
module Faraday
|
7
|
-
# Public: A Faraday middleware to use digest authentication. Since order of
|
8
|
-
# middlewares do care, it should be the first one of the Request middlewares
|
9
|
-
# in order to work properly (due to how digest authentication works).
|
10
|
-
#
|
11
|
-
# If some requests using the connection don't need to use digest auth you
|
12
|
-
# don't have to worry, the middleware will do nothing.
|
13
|
-
#
|
14
|
-
# It uses Net::HTTP::DigestAuth to generate the authorization header but it
|
15
|
-
# should work with any adapter.
|
16
|
-
#
|
17
|
-
# Examples:
|
18
|
-
#
|
19
|
-
# connection = Faraday.new(...) do |connection|
|
20
|
-
# connection.request :digest, USER, PASSWORD
|
21
|
-
# end
|
22
|
-
#
|
23
|
-
# # You can also use it later with a connection:
|
24
|
-
# connection.digest_auth('USER', 'PASSWORD')
|
25
|
-
#
|
26
|
-
class Request::DigestAuth < Faraday::Middleware
|
27
|
-
# Public: Initializes a DigestAuth.
|
28
|
-
#
|
29
|
-
# app - The Faraday app.
|
30
|
-
# user - A String with the user to authentication the connection.
|
31
|
-
# password - A String with the password to authentication the connection.
|
32
|
-
def initialize(app, user, password)
|
33
|
-
super(app)
|
34
|
-
@user, @password = user, password
|
35
|
-
end
|
36
|
-
|
37
|
-
# Public: Sends a first request with an empty body to get the
|
38
|
-
# authentication headers and then send the same request with the body and
|
39
|
-
# authorization header.
|
40
|
-
#
|
41
|
-
# env - A Hash with the request environment.
|
42
|
-
#
|
43
|
-
# Returns a Faraday::Response.
|
44
|
-
def call(env)
|
45
|
-
response = handshake(env)
|
46
|
-
return response unless response.status == 401
|
47
|
-
|
48
|
-
env[:request_headers]['Authorization'] = header(response)
|
49
|
-
@app.call(env)
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
# Internal: Sends the the request with an empry body.
|
55
|
-
#
|
56
|
-
# env - A Hash with the request environment.
|
57
|
-
#
|
58
|
-
# Returns a Faraday::Response.
|
59
|
-
def handshake(env)
|
60
|
-
env_without_body = env.dup
|
61
|
-
env_without_body.delete(:body)
|
62
|
-
@app.call(env_without_body)
|
63
|
-
end
|
64
|
-
|
65
|
-
# Internal: Builds the authorization header with the authentication data.
|
66
|
-
#
|
67
|
-
# response - A Faraday::Response with the authenticate headers.
|
68
|
-
#
|
69
|
-
# Returns a String with the DigestAuth header.
|
70
|
-
def header(response)
|
71
|
-
uri = response.env[:url]
|
72
|
-
uri.user = @user
|
73
|
-
uri.password = @password
|
74
|
-
|
75
|
-
realm = response.headers['www-authenticate']
|
76
|
-
method = response.env[:method].to_s.upcase
|
77
|
-
|
78
|
-
Net::HTTP::DigestAuth.new.auth_header(uri, realm, method)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
class Connection
|
83
|
-
# Public: Adds the digest auth middleware at the top and sets the user and
|
84
|
-
# password.
|
85
|
-
#
|
86
|
-
# user - A String with the user.
|
87
|
-
# password - A String with the password.
|
88
|
-
#
|
89
|
-
def digest_auth(user, password)
|
90
|
-
self.builder.insert(0, Faraday::Request::DigestAuth, user, password)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
5
|
+
require 'faraday/digestauth/connection'
|
6
|
+
require 'faraday/request/digestauth'
|
94
7
|
|
95
8
|
# Register the middleware as a Request middleware with the name :digest
|
96
|
-
Faraday.register_middleware
|
9
|
+
if Faraday.respond_to?(:register_middleware) # Faraday 0.8
|
10
|
+
Faraday.register_middleware :request, :digest => Faraday::Request::DigestAuth
|
11
|
+
elsif Faraday::Request.respond_to?(:register_middleware) # Faraday 0.9
|
12
|
+
Faraday::Request.register_middleware :digest => Faraday::Request::DigestAuth
|
13
|
+
elsif Faraday::Request.respond_to?(:register_lookup_modules) # Faraday 0.7
|
14
|
+
Faraday::Request.register_lookup_modules :digest => :DigestAuth
|
15
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module Faraday
|
3
|
+
module DigestAuth
|
4
|
+
# Connection methods
|
5
|
+
module Connection
|
6
|
+
# Public: Adds the digest auth middleware at the top and sets the user and
|
7
|
+
# password.
|
8
|
+
#
|
9
|
+
# user - A String with the user.
|
10
|
+
# password - A String with the password.
|
11
|
+
#
|
12
|
+
def digest_auth(user, password)
|
13
|
+
builder.insert(0, Faraday::Request::DigestAuth, user, password)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
Faraday::Connection.send :include, Faraday::DigestAuth::Connection
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module Faraday
|
3
|
+
class Request
|
4
|
+
# Public: A Faraday middleware to use digest authentication. Since order of
|
5
|
+
# middlewares do care, it should be the first one of the Request middlewares
|
6
|
+
# in order to work properly (due to how digest authentication works).
|
7
|
+
#
|
8
|
+
# If some requests using the connection don't need to use digest auth you
|
9
|
+
# don't have to worry, the middleware will do nothing.
|
10
|
+
#
|
11
|
+
# It uses Net::HTTP::DigestAuth to generate the authorization header but it
|
12
|
+
# should work with any adapter.
|
13
|
+
#
|
14
|
+
# Examples:
|
15
|
+
#
|
16
|
+
# connection = Faraday.new(...) do |connection|
|
17
|
+
# connection.request :digest, USER, PASSWORD
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# # You can also use it later with a connection:
|
21
|
+
# connection.digest_auth('USER', 'PASSWORD')
|
22
|
+
#
|
23
|
+
class DigestAuth < Faraday::Middleware
|
24
|
+
# Public: Initializes a DigestAuth.
|
25
|
+
#
|
26
|
+
# app - The Faraday app.
|
27
|
+
# user - A String with the user to authentication the connection.
|
28
|
+
# password - A String with the password to authentication the connection.
|
29
|
+
def initialize(app, user, password)
|
30
|
+
super(app)
|
31
|
+
@user, @password = user, password
|
32
|
+
end
|
33
|
+
|
34
|
+
# Public: Sends a first request with an empty body to get the
|
35
|
+
# authentication headers and then send the same request with the body and
|
36
|
+
# authorization header.
|
37
|
+
#
|
38
|
+
# env - A Hash with the request environment.
|
39
|
+
#
|
40
|
+
# Returns a Faraday::Response.
|
41
|
+
def call(env)
|
42
|
+
response = handshake(env)
|
43
|
+
return response unless response.status == 401
|
44
|
+
|
45
|
+
env[:request_headers]['Authorization'] = header(response)
|
46
|
+
@app.call(env)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
# Internal: Sends the the request with an empry body.
|
52
|
+
#
|
53
|
+
# env - A Hash with the request environment.
|
54
|
+
#
|
55
|
+
# Returns a Faraday::Response.
|
56
|
+
def handshake(env)
|
57
|
+
env_without_body = env.dup
|
58
|
+
env_without_body.delete(:body)
|
59
|
+
@app.call(env_without_body)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Internal: Builds the authorization header with the authentication data.
|
63
|
+
#
|
64
|
+
# response - A Faraday::Response with the authenticate headers.
|
65
|
+
#
|
66
|
+
# Returns a String with the DigestAuth header.
|
67
|
+
def header(response)
|
68
|
+
uri = response.env[:url]
|
69
|
+
uri.user = @user
|
70
|
+
uri.password = @password
|
71
|
+
|
72
|
+
realm = response.headers['www-authenticate']
|
73
|
+
method = response.env[:method].to_s.upcase
|
74
|
+
|
75
|
+
Net::HTTP::DigestAuth.new.auth_header(uri, realm, method)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Faraday::Request::DigestAuth do
|
4
|
+
|
5
|
+
# This doesn't do anything yet.
|
6
|
+
it 'should allow users to build faraday objects with digest creds' do
|
7
|
+
@conn = Faraday.new(:url => 'http://localhost/') do |f|
|
8
|
+
f.request(:digest, :username, :password)
|
9
|
+
f.adapter Faraday.default_adapter
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday-digestauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Brian Haberer
|
@@ -10,44 +9,39 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date: 2014-
|
12
|
+
date: 2014-08-04 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: faraday
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
17
|
requirements:
|
20
|
-
- -
|
18
|
+
- - ~>
|
21
19
|
- !ruby/object:Gem::Version
|
22
|
-
version: '0'
|
20
|
+
version: '0.7'
|
23
21
|
type: :runtime
|
24
22
|
prerelease: false
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
24
|
requirements:
|
28
|
-
- -
|
25
|
+
- - ~>
|
29
26
|
- !ruby/object:Gem::Version
|
30
|
-
version: '0'
|
27
|
+
version: '0.7'
|
31
28
|
- !ruby/object:Gem::Dependency
|
32
29
|
name: net-http-digest_auth
|
33
30
|
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
31
|
requirements:
|
36
|
-
- -
|
32
|
+
- - ~>
|
37
33
|
- !ruby/object:Gem::Version
|
38
|
-
version: '
|
34
|
+
version: '1.4'
|
39
35
|
type: :runtime
|
40
36
|
prerelease: false
|
41
37
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
38
|
requirements:
|
44
|
-
- -
|
39
|
+
- - ~>
|
45
40
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
41
|
+
version: '1.4'
|
47
42
|
- !ruby/object:Gem::Dependency
|
48
43
|
name: bundler
|
49
44
|
requirement: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
45
|
requirements:
|
52
46
|
- - ~>
|
53
47
|
- !ruby/object:Gem::Version
|
@@ -55,7 +49,6 @@ dependencies:
|
|
55
49
|
type: :development
|
56
50
|
prerelease: false
|
57
51
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
52
|
requirements:
|
60
53
|
- - ~>
|
61
54
|
- !ruby/object:Gem::Version
|
@@ -63,19 +56,45 @@ dependencies:
|
|
63
56
|
- !ruby/object:Gem::Dependency
|
64
57
|
name: rake
|
65
58
|
requirement: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
59
|
requirements:
|
68
|
-
- -
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '10'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '10'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '3'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ~>
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '3'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: coveralls
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ~>
|
69
89
|
- !ruby/object:Gem::Version
|
70
|
-
version: '0'
|
90
|
+
version: '0.1'
|
71
91
|
type: :development
|
72
92
|
prerelease: false
|
73
93
|
version_requirements: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
94
|
requirements:
|
76
|
-
- -
|
95
|
+
- - ~>
|
77
96
|
- !ruby/object:Gem::Version
|
78
|
-
version: '0'
|
97
|
+
version: '0.1'
|
79
98
|
description: Faraday extension to enable digest auth
|
80
99
|
email:
|
81
100
|
- bhaberer@gmail.com
|
@@ -85,37 +104,42 @@ extensions: []
|
|
85
104
|
extra_rdoc_files: []
|
86
105
|
files:
|
87
106
|
- .gitignore
|
107
|
+
- .travis.yml
|
88
108
|
- Gemfile
|
89
109
|
- LICENSE.txt
|
90
110
|
- README.md
|
91
111
|
- Rakefile
|
92
112
|
- faraday-digestauth.gemspec
|
93
113
|
- lib/faraday/digestauth.rb
|
114
|
+
- lib/faraday/digestauth/connection.rb
|
94
115
|
- lib/faraday/digestauth/version.rb
|
116
|
+
- lib/faraday/request/digestauth.rb
|
117
|
+
- spec/faraday-digestauth_spec.rb
|
118
|
+
- spec/spec_helper.rb
|
95
119
|
homepage: https://github.com/bhaberer/faraday-digestauth
|
96
120
|
licenses:
|
97
121
|
- MIT
|
122
|
+
metadata: {}
|
98
123
|
post_install_message:
|
99
124
|
rdoc_options: []
|
100
125
|
require_paths:
|
101
126
|
- lib
|
102
127
|
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
-
none: false
|
104
128
|
requirements:
|
105
129
|
- - ! '>='
|
106
130
|
- !ruby/object:Gem::Version
|
107
131
|
version: '0'
|
108
132
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
-
none: false
|
110
133
|
requirements:
|
111
134
|
- - ! '>='
|
112
135
|
- !ruby/object:Gem::Version
|
113
136
|
version: '0'
|
114
137
|
requirements: []
|
115
138
|
rubyforge_project:
|
116
|
-
rubygems_version:
|
139
|
+
rubygems_version: 2.2.2
|
117
140
|
signing_key:
|
118
|
-
specification_version:
|
141
|
+
specification_version: 4
|
119
142
|
summary: Digest Auth for Faraday
|
120
|
-
test_files:
|
121
|
-
|
143
|
+
test_files:
|
144
|
+
- spec/faraday-digestauth_spec.rb
|
145
|
+
- spec/spec_helper.rb
|