akamai / edgeauth-token-python Goto Github PK
View Code? Open in Web Editor NEWAkamai Authorization Token for Python
License: Apache License 2.0
Akamai Authorization Token for Python
License: Apache License 2.0
What about support for Python 3.7?
Hello,
Hhen parsing option -s: its parameter is parsed as string line 218
later it's assigned without a cast line 53
then it's compared to string now and (in that case it's overwritten with an int) or it's verified that it can be cast to a positive integer line 72
So far so good.
Problem is that it's not cast to an int when trying to add it to window_second line 103 and when comparing it to end time line 108
A fix consist in casting it to an int in these lines
Another option maybe more consistent with what is done when it's now would consist in overwriting the string by an int asap.
I'll excuse in advance, I'm not that advanced in Python, but it seems that the IP function (-i --ip) doesn't work as it fails.
I fixed mine (I think) changing the code on line 150:
new_token.append('ip={0}'.format(self._escape_early(ip)))
to
new_token.append('ip={0}'.format(self._escape_early(self.ip)))
in cms_edgeauth.py
Hi,
I have an old copy of Akamai EdgeAuth Token 2.0 implementation for PHP.
Can you publish on github?
"author: James Mutton [email protected] // Copyright (c) 2011, Akamai Technologies, Inc."
Thanks!
Want to make sure I understand the terms of using this code.
In the readme it's stated that "(This is Akamai unofficial code)" but later under License section there's: "Copyright 2017 Akamai Technologies, Inc. All rights reserved."
Which is true? :)
$ pip3 install akamai-edgeauth
Collecting akamai-edgeauth
Downloading https://files.pythonhosted.org/packages/15/08/1e01d4b2e1751c71b6677a796964eec236a3a3d6361572d32720ddaadc13/akamai-edgeauth-0.3.2.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-etnez0u5/akamai-edgeauth/setup.py", line 7, in <module>
readme = f.read()
File "/usr/lib/python3.5/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 830: ordinal not in range(128)
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-etnez0u5/akamai-edgeauth/
A quick look through README.rst
shows that there are several bytes that are not ASCII:
danderso@a192-168-20-20:~/tmp$ wget https://raw.githubusercontent.com/akamai/EdgeAuth-Token-Python/master/README.rst
--2019-04-21 20:55:59-- https://raw.githubusercontent.com/akamai/EdgeAuth-Token-Python/master/README.rst
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.40.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.40.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7215 (7.0K) [text/plain]
Saving to: 'README.rst'
README.rst 100%[===================>] 7.05K --.-KB/s in 0s
2019-04-21 20:56:00 (41.9 MB/s) - 'README.rst' saved [7215/7215]
danderso@a192-168-20-20:~/tmp$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> fp = open('README.rst', 'rb')
>>> while True:
... b = fp.read(1)
... if not b:
... break
... if b[0] >= 0x80:
... print('\n\n--- non-ascii byte {0} found here ---\n'.format(int(b[0])))
... continue
... print(b.decode(), end='')
...
EdgeAuth-Token-Python: Akamai Edge Authorization Token for Python
=================================================================
.. image:: https://img.shields.io/pypi/v/akamai-edgeauth.svg
:target: https://pypi.python.org/pypi/akamai-edgeauth
.. image:: https://travis-ci.org/akamai/EdgeAuth-Token-Python.svg?branch=master
:target: https://travis-ci.org/akamai/EdgeAuth-Token-Python
.. image:: http://img.shields.io/:license-apache-blue.svg
:target: https://github.com/akamai/EdgeAuth-Token-Python/blob/master/LICENSE
EdgeAuth-Token-Python 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.
EdgeAuth-Token-Python supports Python 2.6
--- non-ascii byte 226 found here ---
--- non-ascii byte 128 found here ---
--- non-ascii byte 147 found here ---
2.7 & 3.3
--- non-ascii byte 226 found here ---
--- non-ascii byte 128 found here ---
--- non-ascii byte 147 found here ---
3.6 and runs great on PyPy.
.. image:: https://github.com/AstinCHOI/akamai-asset/blob/master/edgeauth/edgeauth.png?raw=true
:align: center
Installation
------------
To install Akamai Edge Authorization Token for Python:
.. code-block:: bash
$ pip install akamai-edgeauth
Example
-------
.. code-block:: python
from akamai.edgeauth import EdgeAuth, EdgeAuthError
import requests # just for this example
ET_HOSTNAME = 'edgeauth.akamaized.net'
ET_ENCRYPTION_KEY = 'YourEncryptionKey'
DEFAULT_WINDOW_SECONDS = 500 # seconds
* ET_ENCRYPTION_KEY must be hexadecimal digit string with even-length.
* Don't expose ET_ENCRYPTION_KEY on the public repository.
**URL parameter option**
.. code-block:: python
# 1) Cookie
et = EdgeAuth(**{'key': ET_ENCRYPTION_KEY,
'window_seconds': DEFAULT_WINDOW_SECONDS})
token = et.generate_url_token("/akamai/edgeauth")
url = "http://{0}{1}".format(ET_HOSTNAME, "/akamai/edgeauth")
response = requests.get(url, cookies={et.token_name: token})
print(response) # Maybe not 403
# 2) Query string
token = et.generate_url_token("/akamai/edgeauth")
url = "http://{0}{1}?{2}={3}".format(ET_HOSTNAME, "/akamai/edgeauth", et.token_name, token)
response = requests.get(url)
print(response)
* 'Escape token input' option in the Property Manager corresponds to 'escape_early' in the code.
| Escape token input (on) == escape_early (True)
| Escape token input (off) == escape_early (False)
* In [Example 2] for Query String, it's only okay for 'Ignore query string' option (on).
* If you want to 'Ignore query string' option (off) using query string as your token, Please contact your Akamai representative.
**ACL(Access Control List) parameter option**
.. code-block:: python
# 1) Header using *
et = EdgeAuth(**{'key': ET_ENCRYPTION_KEY,
'window_seconds': DEFAULT_WINDOW_SECONDS})
token = et.generate_acl_token("/akamai/edgeauth/list/*")
url = "http://{0}{1}".format(ET_HOSTNAME, "/akamai/edgeauth/list/something")
response = requests.get(url, headers={et.token_name: token})
print(response)
# 2) Cookie Delimited by '!'
acl_path = ["/akamai/edgeauth", "/akamai/edgeauth/list/*"]
token = et.generate_acl_token(acl_path)
# url = "http://{0}{1}".format(ET_HOSTNAME, "/akamai/edgeauth")
url = "http://{0}{1}".format(ET_HOSTNAME, "/akamai/edgeauth/list/something2")
response = requests.get(url, cookies={et.token_name: token})
print(response)
* ACL can use the wildcard(\*, ?) in the path.
* Don't use '!' in your path because it's ACL Delimiter.
* Use 'escape_early=False' as default setting but it doesn't matter turning on/off 'Escape token input' option in the Property Manager
Usage
-----
**EdgeAuth Class**
.. code-block:: python
class EdgeAuth(token_type=None, token_name='__token__', key=None, algorithm='sha256',
salt=None, ip=None, payload=None, session_id=None,
start_time=None, end_time=None, window_seconds=None,
field_delimiter='~', acl_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)
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.
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: ~]
acl_delimiter Character used to delimit acl. [ Default: ! ]
escape_early Causes strings to be 'url' encoded before being used.
verbose Print all parameters.
==================== ===================================================================================================
**EdgeAuth's Method**
.. code-block:: python
def generate_url_token(url)
def generate_acl_token(acl)
# Returns the authorization token string.
+-----------+--------------------------------------------------------------------------------------------------------+
| Parameter | Description |
+===========+========================================================================================================+
| url | Single URL path (String) |
+-----------+--------------------------------------------------------------------------------------------------------+
| acl | Access Control List can use the wildcard(\*, ?). It can be String (single path) or Array (multi paths) |
+-----------+--------------------------------------------------------------------------------------------------------+
Test
----
"/test" directory is only for the internal test.
Others
------
If you use the **Segmented Media Protection** behavior in AMD(Adaptive Media Delivery) Product, **token_name** should be '**hdnts**'.
.. image:: https://github.com/AstinCHOI/akamai-asset/blob/master/edgeauth/segmented_media_protection.png?raw=true
:align: center
Command
-------
.. code-block:: bash
$ python cms_edgeauth.py -k YourEncryptionKey -w 5000 -u /hello/world -x
Use -h or --help option for the detail.
>>> fp.close()
>>>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.