Parse Google Plus Login

I use Parse, where users can connect to Facebook, Twitter and Google+. At the moment, only Facebook and Twitter are fully operational.

I managed to log in using Facebook and Twitter as follows:

private void onLoginButtonClicked() { LoginActivity.this.progressDialog = ProgressDialog.show( LoginActivity.this, "", "Logging in...", true); List<String> permissions = Arrays.asList("public_profile", "user_about_me", "user_relationships", "user_birthday", "user_location"); ParseFacebookUtils.logIn(permissions, this, new LogInCallback() { @Override public void done(ParseUser user, ParseException err) { LoginActivity.this.progressDialog.dismiss(); if (user == null) { Log.d(IntegratingFacebookTutorialApplication.TAG, "Uh oh. The user cancelled the Facebook login."); } else if (user.isNew()) { Log.d(IntegratingFacebookTutorialApplication.TAG, "User signed up and logged in through Facebook!"); showUserDetailsActivity(); } else { Log.d(IntegratingFacebookTutorialApplication.TAG, "User logged in through Facebook!"); moodpage(); } } }); } private void onTwitterButtonClicked() { ParseTwitterUtils.logIn(this, new LogInCallback() { @Override public void done(ParseUser user, ParseException err) { if (user == null) { Log.d("MyApp", "Uh oh. The user cancelled the Twitter login."); } else if (user.isNew()) { Log.d("MyApp", "User signed up and logged in through Twitter!"); showUserDetailsActivity(); } else { Log.d("MyApp", "User logged in through Twitter!"); moodpage(); } } }); } 

I'm trying to figure out how to do this using Google+. Someone suggested I look into the Parse Rest API, but I am not familiar with it and need more detailed recommendations.

Any clarification would be appreciated.

+5
source share
1 answer

regarding this:

http://blog.parse.com/announcements/adding-third-party-authentication-to-your-web-app/

and this:

https://parse.com/tutorials/adding-third-party-authentication-to-your-web-app

And my understanding of them

You just need to generate a password using some algorithm in your application or cloud / backend, after successfully logging in to Google + / Github / Whatever

simeple implementation (but it is not protected to have it in your application):

 // given Google Plus login (Using their Api) ie no Parse yet at this point int id = 12345; // assume that this is google+ id (After successfully logging in) ParseUser user = new ParseUser(); user.setUsername("google-plus-" + String.valueOf(id)); user.setPassword(hashMyPassword(id)); // Create password based on the id user.setEmail(" email.from.google.plus.login@gmail.com "); user.signUpInBackground(new SignUpCallback() { public void done(ParseException e) { if (e == null) { // Hooray! Let them use the app now. } else { // Sign up didn't succeed. Look at the ParseException // to figure out what went wrong } } }); 

One important thing in this decision:

Failed to use id / password based on the identifier in your application, the best solution would be to send Google+ Token / UserId to backend / cloud, then Backend / Cloud checks that this token / identifier is valid, then create a username / password and exchange it with by user Parse.

Hope you have an idea.

0
source

Source: https://habr.com/ru/post/1204023/


All Articles