我正在使用 SCRIBE 库在我的应用程序中启用Facebook连接登录。我的问题是,在每次点击登录按钮登录并获取access_token后,我都是在未经授权的情况下登录,因为我已登录Facebook并且access_token仍处于活动状态。有没有办法强制Facebook退出或每次都要问我新的access_token,用cookie或使用connect.facebook.net/en_US/all.js或者在某些时候重定向它是一个好主意到https://www.facebook.com/logout.php?access_token=appId&confirm=1&next=http://localhost:8080/。我知道有很多关于这个主题的问题,但所有这些和建议的解决方案让我感到困惑。这是托管bean中的post post构造方法,用于处理Facebook响应。
@PostConstruct public void init(){ FacesContext context = FacesContext.getCurrentInstance(); HttpServletRequest req =(HttpServletRequest)上下文 。.getExternalContext()Request()方法;
responseCode = req.getParameter("code");
System.out.println("The code is: "+responseCode);
//facebook data
final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/me";
final Token EMPTY_TOKEN = null;
String apiKey = "MY_API_KEY";
String apiSecret = "MY_API_SECRET";
String callbackUrl="the-redirect_page_in_my_application";
OAuthService service = new ServiceBuilder().provider(FacebookApi.class)
.apiKey(apiKey).apiSecret(apiSecret)
//.scope(SCOPE)
.callback(callbackUrl).build();
//get authorization Url
String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
Verifier v=new Verifier(responseCode);
Token accessToken = service.getAccessToken(EMPTY_TOKEN, v);
// Now let's go and ask for a protected resource!
OAuthRequest request = new OAuthRequest(Verb.GET,
PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
Response response = request.send();
Gson gson = new GsonBuilder().create();
FacebookUser faceUser = gson.fromJson(response.getBody(), FacebookUser.class);
setUserName(faceUser.getName());
setUserFacebook(faceUser.getUsername());
setGender(faceUser.getGender());
FacesContext.getCurrentInstance().responseComplete();
}
答案 0 :(得分:0)
您有多种选择: