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

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

Closed
bernatfortet opened this issue Jan 31, 2015 · 6 comments
Closed

Comments

@bernatfortet
Copy link

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
Copy link
Member

pscanf commented Jan 31, 2015

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. 😃

Cheers

@bernatfortet
Copy link
Author

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
Copy link
Member

pscanf commented Jan 31, 2015

I may have figured it out. 😃

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. 😄

Cheers

@bernatfortet
Copy link
Author

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
Copy link
Member

pscanf commented Jan 31, 2015

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

@pscanf pscanf closed this as completed Jan 31, 2015
@bernatfortet
Copy link
Author

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
        )

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

2 participants