meteor icon indicating copy to clipboard operation
meteor copied to clipboard

Cannot use Twitter Oauth with Redirect due to "Ignoring Unexpected Duplicate..." error.

Open adrian-quince opened this issue 10 years ago • 10 comments

I have an app that stores Oauth credentials separately from user accounts to allow the system to store multiple Oauth tokens for the same user. (For example, to allow the app to post to multiple Twitter accounts.)

I am retrieving the credentials using the Twitter.requestCredential function. When using this function with a loginStyle of popup, as shown here, everything works as expected.

Client:

Twitter.requestCredential(function (credentialToken, error) {
    if (error) {
        console.log(error)
    } else {
        console.log(credentialToken)
        var credentialSecret = OAuth._retrieveCredentialSecret(credentialToken)

        // Meteor call that saves the new credential to my Identities table

        Meteor.call("saveNewTwitterCredential", credentialToken, credentialSecret, function(error, response) {
            if (error) {
                // console.log(error)
            } else if (response) {

                // Code that handles the response.

            } else {
                // console.log("No Error or Response from method.")
            }
        });
    }
});

Server:

Meteor.methods({
    saveNewTwitterCredential: function (credentialToken, credentialSecret) {
        var cred = Twitter.retrieveCredential(credentialToken, credentialSecret)

        if (cred) {

            if (Meteor.user()) {
                cred.userID = Meteor.user()._id
            }
            cred.serviceUserID = cred.serviceData.id

            // remove old credentials. When building support for multiples, add serviceUserId to this query
            acIdentities.remove({
                "serviceName": cred.serviceName, 
                "userID": cred.userID})

            var response = acIdentities.insert(cred)

            return response;
        } else {
            throw new Meteor.Error("No-Twitter-Login", "Could not log in to Twitter.")
        }
    }
});

When I change the loginStyle to redirect, I get an error "Ignoring unexpected duplicate page load login attempt info" that is stopping the execution of my client-side javascript. This indicates that the Accounts package is being called on the redirect back to the app. There is zero documentation around using the standalone Twitter package (introduced in 0.6.4) with a redirect, so I can't figure out how to:

  1. Prevent this error from occurring
  2. Get the redirect to work without attempting a login

Can someone familiar with this component please provide a doc update around this?

adrian-quince avatar Jan 20 '16 23:01 adrian-quince

I think this is related: https://github.com/meteor/meteor/issues/3621

rjakobsson avatar Jan 21 '16 13:01 rjakobsson

When doing this, but for the Facebook package I get null back from the var credentialSecret = OAuth._retrieveCredentialSecret(credentialToken) on client. Have you had any issues like this?

rjakobsson avatar Jan 21 '16 14:01 rjakobsson

Hi rjakobsson, the same pattern works fine for both Facebook and Twitter with a login style of popup. My concern is specifically around login style of redirect, where I'm hitting an error message related to Meteor Accounts when I'm specifically trying to use the standalone Oauth packages while not interacting with Meteor Accounts.

adrian-quince avatar Jan 21 '16 18:01 adrian-quince

@adrian-quince thanks for the bug report. I think you'll need to provide a little more info and perhaps we can debug exactly what's going on here:

Please provide a full reproduction as described in: https://github.com/meteor/meteor/wiki/Contributing-to-Meteor#reporting-a-bug-in-meteor

Specifically do you have the accounts-twitter package added to your app? This would automatically handle the redirect and break the flow you are trying to create I think.

tmeasday avatar Feb 02 '16 23:02 tmeasday

@adrian-quince i've also encountered this problem. have you made any headway with this?

i was able to track it down to an instance where my colleague had a chrome extension called hola (a free vpn extension) enabled.

with hola enabled, the DDP console showed that the connect method was being called with a null value for oauth.credentialSecret. when hola was disabled, oauth.credentialSecret had a valid string value and the login worked.

that said, i've also had users tell me that it works fine unless they disable their skype chrome extension, or adblock, and some tell me it only happens when going through their "work vpn". i find it difficult to believe that random chrome extensions are responsible for the null oauth.credentialSecret value.

just like @adrian-quince mentioned earlier this is

... specifically around login style of redirect...

could this be because the app set up at twitter and/or facebook is told to redirect back to the same uri that launched the request? i have not investigated this yet, but it is my next step.

rkstar avatar Feb 22 '16 19:02 rkstar

Hi, I'm having the same issue!

I had to switch to loginStyle: 'redirect' in order to get the login flow to work on some ios devices.

But it seem to break anyway. I'm redirected to the correct link but Meteor does not login the user: http://localhost:3000/_oauth/facebook?code={{ code }}

marcus13371337 avatar Mar 10 '16 19:03 marcus13371337

Having the same issue. Anybody come up with a solution?

kodie avatar Jul 11 '16 16:07 kodie

Same here =S

rubenlpz avatar Jul 16 '16 18:07 rubenlpz

As part of the on-going old issue cleanup process, I'll close this issue for now. If anyone is still having this problem, please post back with a runnable reproduction showing the issue, and we'll re-open. Just a quick heads up - all accounts external services packages are in the process of being split up, so the oauth code is separated out from the Blaze code (see #7715 - these changes are currently slotted for release 1.4.3). Thanks for posting this originally!

hwillson avatar Jan 31 '17 19:01 hwillson

I'm trying to implement a similar service to oauth and I suspect the issue is something along these lines:

  1. Meteor.loginWith is called only if user is not logged in (probably checking Meteor.userId()).
  2. When redirected, Accounts.callLoginMethod is called on Meteor.startup, after that server takes some time to login and send id back to the client, meanwhile user checks Meteor.userId() again to login but the client hasn't received it yet, so it attempts to login again.
  3. This time when redirected back, user is logged in, so Meteor.userId() doens't return null.

The error message has something to do with Accounts._pageLoadLogin, not sure what, but it isn't causing this "double redirect" issue.

Sakerdot avatar Oct 09 '17 21:10 Sakerdot