Java Code Examples for org.openid4java.consumer.VerificationResult#getAuthResponse()
The following examples show how to use
org.openid4java.consumer.VerificationResult#getAuthResponse() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConsumerServlet.java From openid4java with Apache License 2.0 | 4 votes |
public Identifier verifyResponse(HttpServletRequest httpReq) throws ServletException { try { // extract the parameters from the authentication response // (which comes in as a HTTP request from the OpenID provider) ParameterList response = new ParameterList(httpReq .getParameterMap()); // retrieve the previously stored discovery information DiscoveryInformation discovered = (DiscoveryInformation) httpReq .getSession().getAttribute("openid-disc"); // extract the receiving URL from the HTTP request StringBuffer receivingURL = httpReq.getRequestURL(); String queryString = httpReq.getQueryString(); if (queryString != null && queryString.length() > 0) receivingURL.append("?").append(httpReq.getQueryString()); // verify the response; ConsumerManager needs to be the same // (static) instance used to place the authentication request VerificationResult verification = manager.verify(receivingURL .toString(), response, discovered); // examine the verification result and extract the verified // identifier Identifier verified = verification.getVerifiedId(); if (verified != null) { AuthSuccess authSuccess = (AuthSuccess) verification .getAuthResponse(); receiveSimpleRegistration(httpReq, authSuccess); receiveAttributeExchange(httpReq, authSuccess); return verified; // success } } catch (OpenIDException e) { // present error to the user throw new ServletException(e); } return null; }
Example 2
Source File: OpenIdImpl.java From socialauth with MIT License | 4 votes |
/** * Verifies the user when the external provider redirects back to our * application. * * * @param requestParams * request parameters, received from the provider * @return Profile object containing the profile information * @throws Exception */ @Override public Profile verifyResponse(final Map<String, String> requestParams) throws Exception { if (!providerState) { throw new ProviderStateException(); } try { // extract the parameters from the authentication response // (which comes in as a HTTP request from the OpenID provider) ParameterList response = new ParameterList(requestParams); // extract the receiving URL from the HTTP request StringBuffer receivingURL = new StringBuffer(); receivingURL.append(successUrl); StringBuffer sb = new StringBuffer(); for (Map.Entry<String, String> entry : requestParams.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if (sb.length() > 0) { sb.append("&"); } sb.append(key).append("=").append(value); } receivingURL.append("?").append(sb.toString()); // verify the response; ConsumerManager needs to be the same // (static) instance used to place the authentication request VerificationResult verification = manager.verify( receivingURL.toString(), response, discovered); // examine the verification result and extract the verified // identifier Identifier verified = verification.getVerifiedId(); if (verified != null) { LOG.debug("Verified Id : " + verified.getIdentifier()); Profile p = new Profile(); p.setValidatedId(verified.getIdentifier()); AuthSuccess authSuccess = (AuthSuccess) verification .getAuthResponse(); if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) { FetchResponse fetchResp = (FetchResponse) authSuccess .getExtension(AxMessage.OPENID_NS_AX); p.setEmail(fetchResp.getAttributeValue("email")); p.setFirstName(fetchResp.getAttributeValue("firstname")); p.setLastName(fetchResp.getAttributeValue("lastname")); p.setFullName(fetchResp.getAttributeValue("fullname")); // also use the ax namespace for compatibility if (p.getEmail() == null) { p.setEmail(fetchResp.getAttributeValue("emailax")); } if (p.getFirstName() == null) { p.setFirstName(fetchResp .getAttributeValue("firstnameax")); } if (p.getLastName() == null) { p.setLastName(fetchResp.getAttributeValue("lastnameax")); } if (p.getFullName() == null) { p.setFullName(fetchResp.getAttributeValue("fullnameax")); } } userProfile = p; return p; } } catch (OpenIDException e) { throw e; } return null; }
Example 3
Source File: OpenIdConsumer.java From jerseyoauth2 with MIT License | 4 votes |
public Identifier verifyResponse(HttpServletRequest httpReq) { try { // extract the parameters from the authentication response // (which comes in as a HTTP request from the OpenID provider) ParameterList response = new ParameterList(httpReq.getParameterMap()); // retrieve the previously stored discovery information DiscoveryInformation discovered = (DiscoveryInformation) httpReq.getSession().getAttribute(OpenIdConstants.OPENID_DISC); // extract the receiving URL from the HTTP request StringBuffer receivingURL = httpReq.getRequestURL(); String queryString = httpReq.getQueryString(); if (queryString != null && queryString.length() > 0) receivingURL.append("?").append(httpReq.getQueryString()); // verify the response; ConsumerManager needs to be the same // (static) instance used to place the authentication request VerificationResult verification = manager.verify(receivingURL.toString(), response, discovered); // examine the verification result and extract the verified // identifier Identifier verified = verification.getVerifiedId(); if (verified != null) { AuthSuccess authSuccess = (AuthSuccess) verification.getAuthResponse(); if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) { FetchResponse fetchResp = (FetchResponse) authSuccess.getExtension(AxMessage.OPENID_NS_AX); List<?> emails = fetchResp.getAttributeValues("email"); String email = (String) emails.get(0); httpReq.getSession().setAttribute(OpenIdConstants.OPENID_SESSION_VAR, new OpenIDUser(email)); } return verified; // success } } catch (OpenIDException e) { // present error to the user } return null; }