Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to perform auth login to Safari Books Online #301

Closed
bthuree opened this issue Nov 16, 2021 · 7 comments
Closed

unable to perform auth login to Safari Books Online #301

bthuree opened this issue Nov 16, 2021 · 7 comments

Comments

@bthuree
Copy link

bthuree commented Nov 16, 2021

Do anyone have some thoughts on what I am doing wrong here?
Bengt

Logging into Safari Books Online...
[#] Login: unable to perform auth login to Safari Books Online.
[*] Details:
    Unexpected error!
[!] Aborting...

And the info file contains

[16/Nov/2021 18:05:49] ** Welcome to SafariBooks! **
[16/Nov/2021 18:05:49] Logging into Safari Books Online...
[16/Nov/2021 18:05:53] Login: unable to perform auth login to Safari Books Online.
[*] Details:
    Unexpected error!
[16/Nov/2021 18:05:53] Last request done:
	URL: https://www.oreilly.com/member/auth/login/
	DATA: None
	OTHERS: {'json': {'email': 'USER', 'password': 'PASSWORD', 'redirect_uri': 'https://api.ore
illy.com%2Fapi%2Fv1%2Fauth%2Fopenid%2Fauthorize%2F%3Fclient_id%3D235442%26redirect_uri%3Dhttps%3A%2F%2Flearning.oreilly.
com%2Fcomplete%2Funified%2F%26state%3D6ohox3TC5AKm8tHtw2dBrLS1jEynMtf1%26response_type%3Dcode%26scope%3Dopenid%2Bprofile
%2Bemail'}}

	400
	Server: istio-envoy
	Vary: Accept, Cookie, Origin,Accept, Accept-Encoding, Authorization, Cookie,Accept, Accept-Encoding, Authorizati
on, Cookie
	Content-Type: application/json
	strict-transport-security: max-age=31536000; includeSubDomains, max-age=31536000; includeSubDomains
	surrogate-key: groot groot-api, groot_frontend_ds groot_frontend_ds-pages
	x-envoy-upstream-service-time: 994
	x-content-type-options: nosniff, nosniff, nosniff
	Allow: POST, OPTIONS
	x-frame-options: DENY
	referrer-policy: same-origin
	Content-Length: 37
	Expires: Tue, 16 Nov 2021 17:05:53 GMT
	Cache-Control: max-age=0, no-cache, no-store
	Pragma: no-cache
	Date: Tue, 16 Nov 2021 17:05:53 GMT
	Connection: close

{"credentials":"invalid_credentials"}


@0Ky
Copy link

0Ky commented Nov 17, 2021

Have you confirmed whether it was a typo in your credentials when using the --cred "email:pass" option? Are you able to login using the browser?

Make sure you're using the latest commit, if it's still not working, then try authenticating by using a cookies.json file, follow the instructions here.

@bthuree
Copy link
Author

bthuree commented Nov 17, 2021

Have not used a cookies.json file.
I can log on manually, and I even changed the password to only have digits and letters to make it easier.
I tried with --cred as well as --login (manually type login and password)
I just did a fresh clone....

@dgallitelli
Copy link

dgallitelli commented Nov 17, 2021

+1 on this. For both the --cred login and the cookies.json approach.

In the info file, I get <p>Temporary Redirect. Redirecting to <a href="/accounts/login/?next=%2Fprofile%2F">/accounts/login/?next=%2Fprofile%2F</a></p> when trying without --cred, while I get {"credentials":"invalid_credentials"} with it.

@0Ky
Copy link

0Ky commented Nov 18, 2021

I don't know what else to say, it's working for me on both Windows and Linux environments. Maybe check requirements & dependencies?

@bthuree If you have a corporate/university account or you're just using single sign-on (SSO) then you must use cookies.

If you decide to use cookies, then follow these steps below:

  1. Clear existing O’Reilly browser cookies from FireFox (go to Settings > Privacy & Security > Manage Data, then search for oreilly, remove relevant cookies).
  2. Sign-in and visit your O’Reilly profile from FireFox browser.
  3. Ctrl+Shift+E (Network Monitor tab on Developer Tools).
  4. Ctrl+R (Reload).
  5. Select the first request (where file: /profile/ and the type: html).
  6. Select Cookies tab, then right-click anywhere inside "Request Cookies", select "Copy All".
  7. Create a new file named cookies.json in the safaribooks directory (where the .py files are located).
  8. Paste the cookies (from step 6) to the cookies.json file.
  9. Remove Request Cookies object (not the key-value pairs inside it), so that all the cookies are in the main object just like this:

cookies.json

{
    "BrowserCookie": "x",
    "csrfsafari": "x",
    "groot_sessionid": "x",
    "logged_in": "x",
    "orm-jwt": "x",
    "orm-rt": "x",
    "salesforce_id": "x",
    "sessionid": "x"
}

You don't necessarily have to use FireFox, although you will need to convert the cookies to a JSON format, shown above.

@dgallitelli When you were using the cookies.json approach have you completed step 9 from above? Make sure there is no nested objects in the cookies.json file.

Then simply use the command (when using cookies, there is no need to use --login or --cred option):

Example: python3 safaribooks.py 9780137489930

@dgallitelli
Copy link

I had to delete two lines from the cookies.json file to make it match the keys in the snippet you shared in the above comment, then run the script with the --login flag. After that, everything worked as intended, without providing the login keys anymore.

I've also forked the project adding a Dockerfile, since in Docker it worked like a charm. You can check it at https://github.com/dgallitelli/safaribooks/tree/origin/dockerize

@0Ky
Copy link

0Ky commented Nov 26, 2021

Great, you could skip the --login option entirely if the cookies.json file with the correct format is created.

The following isn't related to this issue, but I'd like to bring to your attention that there are bugs which can make it unreadable for certain books.

  • Custom fonts used in the books are not downloaded (This can break an entire book if the book only/mostly uses custom fonts)
  • The order of chapters are not chronological, the epub may start with chapter 3 (This occurs when the text "cover" is in the title of a chapter/section)
  • There is no handling of failed HTTP responses, so the script will eventually download a 404 HTML page and save it as a .css
  • For some books the cover image won't be downloaded (I think it's related to the incorrect parsing and matching)
  • CSS/element attribute related issues (eg: wide images become distorted/squished when either resizing the epub reader or viewing the exported pdf, some texts may be vertically orientated and graphic intensive books have alignment issues or the texts won't appear on images when using an epub reader or exporting it to a pdf)

@lorenzodifuccia
Copy link
Owner

lorenzodifuccia commented Jan 12, 2022

  • Custom fonts used in the books are not downloaded (This can break an entire book if the book only/mostly uses custom fonts)
  • The order of chapters are not chronological, the epub may start with chapter 3 (This occurs when the text "cover" is in the title of a chapter/section)
  • There is no handling of failed HTTP responses, so the script will eventually download a 404 HTML page and save it as a .css
  • For some books the cover image won't be downloaded (I think it's related to the incorrect parsing and matching)
  • CSS/element attribute related issues (eg: wide images become distorted/squished when either resizing the epub reader or viewing the exported pdf, some texts may be vertically orientated and graphic intensive books have alignment issues or the texts won't appear on images when using an epub reader or exporting it to a pdf)

I think we should work on them...
@0Ky could you please add all of them to the Improvement 0x01 milestone so we can start to track their resolution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants