faraday-ntlm_auth 0.1.0

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
+ SHA256:
3
+ metadata.gz: dfabd2fb1466348d115b289a904e4a0fe0bd7c4c2e3c7e628efb08dc8e3d9433
4
+ data.tar.gz: e9e54a8d6688b3c87948c2beefd9757974584a64351ebec6a9ccbb501bfb2a0c
5
+ SHA512:
6
+ metadata.gz: 4f4da888175f41d61c1ae14a3bde743462aca6e70198d6fcef0190551beab34e3a8650296c4b86688c56a99e8288b0af0da70e5858cc61d7fe72a69b5396a8c7
7
+ data.tar.gz: '08999da12bad398336a81fdff421e94a4fe0c00db82da1bc89853ddd6ab0e5e0bd4cc99bab0910859e400f29ff4bb80d825e608706e4edbc12e2adf834178344'
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ * Initial release.
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Lucas Ridge
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,55 @@
1
+ # Faraday NTLM Authentication
2
+
3
+ A simple Faraday middleware for NTLM authentication
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'faraday-ntlm_auth'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```shell
16
+ bundle install
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```shell
22
+ gem install faraday-ntlm_auth
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ require 'faraday/ntlm_auth'
29
+
30
+ conn = Faraday.new(url: 'http://example.com') do |faraday|
31
+ faraday.adapter :net_http_persistent, pool_size: 5, idle_timeout: 5 # Net HTTP persistent adapter is required for NTLM authentication
32
+ faraday.request :ntlm_auth, auth: 'username', 'your_password', 'your_domain'
33
+ end
34
+
35
+ ```
36
+
37
+
38
+ ## Development
39
+
40
+ After checking out the repo, run `bin/setup` to install dependencies.
41
+
42
+ Then, run `bin/test` to run the tests.
43
+
44
+ To install this gem onto your local machine, run `rake build`.
45
+
46
+ To release a new version, make a commit with a message such as "Bumped to 0.0.2" and then run `rake release`.
47
+ See how it works [here](https://bundler.io/guides/creating_gem.html#releasing-the-gem).
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on [GitHub](<%= github_uri %>).
52
+
53
+ ## License
54
+
55
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+ require 'rubyntlm'
3
+ require 'faraday/net_http_persistent'
4
+
5
+ module Faraday
6
+ module NTLMAuth
7
+ # This class provides the main implementation for your middleware.
8
+ # Your middleware can implement any of the following methods:
9
+ # * on_request - called when the request is being prepared
10
+ # * on_complete - called when the response is being processed
11
+ #
12
+ # Optionally, you can also override the following methods from Faraday::Middleware
13
+ # * initialize(app, options = {}) - the initializer method
14
+ # * call(env) - the main middleware invocation method.
15
+ # This already calls on_request and on_complete, so you normally don't need to override it.
16
+ # You may need to in case you need to "wrap" the request or need more control
17
+ # (see "retry" middleware: https://github.com/lostisland/faraday-retry/blob/41b7ea27e30d99ebfed958abfa11d12b01f6b6d1/lib/faraday/retry/middleware.rb#L147).
18
+ # IMPORTANT: Remember to call `@app.call(env)` or `super` to not interrupt the middleware chain!
19
+ class Middleware < Faraday::Middleware
20
+ # This method will be called when the request is being prepared.
21
+ # You can alter it as you like, accessing things like request_body, request_headers, and more.
22
+ # Refer to Faraday::Env for a list of accessible fields:
23
+ # https://github.com/lostisland/faraday/blob/main/lib/faraday/options/env.rb
24
+ #
25
+ # @param env [Faraday::Env] the environment of the request being processed
26
+ def on_request(env)
27
+ ntlm_message = Net::NTLM::Message
28
+ env[:request_headers]['Authorization'] = 'NTLM ' + ntlm_message::Type1.new.encode64
29
+ response = @app.call(env.dup)
30
+ challenge = response.env[:response_headers]['www-authenticate'][/(?:NTLM|Negotiate) (.*)$/, 1]
31
+ message = ntlm_message::Type2.decode64(challenge)
32
+ ntlm_auth = message.response([:user, :password, :domain].zip(@options[:auth]).to_h)
33
+ env[:request_headers]['Authorization'] = "NTLM #{ntlm_auth.encode64}"
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faraday
4
+ module NTLMAuth
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'ntlm_auth/middleware'
4
+ require_relative 'ntlm_auth/version'
5
+
6
+ module Faraday
7
+ # This will be your middleware main module, though the actual middleware implementation will go
8
+ # into <%= middleware_constant %> for the correct namespacing.
9
+ module NTLMAuth
10
+ # Faraday allows you to register your middleware for easier configuration.
11
+ # This step is totally optional, but it basically allows users to use a
12
+ # custom symbol (in this case, `:<%= middleware_name %>`), to use your middleware in their connections.
13
+ # After calling this line, the following are both valid ways to set the middleware in a connection:
14
+ # * conn.use <%= middleware_constant %>
15
+ # * conn.use :<%= middleware_name %>
16
+ # Without this line, only the former method is valid.
17
+ Faraday::Request.register_middleware(ntlm_auth: Faraday::NTLMAuth::Middleware)
18
+
19
+ # Alternatively, you can register your middleware under Faraday::Request or Faraday::Response.
20
+ # This will allow to load your middleware using the `request` or `response` methods respectively.
21
+ #
22
+ # Load middleware with conn.request :<%= middleware_name %>
23
+ # Faraday::Request.register_middleware(<%= middleware_name %>: <%= middleware_constant %>)
24
+ #
25
+ # Load middleware with conn.response :<%= middleware_name %>
26
+ # Faraday::Response.register_middleware(<%= middleware_name %>: <%= middleware_constant %>)
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faraday-ntlm_auth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Luke Ridge
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2025-06-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '2.9'
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '3'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '2.9'
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '3'
32
+ - !ruby/object:Gem::Dependency
33
+ name: rubyntlm
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: faraday-net_http_persistent
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ type: :runtime
54
+ prerelease: false
55
+ version_requirements: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ email:
61
+ - lucas.ridge@igs.com
62
+ executables: []
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - CHANGELOG.md
67
+ - LICENSE.md
68
+ - README.md
69
+ - lib/faraday/ntlm_auth.rb
70
+ - lib/faraday/ntlm_auth/middleware.rb
71
+ - lib/faraday/ntlm_auth/version.rb
72
+ homepage: https://github.com/igs-opensource/faraday-ntlm_auth
73
+ licenses:
74
+ - MIT
75
+ metadata:
76
+ bug_tracker_uri: https://github.com/igs-opensource/faraday-ntlm_auth/issues
77
+ changelog_uri: https://github.com/igs-opensource/faraday-ntlm_auth/blob/v0.1.0/CHANGELOG.md
78
+ documentation_uri: http://www.rubydoc.info/gems/faraday-ntlm_auth/0.1.0
79
+ homepage_uri: https://github.com/igs-opensource/faraday-ntlm_auth
80
+ rubygems_mfa_required: 'true'
81
+ source_code_uri: https://github.com/igs-opensource/faraday-ntlm_auth
82
+ wiki_uri: https://github.com/igs-opensource/faraday-ntlm_auth/wiki
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '3.0'
91
+ - - "<"
92
+ - !ruby/object:Gem::Version
93
+ version: '4'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubygems_version: 3.6.2
101
+ specification_version: 4
102
+ summary: A Faraday middleware for NTLM authentication
103
+ test_files: []