本文整理汇总了Java中net.oauth.OAuthMessage.addRequiredParameters方法的典型用法代码示例。如果您正苦于以下问题:Java OAuthMessage.addRequiredParameters方法的具体用法?Java OAuthMessage.addRequiredParameters怎么用?Java OAuthMessage.addRequiredParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.oauth.OAuthMessage
的用法示例。
在下文中一共展示了OAuthMessage.addRequiredParameters方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: signParameters
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
@Override
public Map<String, String> signParameters(Map<String, String> parameters, String key, String secret, String url, String method) throws LtiSigningException {
OAuthMessage oam = new OAuthMessage(method, url, parameters.entrySet());
OAuthConsumer cons = new OAuthConsumer(null, key, secret, null);
OAuthAccessor acc = new OAuthAccessor(cons);
try {
oam.addRequiredParameters(acc);
Map<String, String> signedParameters = new HashMap<>();
for(Map.Entry<String, String> param : oam.getParameters()){
signedParameters.put(param.getKey(), param.getValue());
}
return signedParameters;
} catch (OAuthException |IOException |URISyntaxException e) {
throw new LtiSigningException("Error signing LTI request.", e);
}
}
示例2: authenticate
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
public Header authenticate(Credentials credentials, HttpRequest request)
throws AuthenticationException {
String uri;
String method;
HttpUriRequest uriRequest = getHttpUriRequest(request);
if (uriRequest != null) {
uri = uriRequest.getURI().toString();
method = uriRequest.getMethod();
} else {
// Some requests don't include the server name in the URL.
RequestLine requestLine = request.getRequestLine();
uri = requestLine.getUri();
method = requestLine.getMethod();
}
try {
OAuthMessage message = new OAuthMessage(method, uri, null);
OAuthAccessor accessor = getAccessor(credentials);
message.addRequiredParameters(accessor);
String authorization = message.getAuthorizationHeader(getRealm());
return new BasicHeader("Authorization", authorization);
} catch (Exception e) {
throw new AuthenticationException(null, e);
}
}
示例3: authenticate
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
public Header authenticate(Credentials credentials, HttpRequest request) throws AuthenticationException {
String uri;
String method;
HttpUriRequest uriRequest = getHttpUriRequest(request);
if (uriRequest != null) {
uri = uriRequest.getURI().toString();
method = uriRequest.getMethod();
} else {
// Some requests don't include the server name in the URL.
RequestLine requestLine = request.getRequestLine();
uri = requestLine.getUri();
method = requestLine.getMethod();
}
try {
OAuthMessage message = new OAuthMessage(method, uri, null);
OAuthAccessor accessor = getAccessor(credentials);
message.addRequiredParameters(accessor);
String authorization = message.getAuthorizationHeader(getRealm());
return new BasicHeader("Authorization", authorization);
} catch (Exception e) {
throw new AuthenticationException(null, e);
}
}
示例4: getRequestURL
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
private String getRequestURL(String consumerKey, String consumerSecret) throws Exception {
OAuthMessage message = new OAuthMessage("GET", RequestURL, Collections.<Map.Entry>emptyList());
OAuthConsumer consumer = new OAuthConsumer("http://callback.net", consumerKey, consumerSecret, null);
OAuthAccessor accessor = new OAuthAccessor(consumer);
message.addParameter(OAuth.OAUTH_CALLBACK, consumer.callbackURL);
message.addRequiredParameters(accessor);
return OAuth.addParameters(message.URL, message.getParameters());
}
示例5: getAccessURL
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
private String getAccessURL(String consumerKey, String consumerSecret, String requestKey, String requestSecret, String verifier) throws Exception {
OAuthMessage message = new OAuthMessage("GET", AccessURL, Collections.<Map.Entry>emptyList());
OAuthConsumer consumer = new OAuthConsumer("http://callback.net", consumerKey, consumerSecret, null);
OAuthAccessor accessor = new OAuthAccessor(consumer);
accessor.requestToken = requestKey;
accessor.tokenSecret = requestSecret;
message.addParameter(OAuthUtils.OAUTH_VERIFIER_PARAM, verifier);
message.addParameter(OAuth.OAUTH_TOKEN, requestKey);
message.addRequiredParameters(accessor);
return OAuth.addParameters(message.URL, message.getParameters());
}
示例6: getProtectedURL
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
private String getProtectedURL(String url, String consumerKey, String consumerSecret, String accessKey, String accessSecret) throws Exception {
OAuthMessage message = new OAuthMessage("GET", ProtectedURL+url, Collections.<Map.Entry>emptyList());
OAuthConsumer consumer = new OAuthConsumer("http://callback.net", consumerKey, consumerSecret, null);
OAuthAccessor accessor = new OAuthAccessor(consumer);
accessor.accessToken = accessKey;
accessor.tokenSecret = accessSecret;
message.addParameter(OAuth.OAUTH_TOKEN, accessKey);
message.addRequiredParameters(accessor);
return OAuth.addParameters(message.URL, message.getParameters());
}
示例7: getPushMessageURL
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private String getPushMessageURL(String callbackURI, String messageSenderId)
throws Exception {
OAuthMessage message = new OAuthMessage("POST", callbackURI, Collections.<Map.Entry>emptyList());
OAuthConsumer consumer = new OAuthConsumer(null, messageSenderId,
getConsumerSecret(messageSenderId), null);
OAuthAccessor accessor = new OAuthAccessor(consumer);
message.addRequiredParameters(accessor);
return OAuth.addParameters(message.URL, message.getParameters());
}
示例8: getRequestURL
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
private String getRequestURL(String consumerKey, String consumerSecret,
String callbackURI, String scope, String permission) throws Exception {
OAuthMessage message = new OAuthMessage("GET", RequestTokenURL, Collections.<Map.Entry>emptyList());
OAuthConsumer consumer = new OAuthConsumer(callbackURI, consumerKey, consumerSecret, null);
OAuthAccessor accessor = new OAuthAccessor(consumer);
message.addParameter(OAuth.OAUTH_CALLBACK, consumer.callbackURL);
message.addParameter("xoauth_scope", scope);
message.addParameter("xoauth_permission", permission);
message.addRequiredParameters(accessor);
return OAuth.addParameters(message.URL, message.getParameters());
}
示例9: getAccessURL
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
private String getAccessURL(String consumerKey, String consumerSecret, String requestKey, String requestSecret, String verifier) throws Exception {
OAuthMessage message = new OAuthMessage("GET", AccessTokenURL, Collections.<Map.Entry>emptyList());
OAuthConsumer consumer = new OAuthConsumer("http://callback.net", consumerKey, consumerSecret, null);
OAuthAccessor accessor = new OAuthAccessor(consumer);
accessor.requestToken = requestKey;
accessor.tokenSecret = requestSecret;
message.addParameter(OAuthUtils.OAUTH_VERIFIER_PARAM, verifier);
message.addParameter(OAuth.OAUTH_TOKEN, requestKey);
message.addRequiredParameters(accessor);
return OAuth.addParameters(message.URL, message.getParameters());
}
示例10: getEndUserURL
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
private String getEndUserURL(String url, String consumerKey, String consumerSecret, String accessKey, String accessSecret) throws Exception {
OAuthMessage message = new OAuthMessage("GET", endUserScope + url, Collections.<Map.Entry>emptyList());
OAuthConsumer consumer = new OAuthConsumer("http://callback.net", consumerKey, consumerSecret, null);
OAuthAccessor accessor = new OAuthAccessor(consumer);
accessor.accessToken = accessKey;
accessor.tokenSecret = accessSecret;
message.addParameter(OAuth.OAUTH_TOKEN, accessKey);
message.addRequiredParameters(accessor);
return OAuth.addParameters(message.URL, message.getParameters());
}
示例11: createOAuthUrlString
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
/**
* Creates a URL that contains the necessary OAuth query parameters for the
* given JSON string.
*
* The required OAuth parameters are:
* <ul>
* <li>oauth_body_hash</li>
* <li>oauth_consumer_key</li>
* <li>oauth_signature_method</li>
* <li>oauth_timestamp</li>
* <li>oauth_nonce</li>
* <li>oauth_version</li>
* <li>oauth_signature</li>
* </ul>
*
* @param method the HTTP method.
* @param jsonBody the JSON string to construct the URL from.
* @param rpcServerUrl the URL of the handler that services the JSON-RPC
* request.
* @param accessor the OAuth accessor used to create the signed string.
* @return a URL for the given JSON string, and the required OAuth parameters.
*/
public static String createOAuthUrlString(String method,
String jsonBody, String rpcServerUrl, OAuthAccessor accessor, List<SimpleEntry<String, String>> params)
throws IOException, URISyntaxException, OAuthException {
OAuthMessage message =
new OAuthMessage(method, rpcServerUrl, params);
if (jsonBody != null) {
// Compute the hash of the body.
byte[] rawBody = jsonBody.getBytes(UTF_8);
byte[] hash = DigestUtils.sha(rawBody);
byte[] encodedHash = Base64.encodeBase64(hash);
message.addParameter(OAUTH_BODY_HASH, new String(encodedHash, UTF_8));
}
// Add other parameters.
message.addRequiredParameters(accessor);
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Signature base string: " + OAuthSignatureMethod.getBaseString(message));
}
// Construct the resulting URL.
StringBuilder sb = new StringBuilder(rpcServerUrl);
char connector = '?';
for (Map.Entry<String, String> p : message.getParameters()) {
if (!p.getKey().equals(jsonBody)) {
sb.append(connector);
sb.append(URLEncoder.encode(p.getKey(), UTF_8));
sb.append('=');
sb.append(URLEncoder.encode(p.getValue(), UTF_8));
connector = '&';
}
}
return sb.toString();
}
示例12: buildResponse
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
/**
* Builds an XOAUTH SASL client response.
*
* @param userEmail The email address of the user, for example
* "[email protected]".
* @param protocol The XoauthProtocol for which to generate an authentication
* string.
* @param tokenAndTokenSecret The OAuth token and token_secret.
* @param consumer The OAuth consumer that is trying to authenticate.
*
* @return A byte array containing the auth string suitable for being returned
* from {@code SaslClient.evaluateChallenge}. It needs to be base64-encoded
* before actually being sent over the network.
*/
public byte[] buildResponse(String userEmail,
XoauthProtocol protocol,
String oauthToken,
String oauthTokenSecret,
OAuthConsumer consumer)
throws IOException, OAuthException, URISyntaxException {
OAuthAccessor accessor = new OAuthAccessor(consumer);
accessor.tokenSecret = oauthTokenSecret;
Map<String, String> parameters = new HashMap<String, String>();
parameters.put(OAuth.OAUTH_SIGNATURE_METHOD, "HMAC-SHA1");
parameters.put(OAuth.OAUTH_TOKEN, oauthToken);
String url = String.format("https://mail.google.com/mail/b/%s/%s/",
userEmail,
protocol.getName());
OAuthMessage message = new OAuthMessage(
"GET",
url,
parameters.entrySet());
message.addRequiredParameters(accessor);
StringBuilder authString = new StringBuilder();
authString.append("GET ");
authString.append(url);
authString.append(" ");
int i = 0;
for (Map.Entry<String, String> entry : message.getParameters()) {
if (i++ > 0) {
authString.append(",");
}
authString.append(OAuth.percentEncode(entry.getKey()));
authString.append("=\"");
authString.append(OAuth.percentEncode(entry.getValue()));
authString.append("\"");
}
return authString.toString().getBytes();
}
示例13: buildOauthMessage
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
private static OAuthMessage buildOauthMessage(String consumerKey, String comsumerSecret, String scope, Map<String, String> params)
throws OAuthException, IOException, URISyntaxException {
OAuthMessage message = new OAuthMessage(OAuthMessage.GET, SCOPE, params.entrySet());
OAuthConsumer consumer = new OAuthConsumer(null, consumerKey, comsumerSecret, null);
OAuthAccessor accessor = new OAuthAccessor(consumer);
message.addRequiredParameters(accessor);
return message;
}
示例14: createOAuthUrlString
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
/**
* Creates a URL that contains the necessary OAuth query parameters for the
* given JSON string.
*
* The required OAuth parameters are:
* <ul>
* <li>oauth_body_hash</li>
* <li>oauth_consumer_key</li>
* <li>oauth_signature_method</li>
* <li>oauth_timestamp</li>
* <li>oauth_nonce</li>
* <li>oauth_version</li>
* <li>oauth_signature</li>
* </ul>
*
* @param jsonBody the JSON string to construct the URL from.
* @param rpcServerUrl the URL of the handler that services the JSON-RPC
* request.
* @param accessor the OAuth accessor used to create the signed string.
* @return a URL for the given JSON string, and the required OAuth parameters.
*/
public static String createOAuthUrlString(
String jsonBody, String rpcServerUrl, OAuthAccessor accessor)
throws IOException, URISyntaxException, OAuthException {
OAuthMessage message =
new OAuthMessage(POST, rpcServerUrl, Collections.<SimpleEntry<String, String>>emptyList());
// Compute the hash of the body.
byte[] rawBody = jsonBody.getBytes(UTF_8);
byte[] hash = DigestUtils.sha(rawBody);
byte[] encodedHash = Base64.encodeBase64(hash);
message.addParameter(OAUTH_BODY_HASH, new String(encodedHash, UTF_8));
// Add other parameters.
message.addRequiredParameters(accessor);
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Signature base string: " + OAuthSignatureMethod.getBaseString(message));
}
// Construct the resulting URL.
StringBuilder sb = new StringBuilder(rpcServerUrl);
char connector = '?';
for (Map.Entry<String, String> p : message.getParameters()) {
if (!p.getKey().equals(jsonBody)) {
sb.append(connector);
sb.append(URLEncoder.encode(p.getKey(), UTF_8));
sb.append('=');
sb.append(URLEncoder.encode(p.getValue(), UTF_8));
connector = '&';
}
}
return sb.toString();
}