Examples of AccessGrant


Examples of org.brickred.socialauth.util.AccessGrant

    String line;
    while ((line = br.readLine()) != null) {
      sb.append(line);
    }
    ObjectMapper mapper = new ObjectMapper();
    AccessGrant accessGrant = mapper.readValue(sb.toString(),
        AccessGrant.class);
    AuthProvider provider = socialAuthManager.connect(accessGrant);
    List<Feed> feeds = new ArrayList<Feed>();
    if (provider
        .isSupportedPlugin(org.brickred.socialauth.plugin.FeedPlugin.class)) {
View Full Code Here

Examples of org.brickred.socialauth.util.AccessGrant

    LOG.debug("Running OpenID discovery");
    String reqTokenStr = "";
    if (this.scope != null) {
      if (Permission.AUTHENTICATE_ONLY.equals(this.permission)) {
        accessToken = new AccessGrant();
      } else {
        if (requestParams.get(OpenIdConsumer.OPENID_REQUEST_TOKEN) != null) {
          reqTokenStr = HttpUtil.decodeURIComponent(requestParams
              .get(OpenIdConsumer.OPENID_REQUEST_TOKEN));
        }
        requestToken = new AccessGrant();
        requestToken.setKey(reqTokenStr);
        LOG.debug("Call to fetch Access Token");
        accessToken = oauth.getAccessToken(
            endpoints.get(Constants.OAUTH_ACCESS_TOKEN_URL),
            requestToken);
View Full Code Here

Examples of org.brickred.socialauth.util.AccessGrant

      String accessToken = requestParams.get("access_token");
      Integer expires = null;
      if (requestParams.get(Constants.EXPIRES) != null) {
        expires = new Integer(requestParams.get(Constants.EXPIRES));
      }
      accessGrant = new AccessGrant();
      accessGrant.setKey(accessToken);
      accessGrant.setAttribute(Constants.EXPIRES, expires);
      if (permission != null) {
        accessGrant.setPermission(permission);
      } else {
        accessGrant.setPermission(Permission.ALL);
      }
      accessGrant.setProviderId(providerId);
      LOG.debug(accessGrant);
      return accessGrant;
    }

    if (!providerState) {
      throw new ProviderStateException();
    }

    String code = requestParams.get("code");
    if (code == null || code.length() == 0) {
      throw new SocialAuthException("Verification code is null");
    }
    LOG.debug("Verification Code : " + code);
    String acode;
    String accessToken = null;
    try {
      acode = URLEncoder.encode(code, "UTF-8");
    } catch (Exception e) {
      acode = code;
    }
    StringBuffer sb = new StringBuffer();
    if (MethodType.GET.toString().equals(methodType)) {
      sb.append(endpoints.get(Constants.OAUTH_ACCESS_TOKEN_URL));
      char separator = endpoints.get(Constants.OAUTH_ACCESS_TOKEN_URL)
          .indexOf('?') == -1 ? '?' : '&';
      sb.append(separator);
    }
    sb.append("client_id=").append(oauth.getConfig().get_consumerKey());
    sb.append("&redirect_uri=").append(this.successUrl);
    sb.append("&client_secret=").append(
        oauth.getConfig().get_consumerSecret());
    sb.append("&code=").append(acode);
    sb.append("&grant_type=authorization_code");

    Response response;
    String authURL = null;
    try {
      if (MethodType.GET.toString().equals(methodType)) {
        authURL = sb.toString();
        LOG.debug("URL for Access Token request : " + authURL);
        response = HttpUtil.doHttpRequest(authURL, methodType, null,
            null);
      } else {
        authURL = endpoints.get(Constants.OAUTH_ACCESS_TOKEN_URL);
        LOG.debug("URL for Access Token request : " + authURL);
        response = HttpUtil.doHttpRequest(authURL, methodType,
            sb.toString(), null);
      }
    } catch (Exception e) {
      throw new SocialAuthException("Error in url : " + authURL, e);
    }
    String result;
    try {
      result = response.getResponseBodyAsString(Constants.ENCODING);
    } catch (IOException io) {
      throw new SocialAuthException(io);
    }
    Map<String, Object> attributes = new HashMap<String, Object>();
    Integer expires = null;
    if (result.indexOf("{") < 0) {
      String[] pairs = result.split("&");
      for (String pair : pairs) {
        String[] kv = pair.split("=");
        if (kv.length != 2) {
          throw new SocialAuthException(
              "Unexpected auth response from " + authURL);
        } else {
          if (kv[0].equals("access_token")) {
            accessToken = kv[1];
          } else if (kv[0].equals("expires")) {
            expires = Integer.valueOf(kv[1]);
          } else if (kv[0].equals("expires_in")) {
            expires = Integer.valueOf(kv[1]);
          } else {
            attributes.put(kv[0], kv[1]);
          }
        }
      }
    } else {
      try {
        JSONObject jObj = new JSONObject(result);
        if (jObj.has("access_token")) {
          accessToken = jObj.getString("access_token");
        }
        if (jObj.has("expires_in")) {
          String str = jObj.getString("expires_in");
          if (str != null && str.length() > 0) {
            expires = Integer.valueOf(str);
          }
        }
        if (accessToken != null) {
          Iterator<String> keyItr = jObj.keys();
          while (keyItr.hasNext()) {
            String key = keyItr.next();
            if (!"access_token".equals(key)
                && !"expires_in".equals(key)) {
              attributes.put(key, jObj.optString(key));
            }
          }
        }
      } catch (JSONException je) {
        throw new SocialAuthException("Unexpected auth response from "
            + authURL);
      }
    }
    LOG.debug("Access Token : " + accessToken);
    LOG.debug("Expires : " + expires);
    if (accessToken != null) {
      accessGrant = new AccessGrant();
      accessGrant.setKey(accessToken);
      accessGrant.setAttribute(Constants.EXPIRES, expires);
      if (attributes.size() > 0) {
        accessGrant.setAttributes(attributes);
      }
View Full Code Here

Examples of org.brickred.socialauth.util.AccessGrant

    } finally {
      lock.unlock();
    }
    stop();

    AccessGrant accessGrant = manager.createAccessGrant(providerId,
        paramsMap, successURL);

    Exporter.exportAccessGrant(accessGrant, tokenFilePath);

    LOG.info("Access Grant Object saved in a file  :: " + tokenFilePath
        + File.separatorChar + accessGrant.getProviderId()
        + "_accessGrant_file.txt");
  }
View Full Code Here

Examples of org.brickred.socialauth.util.AccessGrant

    reader.close();

    String jsonStr = sb.toString();
    LOG.debug("AccessGrant json :: " + jsonStr);
    ObjectMapper mapper = new ObjectMapper();
    AccessGrant grant = mapper.readValue(jsonStr, AccessGrant.class);
    LOG.debug(grant.toString());
    return grant;
  }
