auth = HTTPBasicAuth ( username, password )) > resp. > import requests > headers = > username = 'devnetuser' > password = 'Cisco123!' > AUTH_URL = '' > resp = requests. To authenticate with the DNA Center REST API we need to send a POST request to /dna/system/api/v1/auth/token with an Authorization and Content-Type HTTP header, and if we successfully authenticate we will be returned an API token which we can use in subsequent API requests. The rest of this article focuses on using it with Pythons Request module. If you are using another tool like cURL or Postman to test REST API’s, you can take this string and set it in your HTTP headers. We then create an auth_b64 byte string which is now our username and password encoded the way the REST API will require it. We need to do this because the base64.b64encode() function requires a bytes-like object. encode('ascii') function on our auth_str object. You can see above that we can create a byte string using the. b64encode ( byte_str ) > auth_b64 b 'ZGV2bmV0dXNlcjpDaXNjbzEyMyE=' encode ( 'ascii' ) > byte_str b 'devnetuser:Cisco123!' > auth_b64 = base64. > import base64 > auth_str = 'devnetuser:Cisco123!' > byte_str = auth_str. In the case of Cisco’s DevNet sandbox for DNA Center, that means the username and password would be: The Cisco DNA Center REST API documentation indicates that the usernamd and password should be represented as a string that is colon separated before being encoded as base64. Security is dependent on HTTPS/TLS.īase64 encoding for authentication with a REST API will take on a few different forms, depending on the REST API so check the documentation. It is very important that when using Basic Auth that you use HTTPS, as the credentials are not encrypted in the HTTP headers. It is an authentication scheme that includes your username and password in an HTTP ‘Authentication’ header. I have talked briefly about HTTP Basic Auth in my guide to the Cisco NFVIS API. Important: base64 is not an encryption algorithm as it can be easily reversed, so should not be used for security purposes.There are 64 characters represented in total (26 Uppercase, 26 Lowercase, 10 numbers, and + and / characters).It’s a conversion between bytes and ASCII characters.I encourage you to read the article to gain a better understand. There are quite a few articles out there, but the one that I found on Stack Abuse explained it quite well and simply enough. If you wanted to follow along, open up the Always-On sandbox for Cisco DNA Center AO 2.1.2.5. This article is going to briefly explain base64 encoding and how to use it for authorization with REST API’s, specifically Cisco DNA Center. The one that I’m currently exploring is the Cisco DNA Center REST API.
![change header using base64 encoding change header using base64 encoding](https://media.list.ly/production/322144/1964060/item1964060_600px.png)
![change header using base64 encoding change header using base64 encoding](https://blog.bmaehr.com/wp-content/uploads/2016/01/BLOG_OSB_BasicAuthentication_03.png)
These environments permit a developer access to a wide variety of technologies that Cisco customers deploy, including ACI, ISE, FirePower FMC, Viptela vManage, StealthWatch, Umbrella, Webex Meetings, and many more. Today while reading through the official certification guide it talked about how authorization into the API required that your credentials be passed as a base64 encoded string, but it didn’t indicate how to accomplish this.įor those that aren’t familiar with Cisco’s DevNet Sandboxes, Cisco provides free access to read-only always-on and reservation based sandbox environments. I have been exploring the Cisco DNA Center REST API as part of studying for the Cisco Certified DevNet Associate certification exam. HTTP Basic Auth with Ansible URI Module.A quicker way of using HTTP Basic Auth with Requests.Base64 Encoding with HTTP Basic Auth for API’s