Search in sources :

Example 1 with UserInfoClient

use of org.xdi.oxauth.client.UserInfoClient in project oxAuth by GluuFederation.

the class UserInfoAction method exec.

public void exec() {
    try {
        UserInfoRequest request = new UserInfoRequest(accessToken);
        request.setAuthorizationMethod(authorizationMethod);
        UserInfoClient client = new UserInfoClient(userInfoEndpoint);
        client.setRequest(request);
        client.exec();
        showResults = true;
        requestString = client.getRequestAsString();
        responseString = client.getResponseAsString();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : UserInfoRequest(org.xdi.oxauth.client.UserInfoRequest) UserInfoClient(org.xdi.oxauth.client.UserInfoClient)

Example 2 with UserInfoClient

use of org.xdi.oxauth.client.UserInfoClient in project oxAuth by GluuFederation.

the class RpDemoServlet method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    try {
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter pw = resp.getWriter();
        pw.println("<h1>RP Demo</h1>");
        pw.println("<br/><br/>");
        String accessToken = (String) req.getSession().getAttribute("access_token");
        String userInfoEndpoint = (String) req.getSession().getAttribute("userinfo_endpoint");
        LOG.trace("access_token: " + accessToken + ", userinfo_endpoint: " + userInfoEndpoint);
        UserInfoClient userInfoClient = new UserInfoClient(userInfoEndpoint);
        userInfoClient.setExecutor(Utils.createTrustAllExecutor());
        UserInfoResponse response = userInfoClient.execUserInfo(accessToken);
        LOG.trace("UserInfo response: " + response);
        if (response.getStatus() != 200) {
            pw.print("Failed to fetch user info claims");
            return;
        }
        pw.println("<h2>User Info Claims:</h2>");
        pw.println("<br/>");
        for (Map.Entry<String, List<String>> entry : response.getClaims().entrySet()) {
            pw.print("Name: " + entry.getKey() + " Value: " + entry.getValue());
            pw.println("<br/>");
        }
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
}
Also used : List(java.util.List) UserInfoResponse(org.xdi.oxauth.client.UserInfoResponse) Map(java.util.Map) UserInfoClient(org.xdi.oxauth.client.UserInfoClient) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Aggregations

UserInfoClient (org.xdi.oxauth.client.UserInfoClient)2 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 List (java.util.List)1 Map (java.util.Map)1 ServletException (javax.servlet.ServletException)1 UserInfoRequest (org.xdi.oxauth.client.UserInfoRequest)1 UserInfoResponse (org.xdi.oxauth.client.UserInfoResponse)1