View Full Code Here

Examples of org.brickred.socialauth.util.AccessGrant

      throw new SocialAuthException(e);
    }

    Map<String, Object> attributes = new HashMap<String, Object>();
    String[] pairs = result.split("&");
    AccessGrant ag = new AccessGrant();
    for (String pair : pairs) {
      String[] kv = pair.split("=");
      if (kv.length != 2) {
        throw new SocialAuthException(
            "Unexpected response from refresh token call");
      } else {
        if (kv[0].equals("access_token")) {
          ag.setKey(kv[1]);
        } else if (kv[0].equals("expires")) {
          ag.setAttribute(Constants.EXPIRES, Integer.valueOf(kv[1]));
        } else if (kv[0].equals("expires_in")) {
          ag.setAttribute(Constants.EXPIRES, Integer.valueOf(kv[1]));
        } else {
          attributes.put(kv[0], kv[1]);
        }
      }
    }
    ag.setAttributes(attributes);
    LOG.debug("Refresh token Access Grant ::" + ag);
    accessGrant = ag;
    authenticationStrategy.setAccessGrant(ag);
  }
View Full Code Here

Examples of org.brickred.socialauth.util.AccessGrant

    accessToken = accessTokenObject.getString("token");
    LOG.debug("Access Token : " + accessToken);

    if (accessToken != null) {
      isVerify = true;
      accessGrant = new AccessGrant();
      accessGrant.setKey(accessToken);
      if (scope != null) {
        accessGrant.setPermission(scope);
      } else {
        accessGrant.setPermission(Permission.ALL);
View Full Code Here

Examples of org.encuestame.utils.oauth.AccessGrant

        requestParameters.set("redirect_uri", redirectUri);
        requestParameters.set("grant_type", "authorization_code");
        log.debug("requestParameters "+requestParameters.toString());
        Map result = getRestTemplate().postForObject(accessTokenUrl, requestParameters, Map.class);
        log.debug("Access Grant "+result.toString());
        return new AccessGrant(valueOf(result.get("access_token")), valueOf(result.get("refresh_token")));
    }
View Full Code Here

Examples of org.encuestame.utils.oauth.AccessGrant

        requestParameters.set("grant_type", "refresh_token");
        log.debug("requestParameters "+requestParameters.toString());
        @SuppressWarnings("unchecked")
        Map<String, ?> result = getRestTemplate().postForObject(accessTokenUrl, requestParameters, Map.class);
        log.debug(result);
        return new AccessGrant(valueOf(result.get("access_token")), refreshToken);
    }
View Full Code Here

Examples of org.encuestame.utils.oauth.AccessGrant

    @RequestMapping(value="/social/back/google", method=RequestMethod.GET, params="code")
    public String oauth2Callback(
            @RequestParam("code") String code,
            HttpServletRequest httpRequest,
        WebRequest request) throws Exception {
            final AccessGrant accessGrant = auth2RequestProvider.getAccessGrant(code, httpRequest);
            log.debug(accessGrant.getAccessToken());
            log.debug(accessGrant.getRefreshToken());
            checkOAuth2SocialAccount(SocialProvider.GOOGLE_BUZZ, accessGrant);
            return this.redirect+"#provider="+SocialProvider.GOOGLE_BUZZ.toString().toLowerCase()+"&refresh=true&successful=true";
    }
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.