Page 1 of 1
Authentication Examples?
Posted: Wed Feb 21, 2018 8:53 pm
by oppyoppy
Hello All,
First time poster here.
I've been reading the CGI SDK API and am confused as to why there are no examples for the authentication topic. I'm a CGI noob, but IMHO the documentation shown below is not at all clear. What should be done to login to the camera via CGI? There are examples of all other functionality, but this topic got neglected.
Thanks in advance,
Oppy
The Amcrest video product supplies two authentication ways: basic authentication and digest authentication. If the http request does not have “Authorization”, the Amcrest video product returns a 401, until the http request has a legal authentication.
For example:
1. When basic authentication, the Amcrest video product response: 401 Unauthorized
WWW-Authenticate: Basic realm=”XXXXXX”
Then the client encode the username and password with base64, send the following request:
Authorization: Basic VXZVXZ.
2. When digest authentication, the Amcrest video product response:
WWW-Authenticate: Digest realm="DH_00408CA5EA04", nonce="000562fdY631973ef04f77a3ede7c1832ff48720ef95ad", stale=FALSE, qop="auth";
The client calculates the digest using username, password, nonce, realm and URI with MD5, then send the following request:
Authorization: Digest username="admin", realm="DH_00408CA5EA04", nc=00000001,cnonce="0a4f113b",qop="auth" nonce="000562fdY631973ef04f77a3ede7c1832ff48720ef95ad",uri="cgi-bin/global.login?userName=admin", response="65002de02df697e946b750590b44f8bf"
Re: Authentication Examples?
Posted: Thu May 03, 2018 1:25 pm
by jantman
What more examples are you looking for than the quote above?
With the asterisk that Basic is apparently no longer supported on newer firmware versions, only digest.
Re: Authentication Examples?
Posted: Thu Nov 29, 2018 3:30 pm
by jamestx10
I am currently using
Code: Select all
<img src=http://USER:PW@CAMIP/cgi-bin/snapshot.cgi/ width= '1280'>
to pull an image. How do I make that same request using digest auth? Right now that code works every other time.
Re: Authentication Examples?
Posted: Fri Jan 25, 2019 2:07 pm
by tholius
I have a similar question, because the http construct of user:pass@website is deprecated.
Re: Authentication Examples?
Posted: Tue Dec 07, 2021 9:42 am
by BlueSkyTrawler
So here is what I used to get Digest Authentication Working in Python.
import requests
from requests.auth import HTTPDigestAuth
auth = HTTPDigestAuth ([username],[password])
#Move Right Command, note the auth added to the end.
r=requests.get('http://[cam ip]/cgi-bin/ptz.cgi?action=start&channel=0&code=Right&arg1=0&arg2=1&arg3=0',auth=auth)
After about a half second the camera will start panning to the right. To stop it you have to send another command with the action set to "stop".
later,
Bill
Re: Authentication Examples?
Posted: Wed Dec 08, 2021 2:15 pm
by jantman
What
@BlueSkyTrawler said looks correct to m
jamestx10 wrote: ↑Thu Nov 29, 2018 3:30 pm
I am currently using
Code: Select all
<img src=http://USER:PW@CAMIP/cgi-bin/snapshot.cgi/ width= '1280'>
to pull an image. How do I make that same request using digest auth? Right now that code works every other time.
@jamestx10 and
@tholius, unfortunately that's not possible. Using
format in URLs, either in a browser address bar or in URLs inside a HTML page, only works for Basic authentication; it's not possible to use Digest credentials like this.
Re: Authentication Examples?
Posted: Wed Dec 08, 2021 3:52 pm
by Revo2Maxx
@jantman It all depends on the camera. I have a Old FW camera that it will work on so it really is FW related to what can and can't work. Maybe they are working in a older FW camera I just used it on my 751 over Wifi and it returned a picture

- Screenshot (1604).png (1.62 MiB) Viewed 7872 times
Re: Authentication Examples?
Posted: Thu Dec 09, 2021 6:31 am
by jantman
@Revo2Maxx Oooohhh, you're right, sorry, I forgot that this wasn't mentioned explicitly in the thread:
HTTP Basic authentication (which works using the
format in URLs, and is generally much simpler to work with) is considered insecure. A few years ago Amcrest updated the firmware to use Digest authentication instead, and thereby solve a security risk. Unfortunately, Digest authentication is much more difficult to work with... you can't just throw a username/password in a URL and have it work, and you can't just easily proxy or re-broadcast a stream.
If you have an older camera, or a camera still on the older firmware, you can just use Basic and have none of these issues.
I can't find the exact date/firmware version where the change was made, and it looks like the firmware download site no longer has a change log for... anything...
Re: Authentication Examples?
Posted: Thu Dec 09, 2021 7:45 am
by Revo2Maxx
Yes funny thing is I have some other older cameras that it won't work on as well. Like my 850EB's and my 956EB, 846EB. While they do have older FW I am going to guess it was released after the issues and got the updated info that was needed to plug the hole. I know my 721ES, and my 751 both will work with the command. The 721ES I had to put on my normal network to test the command seeing it is normally behind my NVR on POE port. Now just gives me a reason to change out my 751. Don't really look at the feed much anyway just one of 4 cameras on my Driveway. The 721 is on its post because it has a Mic and have enough 841's and others that I could change it out but only on my Stairs so don't really matter much if it has higher then 720p output. Not broke don't fix it.. or in this case don't change it..
Re: Authentication Examples?
Posted: Thu Aug 29, 2024 3:35 pm
by zistrosk
Strangely, mine was still getting 401 with this code from BlueSky:
username = 'myusername'
password = 'mypassword'
auth = HTTPDigestAuth ([username],[password])
But then worked with this:
auth = HTTPDigestAuth (username,password)
I just kept randomly trying things and this did the trick.
Hope this helps anyone that hit the same issue I did!