【发布时间】:2016-01-18 15:02:46
【问题描述】:
谁能帮助我使用 OAuth2 对 Google Plus 进行身份验证?我可以让身份验证窗口显示、登录并使用我的帐户确认我的应用程序,但由于某种原因,操作事件从未被触发。我得到一个屏幕说请复制此代码,切换到您的应用程序并将其粘贴到那里。
如何让动作事件触发?
提前致谢。
编辑:
我的代码如下:
你好,谢谢你的回复,我的认证代码如下:
Oauth2 auth2 = new Oauth2("https://accounts.google.com/o/oauth2/auth", "Client_Id", "urn:ietf:wg:oauth:2.0:oob or http://localhost", "openid", "https://accounts.google.com/o/oauth2/token", "Client_Secret");
Oauth2.setBackToParent(true);
auth2.showAuthentication(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() instanceof String) {
String token = (String) evt.getSource();
String expires = Oauth2.getExpires();
GOOGLE_TOKEN = token;
System.out.println("recived a token " + token + " which expires on " + expires);
//store token for future queries.
} else {
Exception err = (Exception) evt.getSource();
err.printStackTrace();
Dialog.show("Error", "An error occurred while logging in: " + err, "OK", null);
}
}
});
“auth2.showAuthentication”运行良好,允许您通过用户授权应用程序,但一旦用户授权应用程序,“actionlistener”就不会被调用,我从来没有打过回调。如何强制回调触发以返回令牌?
【问题讨论】:
-
我不清楚您到底想做什么以及如何实现它。如果您提供一些关于您如何使用 Codename One 的其他信息,我认为 OAuth2 API 我们可能会为您提供帮助。
-
现在将跟进代码
-
这是:urn:ietf:wg:oauth:2.0:oob 还是 localhost 您使用的实际字符串?您在注册开发者密钥时定义了什么?您需要使用该 URL,因为 google 发送的重定向应该会将您发送到该位置
-
我可以同时使用两者,“urn:ietf:wg:oauth:2.0:oob”一旦完成就会在网页上显示身份验证令牌,但“localhost”应该返回并执行回调据我了解的方法。
-
您应该使用其中一个。其工作方式是 OAuth2 在完成后向该给定页面发送重定向,我们将您提供的地址与我们获得的地址进行比较。所以这需要非常准确,OAuth 才能正常工作。
标签: codenameone