Skip to content

Todo: Add Twitter login helper. #117

Closed

Description

@zEmily

Hello, now I need my customers login with twitter then add them as parse users.Because there is no function I can use as twitter logining in ParseUser.php, so I write one:

  public static function logInWithTwitter($id, $access_token, $expiration_date = null)
    {
        if (!$id) {
            throw new ParseException("Cannot log in twitter user without an id.");
        }
        if (!$access_token) {
            throw new ParseException(
                "Cannot log in twitter user without an access token."
            );
        }
        if (!$expiration_date) {
            $expiration_date = new \DateTime();
            $expiration_date->setTimestamp(time() + 86400 * 60);
        }
        $data = json_encode(['authData' =>
            ["twitter" => [
                "id" => $id, "access_token" => $access_token,
                "expiration_date" => ParseClient::getProperDateFormat($expiration_date)
            ]]
        ]);
        $result = ParseClient::_request("POST", "/1/users", "", $data);
        $user = new ParseUser();
        $user->_mergeAfterFetch($result);
        $user->handleSaveResult(true);
        ParseClient::getStorage()->set("user", $user);
        return $user;
    }

But when I finished login with twitter, error occurs: Code : 251 Message:Twitter credential verification failed.. I try to look for solutions, but all I found are things about apps platform problems, and they can fix if by setting consumerKey and consumerSecret in TWSignedRequest. But I don't know whether I need to set twitter consumerKey and consumerSecret, if I need to do this ,where should I set?

Activity

  1. zEmily commented on Jun 13, 2015

    @zEmily
    Author

    Right now I add customer key to parse settings, but the error also occurs .

  2. sherizan commented on Jun 13, 2015

    @sherizan

    I'm doing the longer method. Sign in via Facebook/Twitter, get his session fb, redirect to a new page, set password and set as a new user on Parse.

  3. zEmily commented on Jun 13, 2015

    @zEmily
    Author

    @sherizan I have found the right way to add twitter login user as parse user. You can check this https://parse.com/docs/rest/guide/#users-signup and search for twitter, you'll see this:

    {
      "twitter": {
        "id": "user's Twitter id number as a string",
        "screen_name": "user's Twitter screen name",
        "consumer_key": "your application's consumer key",
        "consumer_secret": "your application's consumer secret",
        "auth_token": "an authorized Twitter token for the user with your application",
        "auth_token_secret": "the secret associated with the auth_token"
      }
    }

    and it works!

  4. gfosco commented on Jun 15, 2015

    @gfosco
    Contributor

    Glad you figured out a way to do it using _request :) I'll leave this open though, because we should add a native method as we did for Facebook login.

  5. changed the title [-]Can I login with twitter then add the user to parse[/-] [+]Todo: Add Twitter login helper.[/+] on Jun 15, 2015
  6. raed667 commented on Jul 28, 2015

    @raed667

    +1

  7. murnieza commented on Jan 14, 2016

    @murnieza

    Any news on this one?

  8. talkaboutdesign commented on May 5, 2016

    @talkaboutdesign

    Anyone working on this?

  9. talkaboutdesign commented on May 18, 2016

    @talkaboutdesign

    Would be awesome if you can do this as part of the framework.

  10. raed667 commented on May 19, 2016

    @raed667

    @talkaboutdesign With everything going on with Parse, I wouldn't expect any updates.

  11. montymxb commented on Jan 13, 2017

    @montymxb
    Contributor

    Anyone still interested in this? I imagine we'll be putting this in at some point this year given that support for this (and many more alt logins) has been setup on Parse Server's end. I'm on the project as a maintainer so we can keep things moving along here after Parse shuts down.

  12. vferdiansyah commented on Mar 28, 2017

    @vferdiansyah
    Contributor

    Just submitted a PR #297 for this. Could you help review it @montymxb?

  13. montymxb commented on Mar 31, 2017

    @montymxb
    Contributor

    A twitter login helper has now been added to the sdk. In addition general purpose login/linker methods have been setup in ParseUser, this will allow us to add further 3rd party auths as needed.

    You can login/link with twitter as follows now:

    // login with twitter
    ParseUser::logInWithTwitter(
        'user_id',
        'screen_name',
        'consumer_key',
        'consumer_secret', // this is optional
        'auth_token',
        'auth_token_secret'
    );
    // **MAKE SURE your parse server has the 'auth' option 
    // properly configured for twitter auth to work **
    // vvv Check out the link below for info on this vvv
    // http://parseplatform.org/docs/parse-server/guide/#oauth-and-3rd-party-authentication
    
    
    // login or signup
    ParseUser::logIn('username', '************');
    
    // link the current user
    ParseUser::linkWithTwitter(
        'user_id',
        'screen_name',
        'consumer_key',
        'consumer_secret', // this is optional
        'auth_token',
        'auth_token_secret',
        $useMasterKey   // again optional, will default to false
    );

    Again here's a link for configuring 3rd party auth in parse server. Make sure to do this before you try to run twitter auth from the sdk.

    If there's a desire to add any additional auths be sure to open up an issue or a PR with the relevant additions and we'll take a look. You can find all of the current auth options within parse server here. Among them there are some auths such as github, google, instragram, linkedin, spotify and more.

    We'll probably look into adding these and more as time goes just for good measure, but be sure to let us know if you want to have these integrated sooner.

  14. flovilmart commented on Mar 31, 2017

    @flovilmart
    Contributor

    Awesome! I'm not sure you need to integrate them all now, as the server should be able to understand requests as long as the auth adapter is configured correctly on the other side.

  15. montymxb commented on Mar 31, 2017

    @montymxb
    Contributor

    @flovilmart we'll probably add them as demand requires, we should be good for now though. If anything I'm curious how the other sdks are keeping up with these new integrations. I also took the liberty of updating that last comment I left with some more details in regards to using 3rd party auth.

  16. flovilmart commented on Mar 31, 2017

    @flovilmart
    Contributor

    how the other sdks are keeping up with these new integrations

    we technically still need to make those methods public in the JS SDK, but the mechanisms are open on iOS.

  17. parse-github-assistant commented on Dec 6, 2021

    @parse-github-assistant

    The label type:feature cannot be used in combination with type:improvement.

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