本文整理汇总了Java中net.oauth.OAuthMessage.getParameter方法的典型用法代码示例。如果您正苦于以下问题:Java OAuthMessage.getParameter方法的具体用法?Java OAuthMessage.getParameter怎么用?Java OAuthMessage.getParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.oauth.OAuthMessage
的用法示例。
在下文中一共展示了OAuthMessage.getParameter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAccessToken
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
/**
* Get an access token from the service provider, in exchange for an
* authorized request token.
*
* @param accessor
* should contain a non-null requestToken and tokenSecret, and a
* consumer that contains a consumerKey and consumerSecret. Also,
* accessor.consumer.serviceProvider.accessTokenURL should be the
* URL (determined by the service provider) for getting an access
* token.
* @param httpMethod
* typically OAuthMessage.POST or OAuthMessage.GET, or null to
* use the default method.
* @param parameters
* additional parameters for this request, or null to indicate
* that there are no additional parameters.
* @throws OAuthProblemException
* the HTTP response status code was not 200 (OK)
*/
@SuppressWarnings("rawtypes")
public OAuthMessage getAccessToken(OAuthAccessor accessor, String httpMethod,
Collection<? extends Map.Entry> parameters) throws IOException, OAuthException, URISyntaxException {
if (accessor.requestToken != null) {
if (parameters == null) {
parameters = OAuth.newList(OAuth.OAUTH_TOKEN, accessor.requestToken);
} else if (!OAuth.newMap(parameters).containsKey(OAuth.OAUTH_TOKEN)) {
List<Map.Entry> p = new ArrayList<Map.Entry>(parameters);
p.add(new OAuth.Parameter(OAuth.OAUTH_TOKEN, accessor.requestToken));
parameters = p;
}
}
OAuthMessage response = invoke(accessor, httpMethod,
accessor.consumer.serviceProvider.accessTokenURL, parameters);
response.requireParameters(OAuth.OAUTH_TOKEN, OAuth.OAUTH_TOKEN_SECRET);
accessor.accessToken = response.getParameter(OAuth.OAUTH_TOKEN);
accessor.tokenSecret = response.getParameter(OAuth.OAUTH_TOKEN_SECRET);
return response;
}
示例2: authenticate
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
@Override
public String authenticate(HttpServletRequest request) throws IOException, OAuthException,
URISyntaxException {
OAuthMessage message = OAuthServlet.getMessage(request, null);
// Retrieve and set the user info with the OAuth parameters
Map<UserInfoProperties, Object> oauthParams = new HashMap<UserInfoProperties, Object>();
oauthParams.put(UserInfoProperties.EMAIL,
urlDecode(message.getParameter("opensocial_viewer_id")));
oauthParams.put(UserInfoProperties.VIEWER_ID,
urlDecode(message.getParameter("opensocial_viewer_id")));
oauthParams.put(UserInfoProperties.OWNER_EMAIL,
urlDecode(message.getParameter("opensocial_owner_id")));
oauthParams.put(UserInfoProperties.OWNER_ID,
urlDecode(message.getParameter("opensocial_owner_id")));
oauthParams.put(UserInfoProperties.APPLICATION_ID, message.getParameter("opensocial_app_id"));
oauthParams.put(UserInfoProperties.APPLICATION_URL, message.getParameter("opensocial_app_url"));
UserInfo userInfo = new HashMapBasedUserInfo(oauthParams);
request.setAttribute(AbstractManagedCollectionAdapter.USER_INFO, userInfo);
return message.getParameter("opensocial_viewer_id");
}
示例3: getAccessToken
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
/**
* Get an access token from the service provider, in exchange for an
* authorized request token.
*
* @param accessor
* should contain a non-null requestToken and tokenSecret, and a
* consumer that contains a consumerKey and consumerSecret. Also,
* accessor.consumer.serviceProvider.accessTokenURL should be the
* URL (determined by the service provider) for getting an access
* token.
* @param httpMethod
* typically OAuthMessage.POST or OAuthMessage.GET, or null to
* use the default method.
* @param parameters
* additional parameters for this request, or null to indicate
* that there are no additional parameters.
* @return the response from the service provider
* @throws OAuthProblemException
* the HTTP response status code was not 200 (OK)
*/
@SuppressWarnings("rawtypes")
public OAuthMessage getAccessToken(OAuthAccessor accessor,
String httpMethod, Collection<? extends Map.Entry> parameters)
throws IOException, OAuthException, URISyntaxException {
if (accessor.requestToken != null) {
if (parameters == null) {
parameters = OAuth.newList(OAuth.OAUTH_TOKEN,
accessor.requestToken);
} else if (!OAuth.newMap(parameters).containsKey(OAuth.OAUTH_TOKEN)) {
List<Map.Entry> p = new ArrayList<Map.Entry>(parameters);
p.add(new OAuth.Parameter(OAuth.OAUTH_TOKEN,
accessor.requestToken));
parameters = p;
}
}
OAuthMessage response = invoke(accessor, httpMethod,
accessor.consumer.serviceProvider.accessTokenURL, parameters);
response.requireParameters(OAuth.OAUTH_TOKEN, OAuth.OAUTH_TOKEN_SECRET);
accessor.accessToken = response.getParameter(OAuth.OAUTH_TOKEN);
accessor.tokenSecret = response.getParameter(OAuth.OAUTH_TOKEN_SECRET);
return response;
}
示例4: validateVersion
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
private void validateVersion(OAuthMessage message) throws net.oauth.OAuthException, IOException
{
// Checks OAuth is version 1
String versionString = message.getParameter(OAuth.OAUTH_VERSION);
if( versionString != null )
{
double version = Double.parseDouble(versionString);
if( version < 1.0 || 1.0 < version )
{
OAuthProblemException problem = new OAuthProblemException(OAuth.Problems.VERSION_REJECTED);
problem.setParameter(OAuth.Problems.OAUTH_ACCEPTABLE_VERSIONS, 1.0 + "-" + 1.0);
throw problem;
}
}
}
示例5: validateNonce
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
/**
* Check if Nonce has been used previously and throw an exception if it has
* otherwise store it
*
* @throws IOException, net.oauth.OAuthException
*/
private void validateNonce(OAuthMessage message) throws net.oauth.OAuthException, IOException
{
// Check if OAuth nonce is used...
String nonce = message.getParameter(OAuth.OAUTH_NONCE);
if( oAuthNonceCache.get(nonce).isPresent() )
{
throw new OAuthProblemException(OAuth.Problems.NONCE_USED);
}
oAuthNonceCache.put(nonce, Boolean.TRUE);
}
示例6: getRequestToken
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
/** Get a fresh request token from the service provider.
*
* @param accessor
* should contain a consumer that contains a non-null consumerKey
* and consumerSecret. Also,
* accessor.consumer.serviceProvider.requestTokenURL should be
* the URL (determined by the service provider) for getting a
* request token.
* @param httpMethod
* typically OAuthMessage.POST or OAuthMessage.GET, or null to
* use the default method.
* @param parameters
* additional parameters for this request, or null to indicate
* that there are no additional parameters.
* @throws OAuthProblemException
* the HTTP response status code was not 200 (OK)
*/
@SuppressWarnings("rawtypes")
public void getRequestToken(OAuthAccessor accessor, String httpMethod,
Collection<? extends Map.Entry> parameters) throws IOException,
OAuthException, URISyntaxException {
accessor.accessToken = null;
accessor.tokenSecret = null;
{
// This code supports the 'Variable Accessor Secret' extension
// described in http://oauth.pbwiki.com/AccessorSecret
Object accessorSecret = accessor
.getProperty(OAuthConsumer.ACCESSOR_SECRET);
if (accessorSecret != null) {
List<Map.Entry> p = (parameters == null) ? new ArrayList<Map.Entry>(
1)
: new ArrayList<Map.Entry>(parameters);
p.add(new OAuth.Parameter("oauth_accessor_secret",
accessorSecret.toString()));
parameters = p;
// But don't modify the caller's parameters.
}
}
OAuthMessage response = invoke(accessor, httpMethod,
accessor.consumer.serviceProvider.requestTokenURL, parameters);
accessor.requestToken = response.getParameter(OAuth.OAUTH_TOKEN);
accessor.tokenSecret = response.getParameter(OAuth.OAUTH_TOKEN_SECRET);
response.requireParameters(OAuth.OAUTH_TOKEN, OAuth.OAUTH_TOKEN_SECRET);
}
示例7: authenticate
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
@Override
public String authenticate(HttpServletRequest request) throws IOException, OAuthException,
URISyntaxException {
OAuthMessage message = OAuthServlet.getMessage(request, null);
String consumerKey = message.getConsumerKey();
String signatureMethod = message.getSignatureMethod();
OAuthConsumer consumer = keyManager.getOAuthConsumer(provider, consumerKey, signatureMethod);
if (null == consumer) {
logger.info("signed fetch verification failed: consumer is null");
throw new OAuthException("Unauthorized");
}
OAuthAccessor accessor = new OAuthAccessor(consumer);
message.validateMessage(accessor, validator);
String viewerEmail = message.getParameter("opensocial_viewer_email");
if (viewerEmail == null) {
logger.info("signed fetch verification failed: viewer email is null");
throw new OAuthException("Missing user identity opensocial_viewer_email");
}
// Retrieve and set the user info with the OAuth parameters
Map<UserInfoProperties, Object> oauthParams = new HashMap<UserInfoProperties, Object>();
oauthParams.put(UserInfoProperties.EMAIL, urlDecode(viewerEmail));
oauthParams.put(UserInfoProperties.VIEWER_ID, message.getParameter("opensocial_viewer_id"));
oauthParams.put(UserInfoProperties.OWNER_EMAIL,
urlDecode(message.getParameter("opensocial_owner_email")));
oauthParams.put(UserInfoProperties.OWNER_ID, message.getParameter("opensocial_owner_id"));
oauthParams.put(UserInfoProperties.APPLICATION_ID, message.getParameter("opensocial_app_id"));
oauthParams.put(UserInfoProperties.APPLICATION_URL, message.getParameter("opensocial_app_url"));
UserInfo userInfo = new HashMapBasedUserInfo(oauthParams);
request.setAttribute(AbstractManagedCollectionAdapter.USER_INFO, userInfo);
logger.info("signed fetch verified: " + viewerEmail);
return message.getParameter("opensocial_viewer_id");
}
示例8: getRequestToken
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
/** Get a fresh request token from the service provider.
*
* @param accessor
* should contain a consumer that contains a non-null consumerKey
* and consumerSecret. Also,
* accessor.consumer.serviceProvider.requestTokenURL should be
* the URL (determined by the service provider) for getting a
* request token.
* @param httpMethod
* typically OAuthMessage.POST or OAuthMessage.GET, or null to
* use the default method.
* @param parameters
* additional parameters for this request, or null to indicate
* that there are no additional parameters.
* @throws OAuthProblemException
* the HTTP response status code was not 200 (OK)
*/
public void getRequestToken(OAuthAccessor accessor, String httpMethod,
Collection<? extends Map.Entry> parameters) throws IOException,
OAuthException, URISyntaxException {
accessor.accessToken = null;
accessor.tokenSecret = null;
{
// This code supports the 'Variable Accessor Secret' extension
// described in http://oauth.pbwiki.com/AccessorSecret
Object accessorSecret = accessor
.getProperty(OAuthConsumer.ACCESSOR_SECRET);
if (accessorSecret != null) {
List<Map.Entry> p = (parameters == null) ? new ArrayList<Map.Entry>(
1)
: new ArrayList<Map.Entry>(parameters);
p.add(new OAuth.Parameter("oauth_accessor_secret",
accessorSecret.toString()));
parameters = p;
// But don't modify the caller's parameters.
}
}
OAuthMessage response = invoke(accessor, httpMethod,
accessor.consumer.serviceProvider.requestTokenURL, parameters);
accessor.requestToken = response.getParameter(OAuth.OAUTH_TOKEN);
accessor.tokenSecret = response.getParameter(OAuth.OAUTH_TOKEN_SECRET);
response.requireParameters(OAuth.OAUTH_TOKEN, OAuth.OAUTH_TOKEN_SECRET);
}
示例9: createRequestToken
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
private void createRequestToken(ContextResource contextResource) throws IOException, OAuthException, URISyntaxException {
OAuthMessage requestMessage = getOAuthMessage(contextResource.getRequest());
String consumerKey = requestMessage.getConsumerKey();
if (consumerKey == null) {
OAuthProblemException e = new OAuthProblemException(OAuth.Problems.PARAMETER_ABSENT);
e.setParameter(OAuth.Problems.OAUTH_PARAMETERS_ABSENT, OAuth.OAUTH_CONSUMER_KEY);
throw e;
}
OAuthConsumer consumer = dataStore.getConsumer(consumerKey);
if (consumer == null) {
throw new OAuthProblemException(OAuth.Problems.CONSUMER_KEY_UNKNOWN);
}
OAuthAccessor accessor = new OAuthAccessor(consumer);
VALIDATOR.validateMessage(requestMessage, accessor);
String callback = requestMessage.getParameter(OAuth.OAUTH_CALLBACK);
if (callback == null) {
// see if the consumer has a callback
callback = consumer.callbackURL;
}
if (callback == null) {
callback = "oob";
}
// generate request_token and secret
OAuthEntry entry = dataStore.generateRequestToken(consumerKey, 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) {
responseParams.add(new Parameter(OAuth.OAUTH_CALLBACK_CONFIRMED, "true"));
}
sendResponse(contextResource, responseParams);
}
示例10: createAccessToken
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
private void createAccessToken(ContextResource contextResource) throws ServletException, IOException, OAuthException, URISyntaxException {
OAuthMessage requestMessage = getOAuthMessage(getRequest());
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);
sendError(contextResource, Status.CLIENT_ERROR_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);
sendError(contextResource, Status.CLIENT_ERROR_FORBIDDEN, "This token is not authorized");
return;
}
// turn request token into access token
OAuthEntry accessEntry = dataStore.convertToAccessToken(entry);
sendResponse(contextResource, OAuth.newList(OAuth.OAUTH_TOKEN, accessEntry.getToken(), OAuth.OAUTH_TOKEN_SECRET,
accessEntry.getTokenSecret(), "user_id", entry.getUserId()));
}
示例11: getRequestTokenResponse
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
/**
* Get a fresh request token from the service provider.
*
* @param accessor
* should contain a consumer that contains a non-null consumerKey
* and consumerSecret. Also,
* accessor.consumer.serviceProvider.requestTokenURL should be
* the URL (determined by the service provider) for getting a
* request token.
* @param httpMethod
* typically OAuthMessage.POST or OAuthMessage.GET, or null to
* use the default method.
* @param parameters
* additional parameters for this request, or null to indicate
* that there are no additional parameters.
* @return the response from the service provider
* @throws OAuthProblemException
* the HTTP response status code was not 200 (OK)
*/
@SuppressWarnings("rawtypes")
public OAuthMessage getRequestTokenResponse(OAuthAccessor accessor,
String httpMethod, Collection<? extends Map.Entry> parameters)
throws IOException, OAuthException, URISyntaxException {
accessor.accessToken = null;
accessor.tokenSecret = null;
{
// This code supports the 'Variable Accessor Secret' extension
// described in http://oauth.pbwiki.com/AccessorSecret
Object accessorSecret = accessor
.getProperty(OAuthConsumer.ACCESSOR_SECRET);
if (accessorSecret != null) {
List<Map.Entry> p = (parameters == null) ? new ArrayList<Map.Entry>(
1) : new ArrayList<Map.Entry>(parameters);
p.add(new OAuth.Parameter("oauth_accessor_secret",
accessorSecret.toString()));
parameters = p;
// But don't modify the caller's parameters.
}
}
OAuthMessage response = invoke(accessor, httpMethod,
accessor.consumer.serviceProvider.requestTokenURL, parameters);
accessor.requestToken = response.getParameter(OAuth.OAUTH_TOKEN);
accessor.tokenSecret = response.getParameter(OAuth.OAUTH_TOKEN_SECRET);
response.requireParameters(OAuth.OAUTH_TOKEN, OAuth.OAUTH_TOKEN_SECRET);
return response;
}
示例12: getAccessToken
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
/**
* Get a fresh access token from the service provider.
* @throws IOException
* @throws URISyntaxException
*
* @throws RedirectException
* to obtain authorization
*/
private static void getAccessToken(HttpServletRequest request,
CookieMap cookies, OAuthAccessor accessor)
throws OAuthException, IOException, URISyntaxException
{
final String consumerName = (String) accessor.consumer.getProperty("name");
final String callbackURL = getCallbackURL(request, consumerName);
List<OAuth.Parameter> parameters = OAuth.newList(OAuth.OAUTH_CALLBACK, callbackURL);
// Google needs to know what you intend to do with the access token:
Object scope = accessor.consumer.getProperty("request.scope");
if (scope != null) {
parameters.add(new OAuth.Parameter("scope", scope.toString()));
}
OAuthMessage response = CLIENT.getRequestTokenResponse(accessor, null, parameters);
cookies.put(consumerName + ".requestToken", accessor.requestToken);
cookies.put(consumerName + ".tokenSecret", accessor.tokenSecret);
String authorizationURL = accessor.consumer.serviceProvider.userAuthorizationURL;
if (authorizationURL.startsWith("/")) {
authorizationURL = (new URL(new URL(request.getRequestURL()
.toString()), request.getContextPath() + authorizationURL))
.toString();
}
authorizationURL = OAuth.addParameters(authorizationURL //
, OAuth.OAUTH_TOKEN, accessor.requestToken);
if (response.getParameter(OAuth.OAUTH_CALLBACK_CONFIRMED) == null) {
authorizationURL = OAuth.addParameters(authorizationURL //
, OAuth.OAUTH_CALLBACK, callbackURL);
}
throw new RedirectException(authorizationURL);
}
示例13: processRequest
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
public void processRequest(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
try {
OAuthMessage requestMessage = OAuthServlet.getMessage(request, null);
OAuthConsumer consumer = SampleOAuthProvider.getConsumer(requestMessage);
OAuthAccessor accessor = new OAuthAccessor(consumer);
SampleOAuthProvider.VALIDATOR.validateMessage(requestMessage, accessor);
{
// Support the 'Variable Accessor Secret' extension
// described in http://oauth.pbwiki.com/AccessorSecret
String secret = requestMessage.getParameter("oauth_accessor_secret");
if (secret != null) {
accessor.setProperty(OAuthConsumer.ACCESSOR_SECRET, secret);
}
}
// generate request_token and secret
SampleOAuthProvider.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){
SampleOAuthProvider.handleException(e, request, response, true);
}
}
示例14: getRequestTokenResponse
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
/** Get a fresh request token from the service provider.
*
* @param accessor
* should contain a consumer that contains a non-null consumerKey
* and consumerSecret. Also,
* accessor.consumer.serviceProvider.requestTokenURL should be
* the URL (determined by the service provider) for getting a
* request token.
* @param httpMethod
* typically OAuthMessage.POST or OAuthMessage.GET, or null to
* use the default method.
* @param parameters
* additional parameters for this request, or null to indicate
* that there are no additional parameters.
* @return the response from the service provider
* @throws OAuthProblemException
* the HTTP response status code was not 200 (OK)
*/
public OAuthMessage getRequestTokenResponse(OAuthAccessor accessor, String httpMethod,
Collection<? extends Map.Entry> parameters)
throws IOException, OAuthException, URISyntaxException
{
accessor.accessToken = null;
accessor.tokenSecret = null;
{
// This code supports the 'Variable Accessor Secret' extension
// described in http://oauth.pbwiki.com/AccessorSecret
Object accessorSecret = accessor
.getProperty(OAuthConsumer.ACCESSOR_SECRET);
if (accessorSecret != null) {
List<Map.Entry> p = (parameters == null) ? new ArrayList<Map.Entry>(
1)
: new ArrayList<Map.Entry>(parameters);
p.add(new OAuth.Parameter("oauth_accessor_secret",
accessorSecret.toString()));
parameters = p;
// But don't modify the caller's parameters.
}
}
OAuthMessage response = invoke(accessor, httpMethod,
accessor.consumer.serviceProvider.requestTokenURL, parameters);
accessor.requestToken = response.getParameter(OAuth.OAUTH_TOKEN);
accessor.tokenSecret = response.getParameter(OAuth.OAUTH_TOKEN_SECRET);
response.requireParameters(OAuth.OAUTH_TOKEN, OAuth.OAUTH_TOKEN_SECRET);
return response;
}
示例15: getParameter
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
public static String getParameter(OAuthMessage message, String name) {
try {
return message.getParameter(name);
} catch (IOException e) {
throw new RuntimeException(e);
}
}