如何获取通过 OAuth io 记录的当前用户详细信息 [英] How to get current user details logged through OAuth io

查看:58
本文介绍了如何获取通过 OAuth io 记录的当前用户详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个用户可以通过 google 和 twitter 登录的网页.我决定使用 OAuth.io 并且我成功地为 google 配置了 OAuth.io.成功登录后,我将用户重定向到 TestServlet.一旦控件到达 servlet,我不确定如何获取用户详细信息.

I am trying to create a webpage on which user can log in through google and twitter. I have decided to use OAuth.io and I am successful configuring OAuth.io for google. After successful logging, I redirect the user to the TestServlet. I am not sure how to get user details once the control reaches to servlet.

任何帮助将不胜感激.

推荐答案

你可以在你的 javascript 中使用 OAuth.callback 和 OAuth.redirect(如果这是你正在使用的).

you can use OAuth.callback in pair with OAuth.redirect (if that is what you are using) in your javascript.

您可以从客户端或服务器端获取您的用户详细信息.

You can either get your user details from client side or server side.

例如

OAuth.redirect('google', "/test");

在/test:

OAuth.callback('facebook', function(err, result) {
  // the oauth token is in result.access_token
  result.get("/oauth2/v1/userinfo", function(data) { // or /plus/v1/people/me
    alert('Hello ' + data.displayName)
  });
});

如果您打算从服务器端进行 api 调用,在 Java 中,您可以将令牌(或代码)传递到您的服务器,然后使用 google java api(构建 GoogleCredential)或直接 http 调用

if you are planning to do the api call from server-side, in java, you can pass the token (or code) to your server and either use the google java api (building a GoogleCredential) or direct http calls

这篇关于如何获取通过 OAuth io 记录的当前用户详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