cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1844
Views
0
Helpful
3
Replies

How to get Authorization and Date headers

Ankush_Patel
Level 1
Level 1

As we tried to auth api as per documentation we cant able to generate authorization and date headers. Any valid JAVA code is there to generate that ?

3 Replies 3

DuoKristina
Cisco Employee
Cisco Employee
Duo, not DUO.

Ankush_Patel
Level 1
Level 1

I was unable to reproduce the authorization and data using the python code

import base64, email, hmac, hashlib, urllib
def sign(method, host, path, params, skey, ikey):
“”"
Return HTTP Basic Authentication (“Authorization” and “Date”) headers.
method, host, path: strings from request
params: dict of request parameters
skey: secret key
ikey: integration key
“”"

# create canonical string
now = email.Utils.formatdate()
canon = [now, method.upper(), host.lower(), path]
args = []
for key in sorted(params.keys()):
    val = params[key]
    if isinstance(val, unicode):
        val = val.encode("utf-8")
    args.append(
        '%s=%s' % (urllib.quote(key, '~'), urllib.quote(val, '~')))
canon.append('&'.join(args))
canon = '\n'.join(canon)

# sign canonical string
sig = hmac.new(skey, canon, hashlib.sha1)
auth = '%s:%s' % (ikey, sig.hexdigest())

# return headers
return {'Date': now, 'Authorization': 'Basic %s' % base64.b64encode(auth)}

Please can you help

Thanks,
Regards ,
Ankush

Is there any solution for this just for a reminder.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Quick Links