Akamai-EdgeAuth is Akamai Edge Authorization Token in the HTTP Cookie, Query String and Header for a client. You can configure it in the Property Manager at https://control.akamai.com. It's a behavior which is Auth Token 2.0 Verification.
Akamai-EdgeAuth supports Python 2.6–2.7 & 3.3–3.6, and runs great on PyPy. (This is Akamai unofficial code)
To install Akamai Edge Authorization Token for Python:
$ pip install akamai-edgeauthfrom akamai.edgeauth import EdgeAuth, EdgeAuthError import requests # just for this example ET_HOSTNAME = 'edgeauth.akamaized.net' ET_ENCRYPTION_KEY = 'YourEncryptionKey' DURATION = 500 # secondsET_ENCRYPTION_KEY must be hexadecimal digit string with even-length. Don't expose ET_ENCRYPTION_KEY on the public repository.
URL parameter option
# 1) Cookie at = EdgeAuth(key=ET_ENCRYPTION_KEY, window_seconds=DURATION, escape_early=True) token = at.generateToken(url="/akamai/edgeauth") url = "http://{0}{1}".format(ET_HOSTNAME, "/akamai/edgeauth") response = requests.get(url, cookies={at.token_name: token}) print(response) # Maybe not 403 # 2) Query string token = at.generateToken(url="/akamai/edgeauth") url = "http://{0}{1}?{2}={3}".format(ET_HOSTNAME, "/akamai/edgeauth", at.token_name, token) response = requests.get(url) print(response)It depends on turning on/off 'Escape token input' in the property manager. (on: escape_early=True / off: escape_early=False) In [Example 2], it's only okay for 'Ignore query string' option on in the property manager. If you want to 'Ignore query string' off using query string as your token, Please contact your Akamai representative.
ACL(Access Control List) parameter option
# 1) Header using * at = EdgeAuth(key=ET_ENCRYPTION_KEY, window_seconds=DURATION) token = at.generateToken(acl="/akamai/edgeauth/list/*") url = "http://{0}{1}".format(ET_HOSTNAME, "/akamai/edgeauth/list/something") response = requests.get(url, headers={at.token_name: token}) print(response) # 2) Cookie Delimited by '!' acl = ["/akamai/edgeauth", "/akamai/edgeauth/list/*"] token = at.generateToken(acl=EdgeAuth.ACL_DELIMITER.join(acl)) url = "http://{0}{1}".format(ET_HOSTNAME, "/akamai/edgeauth/list/something2") # or "/akamai/edgeauth" response = requests.get(url, cookies={at.token_name: token}) print(response)It doesn't matter turning on/off 'Escape token input' in the property manager, but you should keep escape_early=False (Default)
EdgeAuth Class
EdgeAuth(token_type=None, token_name='__token__', key=None, algorithm='sha256', salt=None, start_time=None, end_time=None, window_seconds=None, field_delimiter='~', escape_early=False, verbose=False)#
Parameter Description token_type Select a preset. (Not Supported Yet) token_name Parameter name for the new token. [Default: __token__] key Secret required to generate the token. It must be hexadecimal digit string with even-length. algorithm Algorithm to use to generate the token. (sha1, sha256, or md5) [Default:sha256] salt Additional data validated by the token but NOT included in the token body. (It will be deprecated) start_time What is the start time? (Use string 'now' for the current time) end_time When does this token expire? 'end_time' overrides 'window_seconds' window_seconds How long is this token valid for? field_delimiter Character used to delimit token body fields. [Default: ~] escape_early Causes strings to be 'url' encoded before being used. verbose Print all parameters.
EdgeAuth's Static Variable
ACL_DELIMITER = '!' # Character used to delimit acl fields.EdgeAuth's Method
generateToken(url=None, acl=None, start_time=None, end_time=None, window_seconds=None, ip=None, payload=None, session_id=None)# Returns the authorization token string.
Parameter Description url Single URL path. acl Access control list delimited by ! [ie. /*] start_time Same as Authtoken's parameters, but they overrides Authtoken's. end_time window_seconds ip IP Address to restrict this token to. (Troublesome in many cases (roaming, NAT, etc) so not often used) payload Additional text added to the calculated digest. session_id The session identifier for single use tokens or other advanced cases.
$ python cms_edgeauth.py -k YourEncryptionKey -w 5000 -u /hello/world -xUse -h or --help option for the detail.
