Skip to content

installationId is not set in _Session object when using 3rd party auth and signUp #1097

Closed

Description

@tanmays

I'm not sure if this causes any problem but I happened to notice that installationId seems to be missing in Session class when user logs in via Twitter (and possibly other oAuth methods)

I'm using the latest parse-server release v2.2.0.

Here's a screenshot:

Activity

  1. flovilmart commented on Mar 19, 2016

    @flovilmart
    Contributor

    @tanmays that would be related to the SDK not sending the X-Parse-Installation-Id header when logging in with twitter. Can you start your server with VERBOSE=1 and get me the logs that are printed when doing a twitter login? I'd be able to see if the headers are properly set, and in that case, tweak the implementation to properly set the installation ID. If the headers is not correctly set, that would be an error in the SDK you're using.

  2. tanmays commented on Mar 19, 2016

    @tanmays
    Author

    @flovilmart thanks! I'm not actually using any SDK for mobile apps but have all custom cloud code methods. I'll try passing installation token and get back. Thanks!

  3. tanmays commented on Mar 19, 2016

    @tanmays
    Author

    @flovilmart just checked and I'm using the REST api to login via Twitter. Here's the request:

    POST /parse/users/ { host: 'xxxxxx.ngrok.io',
      'content-type': 'application/json',
      'content-length': '317',
      accept: '*/*',
      'user-agent': 'MyApp/0.2 (iPhone; iOS 9.2.1; Scale/2.00)',
      'x-parse-application-id': 'xxx',
      'accept-language': 'en-IN;q=1',
      'accept-encoding': 'gzip, deflate',
      'x-forwarded-proto': 'https',
      'x-forwarded-for': '120.88.xx.xx' } {
      "authData": {
        "twitter": {
          "auth_token": "2769664194-xxxx",
          "id": "2769664194",
          "screen_name": "xxx",
          "consumer_key": "xxx",
          "consumer_secret": "xxx",
          "auth_token_secret": "xxx"
        }
      }
    }
    

    This returns a proper user object and everything works fine except the installationId field is still empty in Session class. I'm not sure how I'd pass an installationId in header before login, I guess that id is generated by parse-server.

  4. flovilmart commented on Mar 19, 2016

    @flovilmart
    Contributor

    the installation-id is indeed generated by the client. you should be able to get it from PFInstallation.currentInstallation and add it to your headers

  5. tanmays commented on Mar 19, 2016

    @tanmays
    Author

    @flovilmart I run the twitter login method directly via a rest api call made from iPhone and doing this results in installationId being empty.

    I run the Parse.User.logIn method via Cloud Code. I do not pass any installation id in header while doing this and still it populates the installationId field on login via password. So I'm not sure how the installationId is generated in this case.

  6. tanmays commented on Mar 19, 2016

    @tanmays
    Author

    I just realised the installationId generated when logging in using a cloud code function is same even if actual devices making the cloud code request are different.

    I think I need to be able to pass in an installationId to the Parse.User.logIn method. Any tips on how to pass in a device UUID to this method when using cloud code?

    As for the Twitter login REST request, I passed in valid UUID in the header token and it still failed to add it to the installationId in Session class.

    Here's the request:

    POST /parse/users/ { host: 'xxx.ngrok.io',
      'content-type': 'application/json',
      accept: '*/*',
      'content-length': '317',
      'x-parse-installation-id': '950384ED-2F67-4DD3-85CB-69D95976CE4A',
      'user-agent': 'MyApp/0.2 (iPhone; iOS 9.2.1; Scale/2.00)',
      'x-parse-application-id': 'xx',
      'accept-language': 'en-IN;q=1',
      'accept-encoding': 'gzip, deflate',
      'x-forwarded-proto': 'https',
      'x-forwarded-for': '120.88.xxx.xx' } {
      "authData": {
        "twitter": {
          "auth_token": "2769664194-xxx",
          "id": "2769664194",
          "screen_name": "xxx",
          "consumer_key": "xxx",
          "consumer_secret": "xxx",
          "auth_token_secret": "xxx"
        }
      }
    }
    
  7. flovilmart commented on Mar 19, 2016

    @flovilmart
    Contributor

    That seems to be a bug, as the installationId is expected in the data you pass instead of the request.info.
    I don't think that causes any error for now, but I'll mark it as a bug

  8. added
    type:bugImpaired feature or lacking behavior that is likely assumed
    on Mar 19, 2016
  9. changed the title [-]InstallationId is empty in Session class for Twitter login[/-] [+]installationId is not set in _Session object when using 3rd party auth[/+] on Mar 19, 2016
  10. tanmays commented on Mar 19, 2016

    @tanmays
    Author

    @flovilmart Thanks! As for my earlier question is there any way I can manually pass a device UUID to a Parse.User.logIn method in cloud code?

  11. flovilmart commented on Mar 19, 2016

    @flovilmart
    Contributor

    you can pass any parameters when you call you cloud function from Parse.Cloud.run see: https://parse.com/docs/cloudcode/guide#cloud-code-cloud-functions

  12. tanmays commented on Mar 19, 2016

    @tanmays
    Author

    Yes but will that UUID be correctly added to the Session class? As I understand parse-server expects the installationId to be in a X-Parse-Installation-Id header. I'm not sure how to set headers when calling Parse.User.logIn from cloud code.

  13. flovilmart commented on Mar 19, 2016

    @flovilmart
    Contributor

    I'm not sure about that either. why would you want to perform logins in cloud code as it's precisely meant to be done on a client?

  14. tanmays commented on Mar 19, 2016

    @tanmays
    Author

    Two reasons I'm doing it in cloud code.

    1. Right now Parse.User.logIn requires you to pass in username and password. It doesn't support email in place of username or say phoneNo in place of username. Cloud code allows me to first fetch a username in case its an email/phoneNo and then log user in. This way is much cleaner than making multiple calls client side and then logging in with username.
    2. I need full pointer objects on login. Right now any pointers will not be returned in full. Using cloud code I can get all related pointer data in 1 request and client doesn't have to make additional unnecessary requests.
  15. flovilmart commented on Mar 19, 2016

    @flovilmart
    Contributor

    So for that question, I recommend you ask around in Stackoverflow as this is not related to parse-server but with a specific point of implementation

  16. tanmays commented on Mar 20, 2016

    @tanmays
    Author

    I figured it out.

    An update to the js sdk added ability to pass installationId.

    Here's a short guide if anyone else wants to do this:

    1. Make sure the js sdk version is at least 1.8.0.
      If you are using parse-server-example open package.json and edit value to "parse": "~1.8.1"
    2. Pass the device generated installationId as a parameter to the custom cloud code function you wrote.
    3. Pass in the installationIdto your cloud code's user.signUp and Parse.User.login methods.

    Sample cloud code function:

    Parse.Cloud.define("Login", function(request, response) {
    
        var installationId = request.params.installationId;
        ...other params
    
        Parse.User.logIn(username, password, {
            success: function(loggedInUser) {
            response.success(loggedInUser);
            },
            error: function(loggedInUser, error) {
              response.error(error);
            },
            "installationId":installationId
        });
    
    });
    
  17. tanmays commented on Mar 20, 2016

    @tanmays
    Author

    @flovilmart I was trying out the same with signUp and looks like its exhibiting the same behaviour with Session class as 3rd party auth.

    The installationId fails to get set in signUp method as well, probably because the /users/ endpoint is same for both regular register and 3rd party register so they seem to be related.

    Also the createdWith field is incorrectly populated as {"action":"login","authProvider":"password"} instead of {"action":"signup","authProvider":"password"}

    Here's a request just in case:

    POST /parse/users/ { host: 'xxx.ngrok.io',
      'content-type': 'application/json',
      'x-parse-installation-id': '614EA84F-DCEA-4836-9C2D-5BC7352ED9A8',
      'content-length': '87',
      accept: '*/*',
      'accept-language': 'en-us',
      'x-parse-application-id': 'xxx',
      'accept-encoding': 'gzip, deflate',
      'user-agent': 'CocoaRestClient/14 CFNetwork/760.2.6 Darwin/15.3.0 (x86_64)',
      'x-forwarded-for': '120.88.xxx.xx' } {
      "email": "test15@asda.com",
      "password": "tanmay",
      "fullName": "Test15",
      "username": "test15"
    }
    
  18. changed the title [-]installationId is not set in _Session object when using 3rd party auth[/-] [+]installationId is not set in _Session object when using 3rd party auth and signUp[/+] on Mar 20, 2016
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

    type:bugImpaired feature or lacking behavior that is likely assumed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions