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

Cookies.json format #2

Closed
neogta opened this issue Feb 22, 2018 · 25 comments
Closed

Cookies.json format #2

neogta opened this issue Feb 22, 2018 · 25 comments

Comments

@neogta
Copy link

neogta commented Feb 22, 2018

Hello, my safaribooksonline account is SSO handled by my company, thus I have NO password.
Could you post an example of the cookies.json format ? (with dummy values of course)

@lorenzodifuccia
Copy link
Owner

Sure!
This is an example of cookies.json file:

{"sessionid": "28cb00fc5fefca1c33677383b7c2499f", "salesforce_id": "c22b5131a048c89949719ddfc77a9401", "csrfsafari": "NAowChgKB1Nwb3RpZnkSABoGmAEByAEB", "original_referer": "\"https://www.safaribooksonline.com/home/\"", "BrowserCookie": "c6691600-bbf6-4c96-b721-af081ff879d8", "corp_sessionid": "f2be05e433a0e5883920f34bcf3ce83a", "logged_in": "y"}

👍

@neogta
Copy link
Author

neogta commented Feb 23, 2018

Thank you !

@neogta
Copy link
Author

neogta commented Feb 23, 2018

(and it works ! ) (after setting "locale" to UTF8)

@lorenzodifuccia
Copy link
Owner

Perfect!! Thanks for the issue.

@anhhh11
Copy link

anhhh11 commented Oct 12, 2018

One fast way to get the cookie:
Paste these code into Console of web inspector (F12) in firefox or chrome to get cookie, then paste into cookies.json
var output = {};document.cookie.split(/\s*;\s*/).forEach(function(pair) {pair = pair.split(/\s*=\s*/);output[pair[0]] = pair.splice(1).join('=');});console.log(JSON.stringify(output));

@gabrielgiordan
Copy link

gabrielgiordan commented Oct 14, 2018

Bookmarlet version of @anhhh11 script

javascript:(function(){var output = {};document.cookie.split(/\s*;\s*/).forEach(function(pair) {pair = pair.split(/\s*=\s*/);output[pair[0]]=pair.splice(1).join('=');});console.log(JSON.stringify(output));})();

@anhhh11
Copy link

anhhh11 commented Oct 15, 2018

Bookmarlet generate cookies.json

javascript:(function(){var output={};document.cookie.split(/\s*;\s*/).forEach(function(pair){pair=pair.split(/\s*=\s*/);output[pair[0]]=pair.splice(1).join('=')});var a=window.document.createElement('a');a.href=window.URL.createObjectURL(new Blob([JSON.stringify(output)],{type:'text/json'}));a.download='cookies.json';document.body.appendChild(a);a.click();document.body.removeChild(a)})()

@mengqi1984
Copy link

SSO is working.
Is there a simple way to download without pasting session parameters?

@AldoMX AldoMX mentioned this issue Nov 29, 2018
@hbakhtiyor
Copy link

