# \[IGN-4258\]Digest auth with httpClient

**URL:** <https://forum.inductiveautomation.com/t/ign-4258-digest-auth-with-httpclient/66137>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [November 4, 2022, 4:08pm UTC](https://forum.inductiveautomation.com/t/ign-4258-digest-auth-with-httpclient/66137 "2022-11-04T16:08:48Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [October 8, 2024, 8:48pm UTC](https://forum.inductiveautomation.com/t/ign-4258-digest-auth-with-httpclient/66137/10 "2024-10-08T20:48:09Z")

</div>

Here is an example function:

```python
def getData(client, uri, url, username, password):
		import hashlib
		import random
		
		res = client.get(url)
		if res.statusCode == 401:
			headers = res.headers
			digestParts = headers["www-authenticate"][0].replace("Digest ", "").split(",")
			digestData = {}
			for part in digestParts:		
				partParts = part.strip().split("=")
				digestData[partParts[0]] = partParts[1].replace("\"", "")
			
			realm = digestData["realm"]
			charset = digestData["charset"]
			algorithm = digestData["algorithm"]
			nonce = digestData["nonce"]
			cnonce = "".join(random.choice("0123456789abcdef") for i in range(8))
			qop = digestData["qop"]
			nc = "00000001"
			
			ha1 = hashlib.md5("%s:%s:%s" % (username, realm, password)).hexdigest()
			ha2 = hashlib.md5("GET:%s" % (uri)).hexdigest()
			response = hashlib.md5("%s:%s:%s:%s:%s:%s" % (ha1, nonce, nc, cnonce, qop, ha2)).hexdigest()
			
			authorization = "Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", qop=%s, nc=%s, cnonce=\"%s\", response=\"%s\"" % (username, realm, nonce, uri, qop, nc, cnonce, response)
			res = client.get(url, headers={"Authorization":authorization})
		
		return res

```

You can call it like so:

```python
ipAddress = "192.168.10.10"
uri = "/path/to/call"
url = "https://%s%s" % (ipAddress, uri)
username = "admin"
password = "password"
client = system.net.httpClient(bypassCertValidation=True)
(authorization, res) = getData(client, uri, url, username, password)

```

---

_[View the full topic](https://forum.inductiveautomation.com/t/ign-4258-digest-auth-with-httpclient/66137)._
