Examples of OAuth2Message


Examples of net.oauth.v2.OAuth2Message

   
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {
       
      OAuth2Message requestMessage = null;
        try{
            requestMessage = OAuth2Servlet.getMessage(request, null);
           
            OAuth2Client client = SampleOAuth2Provider.getClient(requestMessage);
           
            SampleOAuth2Provider.VALIDATOR.validateRequestMessageForAuthorization(requestMessage,client);
           
            sendToAuthorizePage(request, response, client);

       
        } catch (Exception e){
            Boolean sendBodyInJson = false;
            Boolean withAuthHeader = false;
            if (e instanceof OAuth2ProblemException){
              OAuth2ProblemException problem = (OAuth2ProblemException) e;
              problem.setParameter(OAuth2.REDIRECT_URI,OAuth2.decodePercent(requestMessage.getParameter(OAuth2.REDIRECT_URI)));
              problem.setParameter(OAuth2ProblemException.HTTP_STATUS_CODE,new Integer(302));
              /* it can be removed at here */
              if(requestMessage.getParameter(OAuth2.STATE)!=null){
                  problem.setParameter(OAuth2.STATE, requestMessage.getParameter(OAuth2.STATE));
                }
            }
           
            SampleOAuth2Provider.handleException(e, request, response, sendBodyInJson, withAuthHeader);
        }
View Full Code Here

Examples of net.oauth.v2.OAuth2Message

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException{
       
        try{
            OAuth2Message requestMessage = OAuth2Servlet.getMessage(request, null);
           
            OAuth2Client client = SampleOAuth2Provider.getClient(requestMessage);
           
            String userId = request.getParameter("userId");
            if(userId == null){
              SampleOAuth2Provider.VALIDATOR.validateRequestMessageForAuthorization(requestMessage,client);
                sendToAuthorizePage(request, response, client);
            }
           
            OAuth2Accessor accessor = new OAuth2Accessor(client);           
           
            // set userId in accessor and mark it as authorized
            SampleOAuth2Provider.markAsAuthorized(accessor, userId);


            String requested = requestMessage.getParameter(OAuth2.RESPONSE_TYPE);
            if (requested.equals(OAuth2.ResponseType.CODE)) {
                SampleOAuth2Provider.generateCode(accessor);
                returnToConsumer(request, response, accessor);
            }else if (requested.equals(OAuth2.ResponseType.TOKEN)){
                // generate refresh token here but do not send back that
View Full Code Here

Examples of net.oauth.v2.OAuth2Message

            response.reset();
            response.setStatus(Integer.parseInt(httpCode.toString()));
           
           
            OAuth2Message message = new OAuth2Message(null, null, problem.getParameters().entrySet());  
            if(withAuthHeader){
              response.addHeader("WWW-Authenticate", message.getWWWAuthenticateHeader(realm));
            }

            List<Map.Entry<String, String>> sendBackErrorParameters = new ArrayList<Map.Entry<String, String>>(SEND_BACK_ERROR_PARAMETERS.size());
            for (Map.Entry parameter : message.getParameters()) {
                if(SEND_BACK_ERROR_PARAMETERS.contains(parameter.getKey()))
                {
                    sendBackErrorParameters.add(parameter);
                }
            }
View Full Code Here

Examples of org.apache.shindig.gadgets.oauth2.OAuth2Message

  protected void doGet(final HttpServletRequest request, final HttpServletResponse resp)
      throws IOException {

    OAuth2Accessor accessor = null;
    try {
      final OAuth2Message msg = this.oauth2MessageProvider.get();
      msg.parseRequest(request);
      final OAuth2Error error = msg.getError();
      final String requestStateKey = msg.getState();
      if (requestStateKey == null) {
        if (error != null) {
          OAuth2CallbackServlet.sendError(error, msg.getErrorDescription(), msg.getErrorUri(),
              null, resp, null);
        } else {
          OAuth2CallbackServlet.sendError(OAuth2Error.CALLBACK_PROBLEM,
              "OAuth2CallbackServlet requestStateKey is null.", "", null, resp, null);
        }
        return;
      }

      final Integer index = Integer.decode(requestStateKey);
      accessor = this.store.getOAuth2Accessor(index);

      if (error != null) {
        OAuth2CallbackServlet.sendError(error, msg.getErrorDescription(), msg.getErrorUri(),
            accessor, resp, null);
        return;
      }

      if ((accessor == null) || (!accessor.isValid()) || (accessor.isErrorResponse())) {
View Full Code Here

Examples of org.apache.shindig.gadgets.oauth2.OAuth2Message

          "grant_type is not code", null);
    }

    if (ret == null) {
      try {
        final OAuth2Message msg = this.oauth2MessageProvider.get();
        msg.parseRequest(request);

        ret = this.setAuthorizationCode(msg.getAuthorization(), accessor);
      } catch (final Exception e) {
        if (CodeAuthorizationResponseHandler.LOG.isLoggable()) {
          CodeAuthorizationResponseHandler.LOG.log(
              "Exception exchanging authorization code for access_token", e);
        }
View Full Code Here

Examples of org.apache.shindig.gadgets.oauth2.OAuth2Message

            "error exchanging code for access_token", e);
      }

      if ((ret == null) && (response != null)) {
        if (response.getHttpStatusCode() != HttpResponse.SC_OK) {
          final OAuth2Message msg = this.oauth2MessageProvider.get();
          msg.parseJSON(response.getResponseAsString());
          if (msg.getError() != null) {
            ret = new OAuth2HandlerError(msg.getError(), "error exchanging code for access_token",
                null);
          }
        }

        if (ret == null) {
View Full Code Here

Examples of org.apache.shindig.gadgets.oauth2.OAuth2Message

        if (ret == null) {
          final long issuedAt = System.currentTimeMillis() / 1000;

          final String contentType = response.getHeader("Content-Type");
          final String responseString = response.getResponseAsString();
          final OAuth2Message msg = this.oauth2MessageProvider.get();

          if (contentType.startsWith("text/plain")) {
            // Facebook does this
            msg.parseQuery('?' + responseString);
          } else if (contentType.startsWith("application/json")) {
            // Google does this
            final JSONObject responseJson = new JSONObject(responseString);
            msg.parseJSON(responseJson.toString());
          } else {
            if (isLogging) {
              TokenAuthorizationResponseHandler.LOG.log("Unhandled Content-Type {0}", contentType);
              TokenAuthorizationResponseHandler.LOG.exiting(
                  TokenAuthorizationResponseHandler.LOG_CLASS, "handleResponse", null);
            }
            ret = TokenAuthorizationResponseHandler.getError("Unhandled Content-Type "
                + contentType);
          }

          final OAuth2Error error = msg.getError();
          if ((error == null) && (accessor != null)) {
            final String accessToken = msg.getAccessToken();
            final String refreshToken = msg.getRefreshToken();
            final String expiresIn = msg.getExpiresIn();
            final String tokenType = msg.getTokenType();
            final String providerName = accessor.getServiceName();
            final String gadgetUri = accessor.getGadgetUri();
            final String scope = accessor.getScope();
            final String user = accessor.getUser();
            final String macAlgorithm = msg.getMacAlgorithm();
            final String macSecret = msg.getMacSecret();
            final Map<String, String> unparsedProperties = msg.getUnparsedProperties();

            if (accessToken != null) {
              final OAuth2Token storedAccessToken = this.store.createToken();
              storedAccessToken.setIssuedAt(issuedAt);
              if (expiresIn != null) {
View Full Code Here

Examples of org.apache.shindig.gadgets.oauth2.OAuth2Message

  @Override
  protected void doGet(final HttpServletRequest request, final HttpServletResponse resp)
      throws IOException {
    final String method = "doGet";
    DominoOAuth2Accessor accessor = null;
    final OAuth2Message msg = this.oauth2MessageProvider.get();
    msg.parseRequest(request);
    if(!isOAuthMsgValid(msg, resp)) {
      return;
    }
    final DominoOAuth2CallbackState state = new DominoOAuth2CallbackState(this.stateCrypter,
        msg.getState());

    try {
      accessor = this.store.getOAuth2Accessor(state);
    } catch (GadgetException e1) {
      log.logp(Level.WARNING, CLASS, method, "Error getting accessor from store.", e1);
View Full Code Here

Examples of org.apache.shindig.gadgets.oauth2.OAuth2Message

        if (ret == null) {
          final long issuedAt = System.currentTimeMillis();

          final String contentType = response.getHeader("Content-Type");
          final String responseString = response.getResponseAsString();
          final OAuth2Message msg = this.oauth2MessageProvider.get();

          if(log.isLoggable(Level.FINEST)) {
            log.logp(Level.FINEST, CLASS, method, "Content-Type {0}", contentType);
            log.logp(Level.FINEST, CLASS, method, "Response String {0}", response);
          }

          if (contentType.startsWith("application/json")) {
            // Google does this
            msg.parseJSON(responseString);
          } else {
            // Facebook does this
            msg.parseQuery('?' + responseString)
          }

          final OAuth2Error error = msg.getError();
          if (error != null) {
            ret = getError("error parsing request", null, msg.getErrorUri(),
                msg.getErrorDescription());
          } else if (error == null) {
            final String accessToken = msg.getAccessToken();
            final String refreshToken = msg.getRefreshToken();
            final String expiresIn = msg.getExpiresIn();
            final String tokenType = msg.getTokenType();
            final String providerName = accessor.getServiceName();
            final String gadgetUri = accessor.getGadgetUri();
            final String scope = accessor.getScope();
            final String user = accessor.getUser();
            final String macAlgorithm = msg.getMacAlgorithm();
            final String macSecret = msg.getMacSecret();
            final Map<String, String> unparsedProperties = msg.getUnparsedProperties();

            if (accessToken != null) {
              final OAuth2Token storedAccessToken = this.store.createToken();
              storedAccessToken.setIssuedAt(issuedAt);
              if (expiresIn != null) {
View Full Code Here

Examples of org.apache.shindig.gadgets.oauth2.OAuth2Message

              "grant_type is not code", null);
    }

    if (ret == null) {
      try {
        final OAuth2Message msg = this.oauth2MessageProvider.get();
        msg.parseRequest(request);

        ret = this.setAuthorizationCode(msg.getAuthorization(), accessor);
      } catch (final Exception e) {
        if (CodeAuthorizationResponseHandler.LOG.isLoggable()) {
          CodeAuthorizationResponseHandler.LOG.log(
                  "Exception exchanging authorization code for access_token", e);
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.