i tried, but nothing works
[#] API: Out-of-Session (You do not have permission to perform this action.).

vitkin pushed a commit to vitkin/safaribooks that referenced this issue Dec 24, 2018
@tdnghia98
Copy link

Hi how can I specify the cookies file in the command line?

@anhhh11
Copy link

anhhh11 commented Jan 25, 2019

@tdnghia98: Just copy cookies.json to the same folder as safaribooks.py an run this file.

@sathish316
Copy link

(and it works ! ) (after setting "locale" to UTF8)

@neogta How or where do you set the locale?

@dkuzma2
Copy link

dkuzma2 commented Oct 2, 2019

(and it works ! ) (after setting "locale" to UTF8)

@neogta How or where do you set the locale?

Either this is saving the JSON file with correct UTF-8 encoding or system locale - https://www.tecmint.com/set-system-locales-in-linux/

Do you get any errors?

@deppfx
Copy link

deppfx commented Dec 13, 2019

I am getting this error even after using cookies.json

~/git/safaribooks $ (master) python3 safaribooks.py --no-kindle xxxxxxxxxxxx
                                                                                                                                                                                                                   
 ██████╗     ██████╗ ██╗  ██╗   ██╗██████╗ 
██╔═══██╗    ██╔══██╗██║  ╚██╗ ██╔╝╚════██╗
██║   ██║    ██████╔╝██║   ╚████╔╝   ▄███╔╝
██║   ██║    ██╔══██╗██║    ╚██╔╝    ▀▀══╝ 
╚██████╔╝    ██║  ██║███████╗██║     ██╗   
 ╚═════╝     ╚═╝  ╚═╝╚══════╝╚═╝     ╚═╝                                           

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[#] Authentication issue: unable to access profile page.                                                                                                                                                           
[!] Aborting...

@dkuzma2
Copy link

dkuzma2 commented Dec 13, 2019

@deppfx

Make sure that the content of the cookie file looks properly.
What I did is manually edited the json file as I also had issues with exporting the cookie.

In the browser console run:
var output = {};document.cookie.split(/\s*;\s*/).forEach(function(pair) {pair = pair.split(/\s*=\s*/);output[pair[0]] = pair.splice(1).join('=');});console.log(JSON.stringify(output));
and then display the cookie in json by typing output and copy the content to the json file.

@antrianis
Copy link

antrianis commented Dec 15, 2019

does this still work? I get:
[#] Authentication issue: unable to access profile page.
[!] Aborting...

@dkuzma2 what did you edit in the cookies.json?

Update: I fixed it by changing the script to connect to a different url of oreilly.

@lurumad
Copy link

lurumad commented Dec 20, 2019

Hi @antrianis

Would you mind to tell us what url have you changed in the script?

Regards!

@antrianis
Copy link

antrianis commented Dec 20, 2019 via email

@lurumad
Copy link

lurumad commented Dec 20, 2019

In my case, I've changed this:

PROFILE_URL = SAFARI_BASE_URL + "/home/?next=%2Fprofile%2F"

and it's working fine!

Regards!

vlqhai pushed a commit to vlqhai/safaribooks that referenced this issue Feb 23, 2020
remove unused imported module Selector
@deppfx
Copy link

deppfx commented Feb 27, 2020

This is what worked in Firefox.

  1. As @dkuzma2 mentioned, In the browser console run:
    var output = {};document.cookie.split(/\s*;\s*/).forEach(function(pair) {pair = pair.split(/\s*=\s*/);output[pair[0]] = pair.splice(1).join('=');});console.log(JSON.stringify(output));

  2. Edit safaribooks.py and add a new line
    PROFILE_URL = "https://www.oreilly.com/member/"
    right below the line
    PROFILE_URL = SAFARI_BASE_URL + "/profile/"

  3. Run
    python3 safaribooks.py <BOOKID>

@hasanloo
Copy link

After these steps I am getting the following error:

[-] Successfully authenticated.
[*] Retrieving book info...
[#] API: Out-of-Session (Authentication credentials were not provided.).

[!] Aborting...

@uday-nandam
Copy link

After these steps I am getting the following error:

[-] Successfully authenticated.
[*] Retrieving book info...
[#] API: Out-of-Session (Authentication credentials were not provided.).
[!] Aborting...

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

I was able to get it to work when I used the above cookies.json file

@vinayakg
Copy link

vinayakg commented Apr 2, 2020

This is what worked in Firefox.

  1. As @dkuzma2 mentioned, In the browser console run:
    var output = {};document.cookie.split(/\s*;\s*/).forEach(function(pair) {pair = pair.split(/\s*=\s*/);output[pair[0]] = pair.splice(1).join('=');});console.log(JSON.stringify(output));
  2. Edit safaribooks.py and add a new line
    PROFILE_URL = "https://www.oreilly.com/member/"
    right below the line
    PROFILE_URL = SAFARI_BASE_URL + "/profile/"
  3. Run
    python3 safaribooks.py <BOOKID>

Works in Microsoft Edge as well Version 80.0.361.69 (Official build) (64-bit).

@antoineco antoineco mentioned this issue Apr 11, 2020
@rda3mon
Copy link

rda3mon commented Jun 26, 2020

This no longer works. Just use one of the api calls from browser network activity to take cookie and convert into json and place it in cookies.json file. That should work.

@brunoscota
Copy link

This no longer works. Just use one of the api calls from browser network activity to take cookie and convert into json and place it in cookies.json file. That should work.

for me also is not working anymore. Now I need to copy the cookie mannually via browser

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

No branches or pull requests