开发者

Key in Request Token is null or blank- Brick red Social Auth

开发者 https://www.devze.com 2023-03-06 16:05 出处:网络
I need to import contacts to the enable my web app users to send invitation to his/her friends from my site, I am using SocioAuth Open source API to get this done, I have written 2 servlets to get thi

I need to import contacts to the enable my web app users to send invitation to his/her friends from my site, I am using SocioAuth Open source API to get this done, I have written 2 servlets to get this done I am pasting the code of my servlet. when I deployed the app in my Ec2 instance, I am getting an exception saying "Key in request token is null or blank in the line number 27 of the NewSocialAuthentication,

package com.auth.actions;

import java.io.IOException; import java.io.PrintWriter;

import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;

import org.brickred.socialauth.AuthProvider; import org.brickred.socialauth.AuthProviderFactory;

public class NewSocialAuthentication extends HttpServlet{

/**
 * 
 */
private static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    System.out.println("Coming to doGet of NewSocialApp..");
    @SuppressWarnings("unused")
    Pr开发者_StackOverflow社区intWriter out = response.getWriter();
    String socialAppId = request.getParameter("id");
    System.out.println("SocialAppId: "+socialAppId);
    AuthProvider provider;
    try {
        provider = AuthProviderFactory.getInstance(socialAppId);
        String returnToUrl = "http://ec2-50-19-118-108.compute-1.amazonaws.com/SocialAuthNew6/return";
        System.out.println("Return URL..." + returnToUrl);
        String urlString = provider.getLoginRedirectURL(returnToUrl);
        System.out.println("URLString: "+urlString);
        request.getSession().setAttribute("SocialAuth", provider);
        response.sendRedirect(response.encodeRedirectURL(urlString));
    } catch (Exception e) {
        System.out.println("Exception...");
        e.printStackTrace();
    }
}

}

package com.auth.actions;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.brickred.socialauth.AuthProvider;
import org.brickred.socialauth.Contact;
import org.brickred.socialauth.Profile;
import org.brickred.socialauth.util.*;

public class ReturnServlet extends HttpServlet{

    /**
     * 
     */


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("Coming to doGet of Return Servlet..");
        try{
            AuthProvider provider = (AuthProvider)request.getSession().getAttribute("SocialAuth");//this the line is rising exception 
            Profile p = provider.verifyResponse(request);
            System.out.println(p.getFirstName());
            List<Contact> contactsList = provider.getContactList();
            for(int i=0;i<contactsList.size();i++){
                response.setContentType("text/html");
                PrintWriter out = response.getWriter();
                System.out.println(contactsList.get(i).getFirstName()+" : "+contactsList.get(i).getLastName());
                out.println(contactsList.get(i).getFirstName());
                out.println(contactsList.get(i).getLastName());

            }
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }

}


This is the servlet which redirects to the email service provider

import java.io.IOException; import java.io.PrintWriter;

import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;

import org.brickred.socialauth.AuthProvider; import org.brickred.socialauth.AuthProviderFactory;

/** * Servlet implementation class NewSocialAuthentication */ public class NewSocialAuthentication extends HttpServlet { private static final long serialVersionUID = 1L;

/**
 * @see HttpServlet#HttpServlet()
 */
public NewSocialAuthentication() {
    super();
    // TODO Auto-generated constructor stub
}

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    @SuppressWarnings("unused")
    PrintWriter out = response.getWriter();
    String socialAppId = request.getParameter("id");
    System.out.println("SocialAppId: "+socialAppId);
    AuthProvider provider;
    try {
        provider = AuthProviderFactory.getInstance(socialAppId);
        //String returnToUrl = "http://ec2-50-16-183-101.compute-1.amazonaws.com/SocialAuthNew/return";

        String returnToUrl = "u r returning url ";

        System.out.println("Return URL..." + returnToUrl);
        String urlString = provider.getLoginRedirectURL(returnToUrl);
        System.out.println("URLString: "+urlString);
        request.getSession().setAttribute("SocialAuth", provider);
        response.sendRedirect(response.encodeRedirectURL(urlString));
    } catch (Exception e) {
        System.out.println("Exception...");
        e.printStackTrace();
    }
}

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
}

}

the return url would look like this I have embedded in the jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@page import="org.brickred.socialauth.AuthProvider" %> <%@page import="org.brickred.socialauth.Contact" %> <%@page import="org.brickred.socialauth.AuthProvider" %> <%@page import="org.brickred.socialauth.Profile" %> <%@page import="java.util.*" %> Insert title here

CONTACT LIST

<% try{ AuthProvider provider = (AuthProvider)request.getSession().getAttribute("SocialAuth"); try{ System.out.println(provider.getContactList()); } catch(Exception e){ System.out.println("Exception Encountered.."); } Profile p = provider.verifyResponse(request); List contactsList = provider.getContactList(); %>

Hello, <%= p.getFirstName() %>


Contact List

First Name Email <%
for(int i=0;i "/><%= contactsList.get(i).getFirstName() %><%= contactsList.get(i).getEmail() %> <% } %>

 </table>
 <input type="submit" value="GET CONTACTS"/>
 </form>

<%
} catch(Exception e){ e.printStackTrace(); } %>

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号