mondora / asteroid

An alternative client for a Meteor backend
MIT License
734 stars 101 forks source link

Chrome Extension + Twitter Login. Try to login everytime I ophen Chrome #41

Closed bernatfortet closed 9 years ago

bernatfortet commented 9 years ago

Hi!

I've created a Chrome Extension, basically a background page that listens to a browser action (pressing on the extension icon). When that happens it send information about the page to the Meteor Backend.

The problem relies in the fact that everytime I open Chrome the background page logs in with twitter and opens a new tab in the browser.

Is there a way to do the login process in the backround? Or maybe store the credentials?

Am I explaining myself properly?

Thanks!

pscanf commented 9 years ago

Yes, I think you have a similar problem as @foobarbecue in issue #30 . Take a look at this example, and also make sure to add the mondora:asteroid package to your meteor server.

If you still have issues, we can schedule a hangout and see if we can solve them. :smiley:

Cheers

bernatfortet commented 9 years ago

I should have mentioned. I went through thtat thread.

  1. Added mandora:asteroid
  2. set ALLOWED_ORIGIN on env variables
  3. Added "storage' permision to the xtension
  4. I'm waiting for service configuration to be ready:
        this.ddp.on('connected', =>
            console.log 'Connected'

            this.ddp.subscribe("meteor.loginServiceConfiguration").ready.then =>
                this.ddp.loginWithTwitter()
        )

        this.ddp.on('login', (loggedInUserId) =>
            console.log 'Logged, userId:', loggedInUserId
            this.userId = loggedInUserId
        )

I think I've tried everything I could understand from issue #30 and examples.

I'd love to schedule a hangout. Thanks!

pscanf commented 9 years ago

I may have figured it out. :smiley:

First of all, I'm assuming this.ddp is your asteroid instance. Said that, each time you call loginWithXXX (in this case Twitter), Asteroid opens the popup and starts the oauth dance. After the dance has finished, Asteroid stores a session token in localStorage (or, in case of chrome extensions, in chrome.storage.local). When an instance of Asteroid is created, it automatically attempts to resume a previous session if a token is found in localStorage. Therefore, after logging in once via twitter, the next time the background tab reloads it'll automatically login, and there is no need to call loginWithTwitter again.

Hope this clears things up. If not, feel free to schedule a hangout, when I'm not asleep I'm more or less always available. :smile:

Cheers

bernatfortet commented 9 years ago

Hey @pscanf,

  1. yes this.ddp is the asteroid instance.
  2. I guessed exactly what you are mentioning, but I guess asteroid is not able to store locally?
  3. This is the repo: https://github.com/bernatfortet/vessel/blob/master/app/scripts/background.coffee
  4. I'll be connected for the next hour +- could you join this hanghout? https://plus.google.com/hangouts/_/gut5gpbqf7d6avbnudrbxc7uwea?hl=en
pscanf commented 9 years ago

Closing issue post-hangout. :-) Reopen if needed.

bernatfortet commented 9 years ago

For future reference:

    connectToMeteor: ->
        this.ddp = new Asteroid("localhost:3000");

        this.ddp.on('connected', =>
            console.log 'Connected'

            this.ddp.resumeLoginPromise.then( ->
                console.log ('user is already logged in')
            ).fail( ->
                    this.ddp.subscribe("meteor.loginServiceConfiguration").ready.then =>
                       this.ddp.loginWithTwitter()
            )

        )

        this.ddp.on('login', (loggedInUserId) =>
            console.log 'Logged, userId:', loggedInUserId
            this.userId = loggedInUserId
        )