net.oauth.OAuth类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(128)

本文整理了Java中net.oauth.OAuth类的一些代码示例,展示了OAuth类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OAuth类的具体详情如下:
包路径:net.oauth.OAuth
类名称:OAuth

OAuth介绍

暂无

代码示例

代码示例来源:origin: org.gatein.shindig/shindig-common

public static String formEncode(Iterable<? extends Entry<String, String>> parameters) {
 try {
  return OAuth.formEncode(parameters);
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: org.apache.shindig/shindig-common

public static String addParameters(String url, List<Entry<String, String>> parameters) {
 try {
  return OAuth.addParameters(url, parameters);
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: net.oauth.core/oauth

public static String getBaseString(OAuthMessage message)
    throws IOException, URISyntaxException {
  List<Map.Entry<String, String>> parameters;
  String url = message.URL;
  int q = url.indexOf('?');
  if (q < 0) {
    parameters = message.getParameters();
  } else {
    // Combine the URL query string with the other parameters:
    parameters = new ArrayList<Map.Entry<String, String>>();
    parameters.addAll(OAuth.decodeForm(message.URL.substring(q + 1)));
    parameters.addAll(message.getParameters());
    url = url.substring(0, q);
  }
  return OAuth.percentEncode(message.method.toUpperCase()) + '&'
      + OAuth.percentEncode(normalizeUrl(url)) + '&'
      + OAuth.percentEncode(normalizeParameters(parameters));
}

代码示例来源:origin: sakaiproject/sakai

/**
 * Construct a URL like the given one, but with the given parameters added
 * to its query string.
 */
public static String addParameters(String url, String... parameters)
    throws IOException {
  return addParameters(url, newList(parameters));
}

代码示例来源:origin: net.oauth.core/oauth

/**
 * Construct a form-urlencoded document containing the given sequence of
 * name/value pairs. Use OAuth percent encoding (not exactly the encoding
 * mandated by HTTP).
 */
public static String formEncode(Iterable<? extends Map.Entry> parameters)
    throws IOException {
  ByteArrayOutputStream b = new ByteArrayOutputStream();
  formEncode(parameters, b);
  return decodeCharacters(b.toByteArray());
}

代码示例来源:origin: sakaiproject/sakai

/** Construct a &-separated list of the given values, percentEncoded. */
public static String percentEncode(Iterable<?> values) {
  StringBuilder p = new StringBuilder();
  for (Object v : values) {
    if (p.length() > 0) {
      p.append("&");
    }
    p.append(OAuth.percentEncode(toString(v)));
  }
  return p.toString();
}

代码示例来源:origin: org.wso2.org.apache.shindig/shindig-social-api

String query = target.getQuery();
target.setQuery(null);
oauthParams.addAll(OAuth.decodeForm(query));
 if (OAuth.isFormEncoded(contentType)) {
  oauthParams.addAll(OAuth.decodeForm(body));
 } else if (bodySigning == BodySigning.LEGACY) {
  oauthParams.add(new OAuth.Parameter(body, ""));
  break;
 case POST_BODY:
  if (!OAuth.isFormEncoded(contentType)) {
   throw new RuntimeException(
     "OAuth param location can only be post_body if post body is of " +
  String oauthData = OAuth.formEncode(message.getParameters());
  request.setPostData(CharsetUtil.getUtf8Bytes(oauthData));
  break;
 case URI_QUERY:
  request.setQueryString(Uri.parse(OAuth.addParameters(url, entryList)).getQuery());
  break;
 request.setPostData(body, "UTF-8");
 if (contentType.contains(OAuth.FORM_ENCODED)) {
  List<OAuth.Parameter> bodyParams = OAuth.decodeForm(body);
  for (OAuth.Parameter bodyParam : bodyParams) {
   request.setParameter(bodyParam.getKey(), bodyParam.getValue());

代码示例来源:origin: org.apache.shindig/shindig-gadgets

if (aznHeader != null) {
  info.aznHeader = aznHeader;
  for (OAuth.Parameter p : OAuthMessage.decodeAuthorization(aznHeader)) {
   if (!p.getKey().equalsIgnoreCase("realm")) {
    params.add(p);
 throw new RuntimeException("Can't read post body bytes", e);
if (OAuth.isFormEncoded(request.getHeader("Content-Type"))) {
 params.addAll(OAuth.decodeForm(request.getPostBodyAsString()));
info.message = new OAuthMessage(method, parsed.getLocation(), params);

代码示例来源:origin: org.apache.shindig/shindig-social-api

OAuthMessage requestMessage = OAuthServlet.getMessage(servletRequest, null);
String consumerKey = requestMessage.getConsumerKey();
if (consumerKey == null) {
 OAuthProblemException e = new OAuthProblemException(OAuth.Problems.PARAMETER_ABSENT);
validator.validateMessage(requestMessage, accessor);
String callback = requestMessage.getParameter(OAuth.OAUTH_CALLBACK);
                         requestMessage.getParameter(OAuth.OAUTH_VERSION), callback);
List<Parameter> responseParams = OAuth.newList(OAuth.OAUTH_TOKEN, entry.getToken(),
                        OAuth.OAUTH_TOKEN_SECRET, entry.getTokenSecret());
if (callback != null) {

代码示例来源:origin: edu.uiuc.ncsa.security.delegation/ncsa-security-oauth-1.0a

public void write(HttpServletResponse response) throws IOException {
  response.setContentType(OAuthConstants.FORM_ENCODING);
  OutputStream out = response.getOutputStream();
  List<OAuth.Parameter> list;
  ArrayList<String> arrayList = new ArrayList<String>();
  arrayList.add(OAuth.OAUTH_TOKEN);
  arrayList.add(getGrant().getToken());
  arrayList.add(OAuth.OAUTH_TOKEN_SECRET);
  arrayList.add(getGrant().getSharedSecret());
  for (String k : getParameters().keySet()) {
    if (!k.startsWith("oauth_")) {
      arrayList.add(k);
      arrayList.add(getParameters().get(k));
    }
  }
  list = OAuth.newList(arrayList.toArray(new String[arrayList.size()]));
  OAuth.formEncode(list, out);
  out.flush();
  out.close();
}

代码示例来源:origin: sakaiproject/sakai

/** 
   * getOAuthURL - Form a GET request signed by OAuth
 * @param method
 * @param url
 * @param oauth_consumer_key
 * @param oauth_secret
 * @param signature
 */
public static String getOAuthURL(String method, String url, 
  String oauth_consumer_key, String oauth_secret, String signature)
{
  OAuthMessage om = new OAuthMessage(method, url, null);
  om.addParameter(OAuth.OAUTH_CONSUMER_KEY, oauth_consumer_key);
  if ( signature == null ) signature = OAuth.HMAC_SHA1;
  om.addParameter(OAuth.OAUTH_SIGNATURE_METHOD, signature);
  om.addParameter(OAuth.OAUTH_VERSION, "1.0");
  om.addParameter(OAuth.OAUTH_TIMESTAMP, new Long((new Date().getTime()) / 1000).toString());
  om.addParameter(OAuth.OAUTH_NONCE, UUID.randomUUID().toString());
  OAuthConsumer oc = new OAuthConsumer(null, oauth_consumer_key, oauth_secret, null);
  try {
    OAuthSignatureMethod osm = OAuthSignatureMethod.newMethod(signature, new OAuthAccessor(oc));
    osm.sign(om);
    url = OAuth.addParameters(url, om.getParameters());
    return url;
  } catch (Exception e) {
    log.error(e.getMessage(), e);
    return null;
  }
}

代码示例来源:origin: rometools/rome

OAuthMessage message;
try {
  message = new OAuthMessage(method.getName(), method.getURI().toString(), params.entrySet());
  message.sign(accessor);
  finalUri = OAuth.addParameters(message.URL, message.getParameters());

代码示例来源:origin: org.entando.entando/entando-core-engine

public void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException {
  IOAuthConsumerManager consumerManager = 
      (IOAuthConsumerManager) ApsWebApplicationUtils.getBean(SystemConstants.OAUTH_CONSUMER_MANAGER, request);
  try {
    OAuthMessage requestMessage = OAuthServlet.getMessage(request, null);
    OAuthConsumer consumer = consumerManager.getConsumer(requestMessage);
    OAuthAccessor accessor = new OAuthAccessor(consumer);
    consumerManager.getOAuthValidator().validateMessage(requestMessage, accessor);
    String secret = requestMessage.getParameter("oauth_accessor_secret");
    if (secret != null) {
      accessor.setProperty(OAuthConsumer.ACCESSOR_SECRET, secret);
    }
    consumerManager.generateRequestToken(accessor);
    response.setContentType("text/plain");
    OutputStream out = response.getOutputStream();
    OAuth.formEncode(OAuth.newList("oauth_token", accessor.requestToken, 
        "oauth_token_secret", accessor.tokenSecret), out);
    out.close();
  } catch (Exception e){
    consumerManager.handleException(e, request, response, true);
  }
}

代码示例来源:origin: org.apache.shindig/shindig-social-api

private void createAccessToken(HttpServletRequest servletRequest,
                HttpServletResponse servletResponse) throws ServletException, IOException, OAuthException, URISyntaxException {
 OAuthMessage requestMessage = OAuthServlet.getMessage(servletRequest, null);
 OAuthEntry entry = getValidatedEntry(requestMessage);
 if (entry == null)
  throw new OAuthProblemException(OAuth.Problems.TOKEN_REJECTED);
 if (entry.getCallbackToken() != null) {
  // We're using the fixed protocol
  String clientCallbackToken = requestMessage.getParameter(OAuth.OAUTH_VERIFIER);
  if (!entry.getCallbackToken().equals(clientCallbackToken)) {
   dataStore.disableToken(entry);
   servletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "This token is not authorized");
   return;
  }
 } else if (!entry.isAuthorized()) {
  // Old protocol.  Catch consumers trying to convert a token to one that's not authorized
  dataStore.disableToken(entry);
  servletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "This token is not authorized");
  return;
 }
 // turn request token into access token
 OAuthEntry accessEntry = dataStore.convertToAccessToken(entry);
 sendResponse(servletResponse, OAuth.newList(
         OAuth.OAUTH_TOKEN, accessEntry.getToken(),
         OAuth.OAUTH_TOKEN_SECRET, accessEntry.getTokenSecret(),
         "user_id", entry.getUserId()));
}

代码示例来源:origin: com.lmco.shindig/shindig-gadgets

/**
 * Sends OAuth request token and access token messages.
 */
private OAuthMessage sendOAuthMessage(HttpRequest request)
  throws OAuthRequestException, OAuthProtocolException {
 HttpResponse response = fetchFromServer(request);
 checkForProtocolProblem(response);
 OAuthMessage reply = new OAuthMessage(null, null, null);
 reply.addParameters(OAuth.decodeForm(response.getResponseAsString()));
 reply = parseAuthHeader(reply, response);
 if (OAuthUtil.getParameter(reply, OAuth.OAUTH_TOKEN) == null) {
  throw new OAuthRequestException(OAuthError.MISSING_OAUTH_PARAMETER,
    OAuth.OAUTH_TOKEN);
 }
 if (OAuthUtil.getParameter(reply, OAuth.OAUTH_TOKEN_SECRET) == null) {
  throw new OAuthRequestException(OAuthError.MISSING_OAUTH_PARAMETER,
    OAuth.OAUTH_TOKEN_SECRET);
 }
 return reply;
}

代码示例来源:origin: org.apache.shindig/shindig-gadgets

public List<OAuth.Parameter> getParsedQuery() {
 if (decodedQuery == null) {
  if (query != null) {
   decodedQuery = OAuth.decodeForm(query);
  } else {
   decodedQuery = Lists.newArrayList();
  }
 }
 return decodedQuery;
}

代码示例来源:origin: org.gatein.shindig/shindig-common

/**
  * @param tokenEndpoint true if this is a request token or access token request.  We don't check
  * oauth_body_hash on those.
  */
 public static SignatureType getSignatureType(boolean tokenEndpoint, String contentType) {
  if (OAuth.isFormEncoded(contentType)) {
   return SignatureType.URL_AND_FORM_PARAMS;
  }
  if (tokenEndpoint) {
   return SignatureType.URL_ONLY;
  }
  return SignatureType.URL_AND_BODY_HASH;
 }
}

代码示例来源:origin: org.gatein.shindig/shindig-gadgets

static String getAuthorizationHeader(List<Map.Entry<String, String>> oauthParams) {
 StringBuilder result = new StringBuilder("OAuth ");
 boolean first = true;
 for (Map.Entry<String, String> parameter : oauthParams) {
  if (!first) {
   result.append(", ");
  } else {
   first = false;
  }
  result.append(OAuth.percentEncode(parameter.getKey()))
     .append("=\"")
     .append(OAuth.percentEncode(parameter.getValue()))
     .append('"');
 }
 return result.toString();
}

代码示例来源:origin: apache/cxf

private static String doGetAuthorizationHeader(OAuthAccessor accessor,
    String method, String requestURI, Map<String, String> parameters) {
  try {
    OAuthMessage msg = accessor.newRequestMessage(method, requestURI, parameters.entrySet());
    StringBuilder sb = new StringBuilder();
    sb.append(msg.getAuthorizationHeader(null));
    for (Map.Entry<String, String> entry : parameters.entrySet()) {
      if (!entry.getKey().startsWith("oauth_")) {
        sb.append(", ");
        sb.append(OAuth.percentEncode(entry.getKey())).append("=\"");
        sb.append(OAuth.percentEncode(entry.getValue())).append('"');
      }
    }
    return sb.toString();
  } catch (Exception ex) {
    throw new ProcessingException(ex);
  }
}

代码示例来源:origin: apache/incubator-wave

OAuthMessage message = new HttpRequestMessage(req, req.getRequestURL().toString());
String username = OAuth.decodePercent(message.getConsumerKey());

相关文章