Skip to content

Commit 41fa89f

Browse files
committed
Code Refactoring & Doc updates
1 parent b4bbe4a commit 41fa89f

File tree

5 files changed

+483
-254
lines changed

5 files changed

+483
-254
lines changed

README.rst

Lines changed: 76 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
Akamai-EdgeAuth: Akamai Edge Authorization Token for Python
1+
EdgeAuth-Token-Python: Akamai Edge Authorization Token for Python
22
===========================================================
33

44
.. image:: https://img.shields.io/pypi/v/akamai-edgeauth.svg
55
:target: https://pypi.python.org/pypi/akamai-edgeauth
66

7-
.. image:: https://travis-ci.org/AstinCHOI/Akamai-EdgeAuth-Python.svg?branch=master
8-
:target: https://travis-ci.org/AstinCHOI/Akamai-EdgeAuth-Python
7+
.. image:: https://travis-ci.org/akamai/EdgeAuth-Token-Python.svg?branch=master
8+
:target: https://travis-ci.org/akamai/EdgeAuth-Token-Python
99

1010
.. image:: http://img.shields.io/:license-apache-blue.svg
11-
:target: https://github.com/AstinCHOI/Akamai-EdgeAuth-Python/blob/master/LICENSE
11+
:target: https://github.com/akamai/EdgeAuth-Token-Python/blob/master/LICENSE
1212

1313

14-
Akamai-EdgeAuth is Akamai Edge Authorization Token in the HTTP Cookie, Query String and Header for a client.
14+
EdgeAuth-Token-Python is Akamai Edge Authorization Token in the HTTP Cookie, Query String, and Header for a client.
1515
You can configure it in the Property Manager at https://control.akamai.com.
1616
It's a behavior which is Auth Token 2.0 Verification.
1717

18-
Akamai-EdgeAuth supports Python 2.6–2.7 & 3.3–3.6, and runs great on PyPy. (This is Akamai unofficial code)
18+
EdgeAuth-Token-Python supports Python 2.6–2.7 & 3.3–3.6 and runs great on PyPy.
1919

2020

2121
.. image:: https://github.com/AstinCHOI/akamai-asset/blob/master/edgeauth/edgeauth.png?raw=true
@@ -44,122 +44,121 @@ Example
4444
ET_ENCRYPTION_KEY = 'YourEncryptionKey'
4545
DURATION = 500 # seconds
4646
47-
::
4847
49-
ET_ENCRYPTION_KEY must be hexadecimal digit string with even-length.
50-
Don't expose ET_ENCRYPTION_KEY on the public repository.
48+
* ET_ENCRYPTION_KEY must be hexadecimal digit string with even-length.
49+
* Don't expose ET_ENCRYPTION_KEY on the public repository.
5150

5251
**URL parameter option**
5352

