Parse Google plus login
我正在使用Parse,用户可以在其中使用Facebook,Twitter和Google登录。截至目前,只有Facebook和Twitter可以正常使用。
我已经设法通过以下方式使用Facebook和Twitter登录:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | 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(); } } }); } |
我正在尝试通过解析与Google达成此目标。有人建议我研究Parse Rest API,但是我不熟悉它,需要更多指导。
任何澄清将不胜感激。
按此:
http://blog.parse.com/announcements/adding-third-party-authentication-to-your-web-app/
和这个:
https://parse.com/tutorials/adding-third-party-authentication-to-your-web-app
我对它们的理解
在使用Google / Github / Whatever成功登录后,您只需在应用或您的云/后端中使用某种算法生成密码
一个Simeple实施(但不能确保将其包含在您的应用中):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | // given Google Plus login (Using their Api) i.e. 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 protected]"); 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 } } }); |
此解决方案的重要事项:
仅根据您的应用程序中的ID使用ID /密码是不安全的,更好的解决方案是将Google令牌/ UserId发送到后端/云,然后后端/云会验证该令牌/ ID是有效的,然后从中创建用户名/密码,并与"解析用户"进行交换。
我希望你有主意。