Giter Site home page Giter Site logo

Comments (11)

gamelaster avatar gamelaster commented on June 1, 2024 1

@keshavkaul
In all request is used an "parseAndCheckLogin", so If your cookies expired, all requests throw exception "You are not logged in!"
https://github.com/Schmavery/facebook-chat-api/blob/master/utils.js#L542

from facebook-chat-api.

markhughes avatar markhughes commented on June 1, 2024

screenshot 2015-07-17 22 48 33

Yeah I think I will! Here are some ideas I'm gonna go with.

  • Allow passing cookie to login along with email and password (email and password is fallback if cookie expires/crumbles)
  • Add option to enable storing cookies in a cache (cookiecache.json) so when we login with an email and password, we'll first check the cache for for their email and password

Thoughts?

from facebook-chat-api.

bsansouci avatar bsansouci commented on June 1, 2024

I think this is a good idea. You should check how request's cookie jars work (they are the same as tough-cookie).
I think cookie as a string is better than forcing the user to figure out how cookie jars work. It's an implementation detail that they shouldn't have to worry about. The downside is that we have to handle parsing the cookie and checking for errors.

I'm not a huge fan of having this API handle storing the cookies in a jar. We did this for login before and it was a huge mess because we couldn't handle all the possible ways of load the credentials. I like to think that keeping the API surface as small as possible will guarantee the max power to the user while keeping it usable and maintainable.
I think I'd rather simply have a getter for the cookies (maybe it returns an array of cookies).

What do you think?

from facebook-chat-api.

markhughes avatar markhughes commented on June 1, 2024

I guess that way if the user wanted to create a cache of sessions they could do it themselves which is probably better.

So are you still saying we can allow loading a preexisting session? This is my main issue.

from facebook-chat-api.

bsansouci avatar bsansouci commented on June 1, 2024

Yes. I'm saying add two things:

  • a setter, potentially just another field inside the object given to login contains a properly formatted string of a cookie. I can't think of a better solution, but a formatted string is very loose in this case. By that I mean that any typo will just make the whole thing throw which kind of sucks, but I'm in favor of simplicity. So I think the format of the string should be the one you get from copy pasting cookies from Chrome (basically the most used way of getting cookies). What do you think @Schmavery?
  • a getter, something like api.getCookies which would do https://github.com/SalesforceEng/tough-cookie#getcookiessynccurrenturl-options and then map over the array and call toString on it

from facebook-chat-api.

markhughes avatar markhughes commented on June 1, 2024

This sounds good to me! We'll just wait for some feedback.

from facebook-chat-api.

markhughes avatar markhughes commented on June 1, 2024

I've been thinking, we should priorities cookies in the login function. If the cookie fails to login, we can fallback to the users email and password. For example:

login({ cookie: "COOKIE_DATA", email: "FB_EMAIL",  password: "FB_PASSWORD" }, function callback (err, api) {
    // .. do stuff <3 
});

So if the cookie expired, or the session had been ended we would revert back to the email and password.

What're your thoughts on this @bsansouci and @Schmavery?

I'm really in need of this, so I'm going to write this up!

from facebook-chat-api.

Schmavery avatar Schmavery commented on June 1, 2024

I'm fine with this format personally. Login is currently one of the spaghettiest pieces of code left in the project, so we'll have to be careful not to break anything. Thoughts @bsansouci?

from facebook-chat-api.

bsansouci avatar bsansouci commented on June 1, 2024

@markehme don't do a PR, we have some ideas and need to untangle the code a little. The idea would be to serialize the whole app state (including userId, clients, access_token etc..), not just the cookies. Then you can get it with something like api.getAppState and do fs.writeFile("cache.json", JSON.stringify(api.getAppState())) before quitting.
Then you would login like

var appState = fs.readFileSync("cache.json", "utf8");

login({ appState: appState, email: "FB_EMAIL",  password: "FB_PASSWORD" }, function callback (err, api) {
    // .. do stuff <3 
});

Do you think that would be enough?

from facebook-chat-api.

markhughes avatar markhughes commented on June 1, 2024

That sounds good to me.

from facebook-chat-api.

keshavkaul avatar keshavkaul commented on June 1, 2024

@Schmavery @bsansouci
Is there anyway to know if cookie login failed due to expired cookies? Do i get an error callback if login by cookie fails? I'm trying to login with only cookies.

from facebook-chat-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.