Joh*_*ohn 5 java android android-layout android-activity parse-platform
我正在使用Parse,用户可以使用Facebook,Twitter和Google+登录.截至目前,只有Facebook和Twitter功能齐全.
我已设法通过以下方式使用Facebook和Twitter登录:
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(); }
}
});
}
Run Code Online (Sandbox Code Playgroud)
我试图通过解析来解决这个问题.有人建议我查看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 / 成功登录后,您只需要在应用程序或云/后端中使用某种算法生成密码
一个简单的实现(但将其放在您的应用程序中并不安全):
// 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.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
}
}
});
Run Code Online (Sandbox Code Playgroud)
该解决方案的一个重要事项是:
仅使用基于应用程序中的 ID 的 ID/密码是不安全的,更好的解决方案是将 Google+ 令牌/用户 ID 发送到后端/云,然后后端/云验证此令牌/ID 是否有效,然后创建用户名/密码,并与 Parse User 交换。
我希望你明白了。
| 归档时间: |
|
| 查看次数: |
1310 次 |
| 最近记录: |