|
1 |
| -============== |
2 |
| -Authentication |
3 |
| -============== |
4 |
| - |
5 |
| -API Authentication |
6 |
| -================== |
7 |
| - |
8 |
| -Audible uses the `sign request` or the `bearer` method to authenticate the |
9 |
| -requests to the Audible API. |
10 |
| - |
11 |
| -The authentication is done automatically when using the :class:`audible.LoginAuthenticator` |
12 |
| -or :class:`audible.FileAuthenticator`. Simply use an ``Authenticator`` with |
13 |
| -the :class:`audible.Client` or :class:`audible.AsyncClient` like so:: |
14 |
| - |
15 |
| - auth = audible.FileAuthenticator(...) |
16 |
| - client = audible.Client(auth=auth) |
17 |
| - |
18 |
| -The Authenticator will try to use the sign request method if available. |
19 |
| -Otherwise the Authenticator will try the bearer method. If no method is |
20 |
| -available an exception is raised. |
21 |
| - |
22 |
| -Sign request method |
23 |
| -------------------- |
24 |
| - |
25 |
| -With the sign request method you gain unrestricted access to the Audible API. |
26 |
| -To use this method, you need the RSA private key and the adp_token from a |
27 |
| -*device registration*. This method is used by the Audible apps for iOS and |
28 |
| -Android too. |
29 |
| - |
30 |
| -Request signing is fairly straight-forward and uses a signed SHA256 digest. |
31 |
| -Headers look like:: |
32 |
| - |
33 |
| - x-adp-alg: SHA256withRSA:1.0 |
34 |
| - x-adp-signature: AAAAAAAA...:2019-02-16T00:00:01.000000000Z, |
35 |
| - x-adp-token: {enc:...} |
36 |
| - |
37 |
| -Bearer method |
38 |
| -------------- |
39 |
| - |
40 |
| -API requests with the bearer method are restricted. Some API call like the |
41 |
| -:http:post:`/1.0/content/(string:asin)/licenserequest` doesn't work. To use |
42 |
| -the bearer method you need an access token and a client id. You receive the |
43 |
| -token after an authorization or device registration. Which values are valid |
44 |
| -for the client-id is unknown but 0 does work. An access token expires after |
45 |
| -60 minutes. It can be renewed with a refresh token. A refresh token is obtained |
46 |
| -by a device registration only. Headers for the bearer method look like:: |
47 |
| - |
48 |
| - Authorization: Bearer Atna|... |
49 |
| - client-id: 0 |
50 |
| - |
51 |
| -Website Authentication |
52 |
| -====================== |
53 |
| - |
54 |
| -To authenticate website requests you need the website cookies received from an |
55 |
| -authorization or device registration. |
56 |
| - |
57 |
| -You can use the website cookies from an ``Authenticator`` with a |
58 |
| -:class:`httpx.Client` or :class:`httpx.AsyncClient` like so:: |
59 |
| - |
60 |
| - auth = audible.FileAuthenticator(...) |
61 |
| - with httpx.Client(cookies=auth.website_cookies) as client: |
62 |
| - resp = client.get("https://www.amazon.com/cpe/yourpayments/wallet?ref_=ya_d_c_pmt_mpo") |
63 |
| - resp = client.get("https://www.audible.com") |
64 |
| - |
65 |
| -.. note:: |
66 |
| - |
67 |
| - Website cookies are limited to the scope of a top level domain |
68 |
| - (e.g. com, de, ...). To set website cookies for another top level domain |
69 |
| - scope, you can call ``auth.set_website_cookies_for_country(COUNTRY_CODE)``. |
70 |
| - |
71 |
| -.. warning:: |
72 |
| - |
73 |
| - Set website cookies for another country will override the old ones. If you |
74 |
| - want to keep the new cookies, please make sure to save your authentication data. |
75 |
| - |
76 |
| -Using Postman for authentication |
77 |
| -================================ |
78 |
| - |
79 |
| -`Postman <https://www.postman.com>`_ is a helpful utility to test API's. |
80 |
| - |
81 |
| -To use Postman with the Audible API, every request needs to be authenticated. |
82 |
| -You can use the bearer method (with his limitions) with Postman out of the box. |
83 |
| - |
84 |
| -Using the sign request method with Postman is possible, but needs some extra work. |
85 |
| - |
86 |
| -HOWTO: |
87 |
| - |
88 |
| -1. Install the `postman_util_lib <https://joolfe.github.io/postman-util-lib/>`_ |
89 |
| -2. Copy the content from the :download:`pre-request-script <../../../utils/postman/pm_pre_request.js>` |
90 |
| - into the `Pre-request Scripts` Tab for the Collection or request |
91 |
| -3. Create an Environment and define the variables `adp-token` and `private key` |
92 |
| - with the counterparts from the authentication data file |
| 1 | +============== |
| 2 | +Authentication |
| 3 | +============== |
| 4 | + |
| 5 | +API Authentication |
| 6 | +================== |
| 7 | + |
| 8 | +Audible uses the `sign request` or the `bearer` method to authenticate the |
| 9 | +requests to the Audible API. |
| 10 | + |
| 11 | +The authentication is done automatically when using the |
| 12 | +:class:`audible.Authenticator`. Simply use the ``Authenticator`` with |
| 13 | +the :class:`audible.Client` or :class:`audible.AsyncClient` like so:: |
| 14 | + |
| 15 | + auth = audible.Authenticator.from_file(...) |
| 16 | + client = audible.Client(auth=auth) |
| 17 | + |
| 18 | +The Authenticator will try to use the sign request method if available. |
| 19 | +Otherwise the Authenticator will try the bearer method. If no method is |
| 20 | +available an exception is raised. |
| 21 | + |
| 22 | +Sign request method |
| 23 | +------------------- |
| 24 | + |
| 25 | +With the sign request method you gain unrestricted access to the Audible API. |
| 26 | +To use this method, you need the RSA private key and the adp_token from a |
| 27 | +*device registration*. This method is used by the Audible apps for iOS and |
| 28 | +Android too. |
| 29 | + |
| 30 | +Request signing is fairly straight-forward and uses a signed SHA256 digest. |
| 31 | +Headers look like:: |
| 32 | + |
| 33 | + x-adp-alg: SHA256withRSA:1.0 |
| 34 | + x-adp-signature: AAAAAAAA...:2019-02-16T00:00:01.000000000Z, |
| 35 | + x-adp-token: {enc:...} |
| 36 | + |
| 37 | +Bearer method |
| 38 | +------------- |
| 39 | + |
| 40 | +API requests with the bearer method are restricted. Some API call like the |
| 41 | +:http:post:`/1.0/content/(string:asin)/licenserequest` doesn't work. To use |
| 42 | +the bearer method you need an access token and a client id. You receive the |
| 43 | +token after an authorization or device registration. Which values are valid |
| 44 | +for the client-id is unknown but 0 does work. An access token expires after |
| 45 | +60 minutes. It can be renewed with a refresh token. A refresh token is obtained |
| 46 | +by a device registration only. Headers for the bearer method look like:: |
| 47 | + |
| 48 | + Authorization: Bearer Atna|... |
| 49 | + client-id: 0 |
| 50 | + |
| 51 | +Website Authentication |
| 52 | +====================== |
| 53 | + |
| 54 | +To authenticate website requests you need the website cookies received from an |
| 55 | +authorization or device registration. |
| 56 | + |
| 57 | +You can use the website cookies from an ``Authenticator`` with a |
| 58 | +:class:`httpx.Client` or :class:`httpx.AsyncClient` like so:: |
| 59 | + |
| 60 | + auth = audible.Authenticator.from_file(...) |
| 61 | + with httpx.Client(cookies=auth.website_cookies) as client: |
| 62 | + resp = client.get("https://www.amazon.com/cpe/yourpayments/wallet?ref_=ya_d_c_pmt_mpo") |
| 63 | + resp = client.get("https://www.audible.com") |
| 64 | + |
| 65 | +.. note:: |
| 66 | + |
| 67 | + Website cookies are limited to the scope of a top level domain |
| 68 | + (e.g. com, de, ...). To set website cookies for another top level domain |
| 69 | + scope, you can call ``auth.set_website_cookies_for_country(COUNTRY_CODE)``. |
| 70 | + |
| 71 | +.. warning:: |
| 72 | + |
| 73 | + Set website cookies for another country will override the old ones. If you |
| 74 | + want to keep the new cookies, please make sure to save your authentication data. |
| 75 | + |
| 76 | +Using Postman for authentication |
| 77 | +================================ |
| 78 | + |
| 79 | +`Postman <https://www.postman.com>`_ is a helpful utility to test API's. |
| 80 | + |
| 81 | +To use Postman with the Audible API, every request needs to be authenticated. |
| 82 | +You can use the bearer method (with his limitions) with Postman out of the box. |
| 83 | + |
| 84 | +Using the sign request method with Postman is possible, but needs some extra work. |
| 85 | + |
| 86 | +HOWTO: |
| 87 | + |
| 88 | +1. Install the `postman_util_lib <https://joolfe.github.io/postman-util-lib/>`_ |
| 89 | +2. Copy the content from the :download:`pre-request-script <../../../utils/postman/pm_pre_request.js>` |
| 90 | + into the `Pre-request Scripts` Tab for the Collection or request |
| 91 | +3. Create an Environment and define the variables `adp-token` and `private key` |
| 92 | + with the counterparts from the authentication data file |
0 commit comments