Java Code Examples for org.openid4java.message.AuthRequest#addExtension()
The following examples show how to use
org.openid4java.message.AuthRequest#addExtension() .
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 | 6 votes |
/** * Simple Registration Extension example. * * @param httpReq * @param authReq * @throws MessageException * @see <a href="http://code.google.com/p/openid4java/wiki/SRegHowTo">Simple Registration HowTo</a> * @see <a href="http://openid.net/specs/openid-simple-registration-extension-1_0.html">OpenID Simple Registration Extension 1.0</a> */ private void addSimpleRegistrationToAuthRequest(HttpServletRequest httpReq, AuthRequest authReq) throws MessageException { // Attribute Exchange example: fetching the 'email' attribute // FetchRequest fetch = FetchRequest.createFetchRequest(); SRegRequest sregReq = SRegRequest.createFetchRequest(); String[] attributes = { "nickname", "email", "fullname", "dob", "gender", "postcode", "country", "language", "timezone" }; for (int i = 0, l = attributes.length; i < l; i++) { String attribute = attributes[i]; String value = httpReq.getParameter(attribute); if (OPTIONAL_VALUE.equals(value)) { sregReq.addAttribute(attribute, false); } else if (REQUIRED_VALUE.equals(value)) { sregReq.addAttribute(attribute, true); } } // attach the extension to the authentication request if (!sregReq.getAttributes().isEmpty()) { authReq.addExtension(sregReq); } }
Example 2
Source File: ConsumerServlet.java From openid4java with Apache License 2.0 | 6 votes |
/** * Attribute exchange example. * * @param httpReq * @param authReq * @throws MessageException * @see <a href="http://code.google.com/p/openid4java/wiki/AttributeExchangeHowTo">Attribute Exchange HowTo</a> * @see <a href="http://openid.net/specs/openid-attribute-exchange-1_0.html">OpenID Attribute Exchange 1.0 - Final</a> */ private void addAttributeExchangeToAuthRequest(HttpServletRequest httpReq, AuthRequest authReq) throws MessageException { String[] aliases = httpReq.getParameterValues("alias"); String[] typeUris = httpReq.getParameterValues("typeUri"); String[] counts = httpReq.getParameterValues("count"); FetchRequest fetch = FetchRequest.createFetchRequest(); for (int i = 0, l = typeUris == null ? 0 : typeUris.length; i < l; i++) { String typeUri = typeUris[i]; if (StringUtils.isNotBlank(typeUri)) { String alias = aliases[i]; boolean required = httpReq.getParameter("required" + i) != null; int count = NumberUtils.toInt(counts[i], 1); fetch.addAttribute(alias, typeUri, required, count); } } authReq.addExtension(fetch); }
Example 3
Source File: OpenIdImpl.java From socialauth with MIT License | 4 votes |
private String authRequest(final String userSuppliedString, final String returnToUrl) throws IOException { try { // perform discovery on the user-supplied identifier List discoveries = manager.discover(userSuppliedString); // attempt to associate with the OpenID provider // and retrieve one service endpoint for authentication discovered = manager.associate(discoveries); // // store the discovery information in the user's session // httpReq.getSession().setAttribute("openid-disc", discovered); // obtain a AuthRequest message to be sent to the OpenID provider AuthRequest authReq = manager.authenticate(discovered, returnToUrl); // Attribute Exchange example: fetching the 'email' attribute FetchRequest fetch = FetchRequest.createFetchRequest(); // Using axschema fetch.addAttribute("emailax", "http://axschema.org/contact/email", true); fetch.addAttribute("firstnameax", "http://axschema.org/namePerson/first", true); fetch.addAttribute("lastnameax", "http://axschema.org/namePerson/last", true); fetch.addAttribute("fullnameax", "http://axschema.org/namePerson", true); fetch.addAttribute("email", "http://schema.openid.net/contact/email", true); // Using schema.openid.net (for compatibility) fetch.addAttribute("firstname", "http://schema.openid.net/namePerson/first", true); fetch.addAttribute("lastname", "http://schema.openid.net/namePerson/last", true); fetch.addAttribute("fullname", "http://schema.openid.net/namePerson", true); // attach the extension to the authentication request authReq.addExtension(fetch); return authReq.getDestinationUrl(true); } catch (OpenIDException e) { e.printStackTrace(); } return null; }
Example 4
Source File: OpenIdConsumer.java From jerseyoauth2 with MIT License | 4 votes |
@SuppressWarnings("unchecked") public void authRequest(String openidServiceId, String returnToUrl, HttpServletRequest httpReq, HttpServletResponse httpResp) throws IOException, ServletException { try { // --- Forward proxy setup (only if needed) --- // ProxyProperties proxyProps = new ProxyProperties(); // proxyProps.setProxyName("proxy.example.com"); // proxyProps.setProxyPort(8080); // HttpClientFactory.setProxyProperties(proxyProps); // perform discovery on the user-supplied identifier List<?> discoveries = manager.discover(openidServiceId); // attempt to associate with the OpenID provider // and retrieve one service endpoint for authentication DiscoveryInformation discovered = manager.associate(discoveries); // store the discovery information in the user's session httpReq.getSession().setAttribute(OpenIdConstants.OPENID_DISC, discovered); // obtain a AuthRequest message to be sent to the OpenID provider AuthRequest authReq = manager.authenticate(discovered, returnToUrl); // Attribute Exchange example: fetching the 'email' attribute FetchRequest fetch = FetchRequest.createFetchRequest(); fetch.addAttribute("email", // attribute alias "http://schema.openid.net/contact/email", // type URI true); // required // attach the extension to the authentication request authReq.addExtension(fetch); if (!discovered.isVersion2()) { // Option 1: GET HTTP-redirect to the OpenID Provider endpoint // The only method supported in OpenID 1.x // redirect-URL usually limited ~2048 bytes httpResp.sendRedirect(authReq.getDestinationUrl(true)); } else { // Option 2: HTML FORM Redirection (Allows payloads >2048 bytes) sendFormRedirect(httpResp, authReq.getDestinationUrl(false), (Map<String,String>)authReq.getParameterMap()); } } catch (OpenIDException e) { e.printStackTrace(System.err); } }