Comments (9)
Wow thank you! That worked a treat!!! Thanks for taking the time out and pointing me in the right direction. I really appreciate it.
from audible.
Update.
I am using constants for testing with Australia only.
COUNTRY_CODE = "au"
DOMAIN = "com.au"
MARKETPLACE_ID = "AN7EY7DTAW63G"
from audible.
Hi. This does not work!
You create a login url with a specific code verifier. This code verifier must be reused in the login_external function. But the function has no option for this. Instead it creates a new code verifier.
You can now rewrite the callback, so the callback will open the webserver and wait for your curl command.
Or you rewrite the login_external function so it will accept the code verifier as an additional kwargs and then reuse it.
Edit:
FYI - The specific code verifier is bound on the URL (better on the authorization code) you got after a successful login!
from audible.
Oh, I saw you are from Australia. Then it's important that you reuse the serial from the audible.login.build_oauth_url function. Otherwise the external_login function will create a new one and this will not work for your target marketplace.
In my opinion the callback solution is the best way.
from audible.
Thanks for the advice.
In the end, I wont be using CURL, i'll be putting it under an API endpoint using Flask.
I'll have a go at using the callback and making sure the serial and verifier codes all match all the way through.
from audible.
Okay. If you need help, feel free to contact me!
from audible.
Thanks!
I have an endpoint now that returns the URL, code and serial which can be used to build up a web-view on a mobile app.
However, Im not sure how the callback is going to help, as you said, the code isn't an attribute I can pass in like serial is, the callback simply asks for another code_verifier and returns it bypassing the callback anyway (
Line 532 in f225457
Would you have any advice on how to implement the callback system that would help with what I am trying to achieve?
from audible.
I saw you submit the filename too. This is not possible with the callback, since it only accepts a url.
So I rewritten your code.
from urllib.parse import parse_qs
import audible.localization
import audible.login
import httpx
from audible.register import register as register_device
COUNTRY_CODE = "au"
def get_auth_link():
locale = audible.localization.Locale(COUNTRY_CODE)
code_verifier = audible.login.create_code_verifier()
oauth_url, serial = audible.login.build_oauth_url(
country_code=locale.country_code,
domain=locale.domain,
market_place_id=locale.market_place_id,
code_verifier=code_verifier,
with_username=False
)
return {
"code_verifier": code_verifier,
"login_url": oauth_url,
"serial": serial
}
class Authenticator(audible.Authenticator):
@classmethod
def custom_login(
cls, code_verifier: bytes, response_url: str, serial: str
):
auth = cls()
auth.locale = COUNTRY_CODE
response_url = httpx.URL(response_url)
parsed_url = parse_qs(response_url.query.decode())
authorization_code = parsed_url["openid.oa2.authorization_code"][0]
registration_data = register_device(
authorization_code=authorization_code,
code_verifier=code_verifier,
domain=auth.locale.domain,
serial=serial
)
auth._update_attrs(**registration_data)
return auth
def audible_login(request):
# { id: str, url: str, code_verifier: bytes, serial: str}
params = request.json
auth = Authenticator.custom_login(
code_verifier=params['code_verifier'],
response_url=params['url'],
serial=params['serial']
)
auth.to_file(params['id'])
That should actually work.
But if you use Flask, you can also use a kind of proxy to login. Take a look at alexaproxy. I do the same with my private Audible Django project. And it runs fine.
The server request the page at Amazon and rewrite the html code. The prepared html code will send to the clients webbrowser. So the client think, he communicate directly with Amazon.
from audible.
Great to hear that. You have inspires me. I've wrote a POC with playwright in some minutes and it works.
import asyncio
from urllib.parse import parse_qs
import audible.localization
import audible.login
import httpx
from audible.register import register as register_device
from playwright.async_api import async_playwright
COUNTRY_CODE = "de"
def get_auth_link():
locale = audible.localization.Locale(COUNTRY_CODE)
code_verifier = audible.login.create_code_verifier()
oauth_url, serial = audible.login.build_oauth_url(
country_code=locale.country_code,
domain=locale.domain,
market_place_id=locale.market_place_id,
code_verifier=code_verifier,
with_username=False
)
return {
"code_verifier": code_verifier,
"login_url": oauth_url,
"serial": serial
}
class Authenticator(audible.Authenticator):
@classmethod
def custom_login(
cls, code_verifier: bytes, response_url: str, serial: str
):
auth = cls()
auth.locale = COUNTRY_CODE
response_url = httpx.URL(response_url)
parsed_url = parse_qs(response_url.query.decode())
authorization_code = parsed_url["openid.oa2.authorization_code"][0]
registration_data = register_device(
authorization_code=authorization_code,
code_verifier=code_verifier,
domain=auth.locale.domain,
serial=serial
)
auth._update_attrs(**registration_data)
return auth
def audible_login(data):
# { fn: str, url: str, code_verifier: bytes, serial: str}
params = data
print(params)
auth = Authenticator.custom_login(
code_verifier=params['code_verifier'],
response_url=params['url'],
serial=params['serial']
)
auth.to_file(params['fn'])
async def main():
async with async_playwright() as p:
iphone = p.devices["iPhone 12 Pro"]
browser = await p.webkit.launch(headless=False)
context = await browser.new_context(
**iphone,
locale="de-DE"
)
page = await browser.new_page()
login_data = get_auth_link()
await page.goto(login_data["login_url"])
while True:
await page.wait_for_timeout(600)
if "/ap/maplanding" in page.url:
data = {
"fn": "credentials.json",
"url": page.url,
"code_verifier": login_data["code_verifier"],
"serial": login_data["serial"]
}
audible_login(data)
break
continue
await browser.close()
asyncio.run(main())
If you are interessting in.
from audible.
Related Issues (20)
- 错误提示 HOT 19
- Quality is set to `Extreme` even set to `high` HOT 1
- TEST: New device registration method HOT 4
- Extract Audible Bookmark Notes HOT 3
- Issue getting activation bytes from auth server HOT 9
- Switch to poetry, implement CI+CD, remove Python version <3.8
- Lift upper version restriction on `httpx`. HOT 3
- Is there any way to get a list of books in a series? HOT 1
- Amazon authentication code not handled properly HOT 2
- I need some help with metadata HOT 2
- Audible brazil HOT 11
- Brazil Account Can not login by external_login HOT 3
- RecursionError introduced in 0.9.0 in some cases HOT 3
- API doc: Only High and Normal is allowed as quality
- `valid_mail` regex is too strict HOT 3
- How does the BestSellers sort_by option in the APIs work? HOT 3
- Where does the file get stored with to_file() HOT 5
- Can't filter plus catalog books from 'catalog/products' HOT 9
- state token for library requests HOT 2
- response_callback no longer works properly with the endpoint: https://cde-ta-g7g.amazon.com/FionaCDEServiceEngine/sidecar HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from audible.