Package org.openid4java.message

Examples of org.openid4java.message.AuthRequest


      // Persist the User
      InMemoryUserCache.INSTANCE.put(sessionToken, tempUser);

      // Build the AuthRequest message to be sent to the OpenID provider
      AuthRequest authReq = consumerManager.authenticate(discovered, returnToUrl);

      // Build the FetchRequest containing the information to be copied
      // from the OpenID provider
      FetchRequest fetch = FetchRequest.createFetchRequest();
      // Attempt to decode each entry
      if (identifier.startsWith(GOOGLE_ENDPOINT)) {
        fetch.addAttribute("email", "http://axschema.org/contact/email", true);
        fetch.addAttribute("firstName", "http://axschema.org/namePerson/first", true);
        fetch.addAttribute("lastName", "http://axschema.org/namePerson/last", true);
      } else if (identifier.startsWith(YAHOO_ENDPOINT)) {
        fetch.addAttribute("email", "http://axschema.org/contact/email", true);
        fetch.addAttribute("fullname", "http://axschema.org/namePerson", true);
      } else { // works for myOpenID
        fetch.addAttribute("fullname", "http://schema.openid.net/namePerson", true);
        fetch.addAttribute("email", "http://schema.openid.net/contact/email", true);
      }

      // Attach the extension to the authentication request
      authReq.addExtension(fetch);

      // Redirect the user to their OpenId server authentication process
      return Response
        .seeOther(URI.create(authReq.getDestinationUrl(true)))
        .build();

    } catch (MessageException e1) {
      log.error("MessageException:", e1);
    } catch (DiscoveryException e1) {
View Full Code Here


            // // 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
            // providerType
            AuthRequest authReq = manager.authenticate(discovered, returnToUrl);

            // Attribute Exchange example: fetching the 'email' attribute
            FetchRequest fetch = FetchRequest.createFetchRequest();
            openIdProvider.prepareRequest(fetch);

            // attach the extension to the authentication request
            authReq.addExtension(fetch);

            return authReq.getDestinationUrl(true);
        } catch (OpenIDException e) {
            LOGGER.warn("exception", e);
        }

        return null;
