Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/spider-gazelle/ntlm
NTLM authentication for crystal lang
https://github.com/spider-gazelle/ntlm
Last synced: about 1 month ago
JSON representation
NTLM authentication for crystal lang
- Host: GitHub
- URL: https://github.com/spider-gazelle/ntlm
- Owner: spider-gazelle
- License: mit
- Created: 2020-07-15T13:39:32.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-05-25T10:06:40.000Z (over 3 years ago)
- Last Synced: 2024-11-18T22:32:22.754Z (about 2 months ago)
- Language: Crystal
- Size: 24.4 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-crystal - ntlm - NTLM authentication (HTTP)
README
# Crystal Lang NTLM Auth
[![CI](https://github.com/spider-gazelle/ntlm/actions/workflows/ci.yml/badge.svg)](https://github.com/spider-gazelle/ntlm/actions/workflows/ci.yml)
Communicate with servers that implement NTLM auth.
## Installation
1. Add the dependency to your `shard.yml`:
```yaml
dependencies:
ntlm:
github: spider-gazelle/ntlm
```2. Run `shards install`
## Usage
### Authenticate a HTTP request
```crystal
require "http/client"
require "ntlm"route = "/terrible/soap/api"
username = "username"
password = "password"# NOTE:: domain is not always required, this can sometimes be left `nil`
domain = "DOMAIN"client = HTTP::Client.new "corporate.service"
response = client.get routeif response.status_code == 401 && response.headers["WWW-Authenticate"]?
supported = response.headers.get("WWW-Authenticate")
raise "doesn't support NTLM auth: #{supported}" unless supported.includes?("NTLM")# Negotiate NTLM
response = client.get route, HTTP::Headers{"Authorization" => NTLM.negotiate_http(domain)}# Extract the challenge
raise "unexpected response #{response.status_code}" unless response.status_code == 401 && response.headers["WWW-Authenticate"]?
challenge = response.headers["WWW-Authenticate"]# Authenticate the client
response = client.get route, HTTP::Headers{"Authorization" => NTLM.authenticate_http(challenge, username, password)}
endresponse
```