|
1 | | -Akamai-EdgeAuth: Akamai Edge Authorization Token for Python |
| 1 | +EdgeAuth-Token-Python: Akamai Edge Authorization Token for Python |
2 | 2 | =========================================================== |
3 | 3 |
|
4 | 4 | .. image:: https://img.shields.io/pypi/v/akamai-edgeauth.svg |
5 | 5 | :target: https://pypi.python.org/pypi/akamai-edgeauth |
6 | 6 |
|
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 |
9 | 9 |
|
10 | 10 | .. 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 |
12 | 12 |
|
13 | 13 |
|
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. |
15 | 15 | You can configure it in the Property Manager at https://control.akamai.com. |
16 | 16 | It's a behavior which is Auth Token 2.0 Verification. |
17 | 17 |
|
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. |
19 | 19 |
|
20 | 20 |
|
21 | 21 | .. image:: https://github.com/AstinCHOI/akamai-asset/blob/master/edgeauth/edgeauth.png?raw=true |
@@ -44,122 +44,121 @@ Example |
44 | 44 | ET_ENCRYPTION_KEY = 'YourEncryptionKey' |
45 | 45 | DURATION = 500 # seconds |
46 | 46 |
|
47 | | - :: |
48 | 47 |
|
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. |
51 | 50 |
|
52 | 51 | **URL parameter option** |
53 | 52 |
|
54 | 53 | .. code-block:: python |
55 | 54 |
|
56 | 55 | # 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") |
59 | 59 | 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}) |
61 | 61 | print(response) # Maybe not 403 |
62 | 62 |
|
63 | 63 | # 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) |
66 | 66 | response = requests.get(url) |
67 | 67 | print(response) |
68 | 68 |
|
69 | | - :: |
70 | 69 |
|
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. |
74 | 76 |
|
75 | 77 |
|
76 | 78 | **ACL(Access Control List) parameter option** |
77 | 79 |
|
78 | 80 | .. code-block:: python |
79 | 81 |
|
80 | 82 | # 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/*") |
83 | 86 | 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}) |
85 | 88 | print(response) |
86 | 89 |
|
87 | 90 | # 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") |
90 | 94 | url = "http://{0}{1}".format(ET_HOSTNAME, "/akamai/edgeauth/list/something2") |
91 | | - # or "/akamai/edgeauth" |
92 | 95 | response = requests.get(url, cookies={at.token_name: token}) |
93 | 96 | print(response) |
94 | | -
|
95 | 97 | :: |
96 | 98 |
|
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 | + |
99 | 103 |
|
100 | 104 | Usage |
101 | 105 | ----- |
102 | 106 | **EdgeAuth Class** |
103 | 107 |
|
104 | 108 | .. code-block:: python |
105 | 109 |
|
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** |
129 | 134 |
|
130 | 135 | .. code-block:: python |
131 | 136 |
|
132 | | - ACL_DELIMITER = '!' # Character used to delimit acl fields. |
| 137 | + generate_url_token(url_path) |
| 138 | + generate_acl_token(acl_path) |
133 | 139 |
|
| 140 | + # Returns the authorization token string. |
134 | 141 |
|
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 | ++----------------+--------------------------------------------------------------------------------------------+ |
136 | 149 |
|
137 | | -.. code-block:: python |
138 | 150 |
|
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 |
163 | 162 |
|
164 | 163 |
|
165 | 164 | Command |
|
0 commit comments