Skip to content

authData:facebook vs _auth_data_facebook? #755

Description

@michaelbina

Before migrating to parse-server on heroku, all of the Facebook auth data was stored in the authData field for a User object like so:

    "authData": {
        "facebook":  {
            "id": "10104620262907903",
            "access_token": "...",
            "expiration_date": "4001-01-01T00:00:00.000Z"
        },
    }

After migrating, I am seeing the field _auth_data_facebook like so:

    "_auth_data_facebook": {
        "id": "10104620262907903",
        "access_token": "...",
        "expiration_date": "4001-01-01T00:00:00.000Z"
    },

First, why was this changed?

Second, I am having problems accessing the _auth_data_facebook from Parse Cloud.

A search for a user in parse cloud, returns the user object without the _auth_data_facebook field and with the facebook field in authData set to nil. Also my call to Parse.FacebookUtils.isLinked(user) returns false even thought its true and I have no way to retrieve the access token from the user object.

Any help would be appreciated in figuring out what I'm doing wrong or if this is a bug. Thanks!

Activity

  1. michaelbina commented on Mar 2, 2016

    @michaelbina
    Author

    Looks like the change was made in this pull: #310 by @flessard

  2. flovilmart commented on Mar 6, 2016

    @flovilmart
    Contributor

    If you see the field in MongoDB that's totally normal, the auth data gets flatten for performance reasons. Can you properly login with Facebook?

  3. michaelbina commented on Mar 7, 2016

    @michaelbina
    Author

    I can properly login, yes, but it's causing the other problems I mentioned, namely an invalid value for Parse.FacebookUtils.isLinked(user) and the ability to get the token from Parse Cloud. Any thoughts on those problems?

  4. gfosco commented on Mar 7, 2016

    @gfosco
    Contributor

    Can you provide the code you're using in cloud code?

  5. michaelbina commented on Mar 7, 2016

    @michaelbina
    Author

    Coffeescript:

      user.get(userObjectId).then((user) ->
        console.log 'UserID: ' + user.id
        if Parse.FacebookUtils.isLinked(user)
          console.log 'token:' + user.get('authData').facebook.access_token
    

    The second console is what would have gotten me the token before but doesn't work anymore.

  6. gfosco commented on Mar 7, 2016

    @gfosco
    Contributor

    Instead of Parse.FacebookUtils, do you get the right result if you query with the master key and check the authData key directly?

    user.get(userObjectId, { useMasterKey: true }).then((user) ->
      if user.get('authData') && user.get('authData').facebook
        console.log user.get('authData').facebook.access_token
  7. michaelbina commented on Mar 7, 2016

    @michaelbina
    Author

    That does not solve it (I posted old code and was already calling useMasterKey).

    Even when the user is connected to Facebook, the authData field is showing up like this:

    "authData":{"facebook":null}

    When I check mongo directly, I see the data is being stored in the "_auth_data_facebook" field and I don't seem to have any way to access that field as it's not showing up in the returned user object.

  8. DrBeak1 commented on Mar 7, 2016

    @DrBeak1

    I may be experiencing a related issue. When I log in with facebook, it creates a new user every time and that user cannot be modified; for example, if I try to update the username it reverts back to the random string provided by facebook. If I log out then back in with the same facebook account, it generates a brand new user, brand new random string.

    ** EDIT **
    Actually, this may have been related to a beforeSave that I had in place. Still investigating, but won't hijack your thread with a separate issue if it turns out that way.

  9. flovilmart commented on Mar 7, 2016

    @flovilmart
    Contributor

    @michaelbina in your code, user.get(userObjectId) does that refers to a userQuery?

    Is the user currently logged in?
    Can you share more of that snipet so we have more context?

  10. michaelbina commented on Mar 7, 2016

    @michaelbina
    Author

    Yes. It's a Parse.Query(Parse.User) object. I'm not sure it should make a difference if the user is logged in since it's running from cloud code. Should I be doing something with a session token or something to get more user data or something? Here's the entire function:

    Parse.Cloud.afterSave "AnimalTimelineEntry", (request, response) ->
      console.log("timeline entry created: " + JSON.stringify(request))
      console.log("shareToFacebook: " + request.object.get("shareToFacebook"))
      console.log("shareToTwitter: " + request.object.get("shareToTwitter"))
    
      if(request.object.get("shareToFacebook"))
        console.log("sharing to Facebook for: " + request.object.get("createdBy").id)
        userObjectId = request.object.get("createdBy").id
        entryText = request.object.get("text")
    
        userQuery = new Parse.Query(Parse.User)
        userQuery.get(userObjectId,
          useMasterKey: true
        ).then((user) ->
          console.log 'User: ' + JSON.stringify(user)
          # if Parse.FacebookUtils.isLinked(user)
    
          # if user.get('_auth_data_facebook')
          #   console.log 'token:' + user.get('_auth_data_facebook').access_token
    
          if user.get('authData') && user.get('authData').facebook
            console.log 'token: ' + user.get('authData').facebook.access_token
    
            Parse.Cloud.httpRequest(
              method: 'POST'
              url: 'https://graph.facebook.com/me/feed'
              params:
                access_token: user.get('authData').facebook.access_token
                message: entryText + "\n\nCheck out Phoebe on White Rabbit Apps"
                link: "http://www.whiterabbitapps.net/cat/phoebe_the_bug"
            ).then ((httpResponse) ->
              console.log("back from http request")
            ), (error) ->
              console.log("error with http request: " + error.data.error.message)
              return response.error(error.data.error.message)
          else
            return Parse.Promise.error('user not linked to fb account')
          return
        ).then ((result) ->
          console.log "result from post: " + JSON.stringify(result)
          return response.success 'Post'
        ), (error) ->
          console.log error
          console.error error
          return response.error("Error posting")
        return
    
  11. flovilmart commented on Mar 11, 2016

    @flovilmart
    Contributor

    This should be fixed by #952

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions