Question

I am testing scribe for facebook authentication. I am not receiving the oauth_verifier when authenticating against facebook - let me know if this is incorrect behavior. For facebook auth, how should I go about creating the verifier in order to create the OAuthRequest.

 redirect_uri=http%3A%2F%2Flocalhost%2Foauth%2Ffacebook

Thanks

Was it helpful?

Solution

LoginServlet:

public void doGet(HttpServletRequest req, HttpServletResponse res) {
    OAuthService service = new ServiceBuilder().provider(FacebookApi.class).apiKey(FACEBBOK_APP_KEY)
.apiSecret(FACEBOOK_APP_SECRET).callback(FACEBOOK_CALLBACK);
    String authenticationUrl = service.getAuthorizationUrl(null);
    res.sendRedirect(authenticationUrl);
}

CallbackServlet:

public void doGet(HttpServletRequest req, HttpServletResponse res) {
    String code = "";
    Enumeration paramEnum = req.getParameterNames();
    while (paramEnum.hasMoreElements()) {
    String name = (String) paramEnum.nextElement();
    if (name.equals("code")) {
        code = req.getParameter(name);
    }

    OAuthService service = new ServiceBuilder().provider(FacebookApi.class).apiKey(FACEBBOK_APP_KEY)
.apiSecret(FACEBOOK_APP_SECRET).callback(FACEBOOK_CALLBACK);
    Verifier verifier = new Verifier(code);
    //....
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top