5453
.. code-block:: python
5554
5655
# 1) Cookie
57-
at = EdgeAuth(key=ET_ENCRYPTION_KEY, window_seconds=DURATION, escape_early=True)
58-
token = at.generateToken(url="/akamai/edgeauth")
56+
et = EdgeAuth((**{'key': ET_ENCRYPTION_KEY,
57+
'window_seconds': DEFAULT_WINDOW_SECONDS}
58+
token = et.generate_url_token("/akamai/edgeauth")
5959
url = "http://{0}{1}".format(ET_HOSTNAME, "/akamai/edgeauth")
60-
response = requests.get(url, cookies={at.token_name: token})
60+
response = requests.get(url, cookies={et.token_name: token})
6161
print(response) # Maybe not 403
6262
6363
# 2) Query string
64-
token = at.generateToken(url="/akamai/edgeauth")
65-
url = "http://{0}{1}?{2}={3}".format(ET_HOSTNAME, "/akamai/edgeauth", at.token_name, token)
64+
token = et.generate_url_token("/akamai/edgeauth")
65+
url = "http://{0}{1}?{2}={3}".format(ET_HOSTNAME, "/akamai/edgeauth", et.token_name, token)
6666
response = requests.get(url)
6767
print(response)
6868
69-
::
7069
71-
It depends on turning on/off 'Escape token input' in the property manager. (on: escape_early=True / off: escape_early=False)
72-
In [Example 2], it's only okay for 'Ignore query string' option on in the property manager.
73-
If you want to 'Ignore query string' off using query string as your token, Please contact your Akamai representative.
70+
* 'Escape token input' option in the Property Manager corresponds to 'escape_early' in the code.
71+
Escape token input (on) == escape_early (True)
72+
Escape token input (off) == escape_early (False)
73+
74+
* In [Example 2] for Query String, it's only okay for 'Ignore query string' option (on).
75+
* If you want to 'Ignore query string' option (off) using query string as your token, Please contact your Akamai representative.
7476
7577
7678
**ACL(Access Control List) parameter option**
7779
7880
.. code-block:: python
7981
8082
# 1) Header using *
81-
at = EdgeAuth(key=ET_ENCRYPTION_KEY, window_seconds=DURATION)
82-
token = at.generateToken(acl="/akamai/edgeauth/list/*")
83+
et = EdgeAuth((**{'key': ET_ENCRYPTION_KEY,
84+
'window_seconds': DEFAULT_WINDOW_SECONDS}
85+
token = et.generate_acl_token("/akamai/edgeauth/list/*")
8386
url = "http://{0}{1}".format(ET_HOSTNAME, "/akamai/edgeauth/list/something")
84-
response = requests.get(url, headers={at.token_name: token})
87+
response = requests.get(url, headers={et.token_name: token})
8588
print(response)
8689
8790
# 2) Cookie Delimited by '!'
88-
acl = ["/akamai/edgeauth", "/akamai/edgeauth/list/*"]
89-
token = at.generateToken(acl=EdgeAuth.ACL_DELIMITER.join(acl))
91+
acl_path = ["/akamai/edgeauth", "/akamai/edgeauth/list/*"]
92+
token = at.generate_acl_token(acl_path)
93+
# url = "http://{0}{1}".format(ET_HOSTNAME, "/akamai/edgeauth")
9094
url = "http://{0}{1}".format(ET_HOSTNAME, "/akamai/edgeauth/list/something2")
91-
# or "/akamai/edgeauth"
9295
response = requests.get(url, cookies={at.token_name: token})
9396
print(response)
94-
9597
::
9698
97-
It doesn't matter turning on/off 'Escape token input' in the property manager, but you should keep escape_early=False (Default)
98-
99+
* ACL can use the wildcard(\*, ?) in the path.
100+
* Don't use '!' in your path because it's ACL Delimiter.
101+
* Use 'escape_early=False' as default setting but it doesn't matter turning on/off 'Escape token input' option in the Property Manager
102+
99103
100104
Usage
101105
-----
102106
**EdgeAuth Class**
103107
104108
.. code-block:: python
105109
106-
EdgeAuth(token_type=None, token_name='__token__', key=None, algorithm='sha256',
107-
salt=None, start_time=None, end_time=None, window_seconds=None,
108-
field_delimiter='~', escape_early=False, verbose=False)
109-
110-
#
111-
112-
==================== ===================================================================================================
113-
Parameter Description
114-
==================== ===================================================================================================
115-
token_type Select a preset. (Not Supported Yet)
116-
token_name Parameter name for the new token. [Default: __token__]
117-
key Secret required to generate the token. It must be hexadecimal digit string with even-length.
118-
algorithm Algorithm to use to generate the token. (sha1, sha256, or md5) [Default:sha256]
119-
salt Additional data validated by the token but NOT included in the token body. (It will be deprecated)
120-
start_time What is the start time? (Use string 'now' for the current time)
121-
end_time When does this token expire? 'end_time' overrides 'window_seconds'
122-
window_seconds How long is this token valid for?
123-
field_delimiter Character used to delimit token body fields. [Default: ~]
124-
escape_early Causes strings to be 'url' encoded before being used.
125-
verbose Print all parameters.
126-
==================== ===================================================================================================
127-
128-
**EdgeAuth's Static Variable**
110+
EdgeAuth(token_type=None, token_name='__token__', key=None, algorithm='sha256', salt=None,
111+
ip=None, payload=None, session_id=None, start_time=None, end_time=None, window_seconds=None,
112+
field_delimiter='~', acl_delimiter='!', escape_early=False, verbose=False)
113+
114+
==================== ===================================================================================================
115+
Parameter Description
116+
==================== ===================================================================================================
117+
token_type Select a preset. (Not Supported Yet)
118+
token_name Parameter name for the new token. [Default: __token__]
119+
key Secret required to generate the token. It must be hexadecimal digit string with even-length.
120+
algorithm Algorithm to use to generate the token. (sha1, sha256, or md5) [Default:sha256]
121+
salt Additional data validated by the token but NOT included in the token body. (It will be deprecated)
122+
ip IP Address to restrict this token to. (Troublesome in many cases (roaming, NAT, etc) so not often used)
123+
payload Additional text added to the calculated digest.
124+
session_id The session identifier for single use tokens or other advanced cases.
125+
start_time What is the start time? (Use string 'now' for the current time)
126+
end_time When does this token expire? 'end_time' overrides 'window_seconds'
127+
window_seconds How long is this token valid for?
128+
field_delimiter Character used to delimit token body fields. [Default: ~]
129+
escape_early Causes strings to be 'url' encoded before being used.
130+
verbose Print all parameters.
131+
==================== ===================================================================================================
132+
133+
**EdgeAuth's Method**
129134
130135
.. code-block:: python
131136
132-
ACL_DELIMITER = '!' # Character used to delimit acl fields.
137+
generate_url_token(url_path)
138+
generate_acl_token(acl_path)
133139
140+
# Returns the authorization token string.
134141
135-
**EdgeAuth's Method**
142+
+----------------+--------------------------------------------------------------------------------------------+
143+
| Parameter | Description |
144+
+================+============================================================================================+
145+
| url_path | Single URL path (String) |
146+
+----------------+--------------------------------------------------------------------------------------------+
147+
| acl_path | Access control list using the wildcard(\*, ?) and can be delimited by '!' (String or Array)|
148+
+----------------+--------------------------------------------------------------------------------------------+
136149
137-
.. code-block:: python
138150
139-
generateToken(url=None, acl=None, start_time=None, end_time=None,
140-
window_seconds=None, ip=None, payload=None, session_id=None)
141-
142-
# Returns the authorization token string.
143-
144-
+----------------+---------------------------------------------------------------------------------------------------------+
145-
| Parameter | Description |
146-
+================+=========================================================================================================+
147-
| url | Single URL path. |
148-
+----------------+---------------------------------------------------------------------------------------------------------+
149-
| acl | Access control list delimited by ! [ie. /\*] |
150-
+----------------+---------------------------------------------------------------------------------------------------------+
151-
| start_time | |
152-
+----------------+ +
153-
| end_time | Same as Authtoken's parameters, but they overrides Authtoken's. |
154-
+----------------+ +
155-
| window_seconds | |
156-
+----------------+---------------------------------------------------------------------------------------------------------+
157-
| ip | IP Address to restrict this token to. (Troublesome in many cases (roaming, NAT, etc) so not often used) |
158-
+----------------+---------------------------------------------------------------------------------------------------------+
159-
| payload | Additional text added to the calculated digest. |
160-
+----------------+---------------------------------------------------------------------------------------------------------+
161-
| session_id | The session identifier for single use tokens or other advanced cases. |
162-
+----------------+---------------------------------------------------------------------------------------------------------+
151+
Test
152+
----
153+
"/test" directory is only for the internal test.
154+
155+
156+
Others
157+
------
158+
If you use the **Segmented Media Protection** behavior in AMD(Adaptive Media Delivery) Product, **tokenName(options.tokenName)** should be '**hdnts**'.
159+
160+
.. image:: https://github.com/AstinCHOI/akamai-asset/blob/master/edgeauth/segmented_media_protection.png?raw=true
161+
:align: center
163162
164163
165164
Command

0 commit comments

Comments
 (0)