View Full Code Here

      String userSelectedClaimedId = (String) userData.get(0);
      Boolean authenticatedAndApproved = (Boolean) userData.get(1);
      String email = (String) userData.get(2);

      // --- process an authentication request ---
      AuthRequest authReq = AuthRequest.createAuthRequest(request, manager.getRealmVerifier());
      response = manager.authResponse(request, null, userSelectedClaimedId, authenticatedAndApproved, false); // Sign after we added extensions.

      if (response instanceof DirectError) {
        return directResponse(httpResp, response.keyValueFormEncoding());
      } else {
        if (authReq.hasExtension(AxMessage.OPENID_NS_AX)) {
          MessageExtension ext = authReq.getExtension(AxMessage.OPENID_NS_AX);
          if (ext instanceof FetchRequest) {
            FetchRequest fetchReq = (FetchRequest) ext;
            Map<?, ?> required = fetchReq.getAttributes(true);
            //Map optional = fetchReq.getAttributes(false);
            if (required.containsKey("email")) {
              Map<Object, Object> userDataExt = new HashMap<>();
              //userDataExt.put("email", userData.get(3));

              FetchResponse fetchResp = FetchResponse.createFetchResponse(fetchReq, userDataExt);
              // (alternatively) manually add attribute values
              fetchResp.addAttribute("email", "http://schema.openid.net/contact/email", email);
              response.addExtension(fetchResp);
            }
          } else {
            throw new UnsupportedOperationException("TODO");
          }
        }
        if (authReq.hasExtension(SRegMessage.OPENID_NS_SREG)) {
          MessageExtension ext = authReq.getExtension(SRegMessage.OPENID_NS_SREG);
          if (ext instanceof SRegRequest) {
            SRegRequest sregReq = (SRegRequest) ext;
            List<?> required = sregReq.getAttributes(true);
            //List optional = sregReq.getAttributes(false);
            if (required.contains("email")) {
View Full Code Here

        // store the discovery information in the user's session
        request.getSession().setAttribute(DISCOVERY_SESSION_KEY, discovered);

        // obtain a AuthRequest message to be sent to the OpenID provider
        AuthRequest authReq = manager.authenticate(discovered, returnUrl);
        authReq.setImmediate(isImmediateRequest);

        // since our service uses OpenId Version two this should to it
        response.sendRedirect(authReq.getDestinationUrl(true));
    }
View Full Code Here

            // 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 = null;

            String returnToUrl = httpReq.getRequestURL().toString();
            authReq = manager.authenticate(discovered, returnToUrl);
            String destinationUrl = authReq.getDestinationUrl(true);
           
            ClientRequest req = new ClientRequest(destinationUrl);
            ClientResponse<String> resp = null;
            ParameterList response = null;
            try {
View Full Code Here

                directResponse(resp, responseText);
                return;
            }
         
            // --- process an authentication request ---
            AuthRequest authReq = null;
            try {
                authReq = AuthRequest.createAuthRequest(request, manager.getRealmVerifier());
            } catch (Exception ex) {
              throw new ServletException(ex);
            }

            String opLocalId = null;
            // if the user chose a different claimed_id than the one in request
            if (userSelectedClaimedId != null &&
                userSelectedClaimedId.equals(authReq.getClaimed()))
            {
                //opLocalId = lookupLocalId(userSelectedClaimedId);
            }
           
            response = manager.authResponse(request,
View Full Code Here

      DiscoveryInformation discovered = providerInfo.get();

      // obtain a AuthRequest message to be sent to the OpenID provider
      try
      {
         AuthRequest authReq = consumerManager.authenticate(discovered,
               adapter.getReturnURL());

         // Attribute Exchange example: fetching the 'email' attribute
         FetchRequest fetch = FetchRequest.createFetchRequest();
         SRegRequest sregReq = SRegRequest.createFetchRequest();

         OpenIDAttributeMap amap = adapter.getAttributeMap();
        
         if ("1".equals(amap.get("nickname")))
         {
            // fetch.addAttribute("nickname",
            // "http://schema.openid.net/contact/nickname", false);
            sregReq.addAttribute("nickname", false);
         }
        
         if ("1".equals(amap.get("email")))
         {
            fetch.addAttribute("email",OpenIDConstants.EMAIL.url(), false);
            sregReq.addAttribute("email", false);
         }
        
         if ("1".equals(amap.get("fullname")))
         {
            fetch.addAttribute("fullname",OpenIDConstants.FULLNAME.url(), false);
            sregReq.addAttribute("fullname", false);
         }
         if ("1".equals(amap.get("dob")))
         {
            fetch.addAttribute("dob",OpenIDConstants.DOB.url(), true);
            sregReq.addAttribute("dob", false);
         }
        
         if ("1".equals(amap.get("gender")))
         {
            fetch.addAttribute("gender",OpenIDConstants.GENDER.url(), false);
            sregReq.addAttribute("gender", false);
         }
        
         if ("1".equals(amap.get("postcode")))
         {
            fetch.addAttribute("postcode",OpenIDConstants.POSTCODE.url(), false);
            sregReq.addAttribute("postcode", false);
         }
        
         if ("1".equals(amap.get("country")))
         {
            fetch.addAttribute("country",OpenIDConstants.COUNTRY.url(), false);
            sregReq.addAttribute("country", false);
         }
        
         if ("1".equals(amap.get("language")))
         {
            fetch.addAttribute("language", OpenIDConstants.LANGUAGE.url(),false);
            sregReq.addAttribute("language", false);
         }
        
         if ("1".equals(amap.get("timezone")))
         {
            fetch.addAttribute("timezone", OpenIDConstants.TIMEZONE.url(), false);
            sregReq.addAttribute("timezone", false);
         }
        
        
         // attach the extension to the authentication request
         if (!sregReq.getAttributes().isEmpty())
         {
             authReq.addExtension(sregReq);
         }

         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
            adapter.sendToProvider(1, authReq.getDestinationUrl(true), null);
            return false;
         }
         else
         {
             // Option 2: HTML FORM Redirection (Allows payloads >2048 bytes)
            adapter.sendToProvider(2, authReq.getDestinationUrl(false),
                  authReq.getParameterMap());
         }
      }
      catch (MessageException e)
      {
         throw new OpenIDMessageException(e);
View Full Code Here

      // configure the return_to URL where your application will receive
      // the authentication responses from the OpenID provider
      String returnToUrl = _delegate.returnToUrl(request, context);

      // obtain a AuthRequest message to be sent to the OpenID provider
      AuthRequest authReq = _manager.authenticate(discovered, returnToUrl, realm);

      // add the message extensions
      List<MessageExtension> exts = _delegate.createFetchMessageExtensions(userSuppliedString, request, context);
      for (MessageExtension ext : exts) {
        // attach the extension to the authentication request
        EROpenIDManager.log.debug("Authentication request extension: " + ext);
        authReq.addExtension(ext);
      }

      if (!discovered.isVersion2()) {
        WORedirect redirect = new WORedirect(context);
        String url = authReq.getDestinationUrl(true);
        EROpenIDManager.log.debug("Request URL: " + url);
        redirect.setUrl(url);
        results = redirect;
      }
      else {
        String formRedirectionPageName = ERXProperties.stringForKeyWithDefault("er.openid.formRedirectionPageName", EROFormRedirectionPage.class.getName());
        EROFormRedirectionPage formRedirectionPage = (EROFormRedirectionPage)WOApplication.application().pageWithName(formRedirectionPageName, context);
        formRedirectionPage.setParameters( authReq.getParameterMap() );
        String url = authReq.getDestinationUrl(false);
        EROpenIDManager.log.debug("Request URL: " + url);
        formRedirectionPage.takeValueForKey(url, "redirectionUrl");
        results = formRedirectionPage;
      }
    }
View Full Code Here

  }

  public void redirect(String openId) {
    discoveryInformation = performDiscovery(openId);

    AuthRequest authRequest = createOpenIdAuthRequest();

    WicketUtils.performTemporaryRedirect(authRequest.getDestinationUrl(true));
  }
View Full Code Here

  private AuthRequest createOpenIdAuthRequest() {
    try {
      ConsumerManager consumerManager = OpenIdSession.get().getConsumerManager();

      AuthRequest auth = consumerManager.authenticate(discoveryInformation, OpenIdSession.get()
          .getOpenIdReturnUrl());

      if (discoveryInformation.getTypes().contains(AxMessage.OPENID_NS_AX)) {
        FetchRequest fetch = FetchRequest.createFetchRequest();
        fetch.addAttribute("email", "http://axschema.org/contact/email", true);
        fetch.addAttribute("fullname", "http://axschema.org/namePerson", false);
        fetch.addAttribute("firstname", "http://axschema.org/namePerson/first", false);
        fetch.addAttribute("lastname", "http://axschema.org/namePerson/last", false);
        auth.addExtension(fetch);
      } else if (discoveryInformation.getTypes().contains(SRegMessage.OPENID_NS_SREG)) {
        SRegRequest sregReq = SRegRequest.createFetchRequest();

        sregReq.addAttribute("fullname", true);
        sregReq.addAttribute("email", true);

        auth.addExtension(sregReq);
      }

      return auth;
    } catch (MessageException e) {
      throw new WicketRuntimeException("failed to create OpenID AuthRequest", e);
View Full Code Here

TOP

Related Classes of org.openid4java.message.AuthRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.