当前位置: 首页>>代码示例>>Java>>正文


Java OAuth类代码示例

本文整理汇总了Java中net.oauth.OAuth的典型用法代码示例。如果您正苦于以下问题:Java OAuth类的具体用法?Java OAuth怎么用?Java OAuth使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


OAuth类属于net.oauth包,在下文中一共展示了OAuth类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createLaunchParameters

import net.oauth.OAuth; //导入依赖的package包/类
private OAuthMessage createLaunchParameters(String consumerKey, String secret, String url, String bodyHash)
{
	final String nonce = UUID.randomUUID().toString();
	final String timestamp = Long.toString(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()));

	final OAuthMessage message = new OAuthMessage(OAuthMessage.POST, url, null);
	message.addParameter(OAuth.OAUTH_CONSUMER_KEY, consumerKey);
	message.addParameter(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.HMAC_SHA1);
	message.addParameter(OAuth.OAUTH_NONCE, nonce);
	message.addParameter(OAuth.OAUTH_TIMESTAMP, timestamp);
	message.addParameter("oauth_body_hash", bodyHash);

	final OAuthConsumer consumer = new OAuthConsumer(null, consumerKey, secret, null);
	final OAuthAccessor accessor = new OAuthAccessor(consumer);
	try
	{
		message.sign(accessor);
		return message;
	}
	catch( Exception e )
	{
		throw new RuntimeException(e);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:25,代码来源:LtiServiceImpl.java

示例2: getBaseString

import net.oauth.OAuth; //导入依赖的package包/类
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));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:OAuthSignatureMethod.java

示例3: computeSignature

import net.oauth.OAuth; //导入依赖的package包/类
private byte[] computeSignature(String baseString)
        throws GeneralSecurityException, UnsupportedEncodingException {
    SecretKey key = null;
    synchronized (this) {
        if (this.key == null) {
            String keyString = OAuth.percentEncode(getConsumerSecret())
                    + '&' + OAuth.percentEncode(getTokenSecret());
            byte[] keyBytes = keyString.getBytes(ENCODING);
            this.key = new SecretKeySpec(keyBytes, MAC_NAME);
        }
        key = this.key;
    }
    Mac mac = Mac.getInstance(MAC_NAME);
    mac.init(key);
    byte[] text = baseString.getBytes(ENCODING);
    return mac.doFinal(text);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:HMAC_SHA1.java

示例4: getParameters

import net.oauth.OAuth; //导入依赖的package包/类
public static List<OAuth.Parameter> getParameters(HttpServletRequest request) {
    List<OAuth.Parameter> list = new ArrayList<OAuth.Parameter>();
    for (Enumeration<String> headers = request.getHeaders("Authorization"); headers != null
            && headers.hasMoreElements();) {
        String header = headers.nextElement();
        for (OAuth.Parameter parameter : OAuthMessage
                .decodeAuthorization(header)) {
            if (!"realm".equalsIgnoreCase(parameter.getKey())) {
                list.add(parameter);
            }
        }
    }
    for (Object e : request.getParameterMap().entrySet()) {
        Map.Entry<String, String[]> entry = (Map.Entry<String, String[]>) e;
        String name = entry.getKey();
        for (String value : entry.getValue()) {
            list.add(new OAuth.Parameter(name, value));
        }
    }
    return list;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:HttpRequestMessage.java

示例5: sendForm

import net.oauth.OAuth; //导入依赖的package包/类
/** Send the given parameters as a form-encoded response body. */
public static void sendForm(HttpServletResponse response,
        Iterable<? extends Map.Entry> parameters) throws IOException {
    response.resetBuffer();
    response.setContentType(OAuth.FORM_ENCODED + ";charset="
            + OAuth.ENCODING);
    OAuth.formEncode(parameters, response.getOutputStream());
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:OAuthServlet.java

示例6: validateCallbackURL

import net.oauth.OAuth; //导入依赖的package包/类
protected void validateCallbackURL(Client client,
                                   String oauthCallback) throws OAuthProblemException {
    // the callback must not be empty or null, and it should either match
    // the pre-registered callback URI or have the common root with the
    // the pre-registered application URI
    if (!StringUtils.isEmpty(oauthCallback) 
        && (!StringUtils.isEmpty(client.getCallbackURI())
            && oauthCallback.equals(client.getCallbackURI())
            || !StringUtils.isEmpty(client.getApplicationURI())
            && oauthCallback.startsWith(client.getApplicationURI()))) {
        return;
    }
    OAuthProblemException problemEx = new OAuthProblemException(
        OAuth.Problems.PARAMETER_REJECTED + " - " + OAuth.OAUTH_CALLBACK);
    problemEx
        .setParameter(OAuthProblemException.HTTP_STATUS_CODE,
            HttpServletResponse.SC_BAD_REQUEST);
    throw problemEx;
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:20,代码来源:OscarRequestTokenHandler.java

示例7: grantAccessToken

import net.oauth.OAuth; //导入依赖的package包/类
/**
 * Grant the access token and secret for this consumer based on the request
 * token and secret. When the access token is granted, the consumer could
 * access the user's data in YNote.
 *
 * <p>User must have granted the authorization for this consumer before
 * this method is invoked. Usually this method is invoked in a callback
 * method which is notified after user authorized.
 *
 * @param verifier oauth verifier
 * @throws YNoteException 
 * @throws IOException 
 */
public void grantAccessToken(String verifier) throws IOException, YNoteException {
    lock.writeLock().lock();
    try {
        Map<String, String> parameters = new HashMap<String, String>();
        parameters.put(OAuth.OAUTH_TOKEN, accessor.requestToken);
        parameters.put(OAuth.OAUTH_VERIFIER, verifier);
        HttpResponse response = YNoteHttpUtils.doGet(
                accessor.consumer.serviceProvider.accessTokenURL,
                parameters, accessor);
        // extract the access token and token secret
        String content = YNoteHttpUtils.getResponseContent(
                response.getEntity().getContent());
        Map<String, String> model = YNoteHttpUtils.parseOAuthResponse(content);
        accessor.accessToken = model.get(OAuth.OAUTH_TOKEN);
        accessor.tokenSecret = model.get(OAuth.OAUTH_TOKEN_SECRET);
    } finally {
        lock.writeLock().unlock();
    }
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:33,代码来源:YNoteClient.java

示例8: doGet

import net.oauth.OAuth; //导入依赖的package包/类
/**
 * Do a http get for the given url.
 *
 * @param url requested url
 * @param parameters request parameters
 * @param accessor oauth accessor
 * @return the http response
 * @throws IOException
 * @throws {@link YNoteException}
 */
public static HttpResponse doGet(String url, Map<String, String> parameters,
        OAuthAccessor accessor) throws IOException, YNoteException {
    // add ynote parameters to the url
    OAuth.addParameters(url, parameters == null ? null : parameters.entrySet());
    HttpGet get = new HttpGet(url);
    // sign all parameters, including oauth parameters and ynote parameters
    // and add the oauth related information into the header        
    Header oauthHeader = getAuthorizationHeader(url, OAuthMessage.GET,
            parameters, accessor);
    get.addHeader(oauthHeader);
    HttpParams params = new BasicHttpParams();
    HttpClientParams.setRedirecting(params, false);
    get.setParams(params);
    HttpResponse response = client.execute(get);
    if ((response.getStatusLine().getStatusCode() / 100) != 2) {
        YNoteException e = wrapYNoteException(response);
        throw e;
    }
    return response;
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:31,代码来源:YNoteHttpUtils.java

示例9: testRequestAllParams

import net.oauth.OAuth; //导入依赖的package包/类
@Test
public void testRequestAllParams() throws Exception
{
   Client client = ClientBuilder.newClient();
   WebTarget target = client.target(getRequestURL(MyProvider.Consumer1Key, MyProvider.Consumer1Secret));
   Invocation.Builder request = target.request();
   Response response = request.get();
   Assert.assertEquals(HttpResponseCodes.SC_OK, response.getStatus());
   Map<String, String> tokens = getResponse(response.readEntity(String.class));
   Assert.assertEquals(tokens.size(), 3);
   Assert.assertTrue(tokens.containsKey(OAuth.OAUTH_TOKEN));
   Assert.assertTrue(tokens.get(OAuth.OAUTH_TOKEN).length() > 0);
   Assert.assertTrue(tokens.containsKey(OAuth.OAUTH_TOKEN_SECRET));
   Assert.assertTrue(tokens.get(OAuth.OAUTH_TOKEN_SECRET).length() > 0);
   Assert.assertTrue(tokens.containsKey(OAuthUtils.OAUTH_CALLBACK_CONFIRMED_PARAM));
   Assert.assertEquals(tokens.get(OAuthUtils.OAUTH_CALLBACK_CONFIRMED_PARAM), "true");
}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:18,代码来源:OAuthTest.java

示例10: testAccessAllParams

import net.oauth.OAuth; //导入依赖的package包/类
@Test
public void testAccessAllParams() throws Exception
{
   Client client = ClientBuilder.newClient();
   WebTarget target = client.target(getAccessURL(MyProvider.Consumer1Key, MyProvider.Consumer1Secret, MyProvider.Consumer1Request1Key, MyProvider.Consumer1Request1Secret, MyProvider.Consumer1Request1Verifier));
   Invocation.Builder request = target.request();
   Response response = request.get();
   Assert.assertEquals(HttpResponseCodes.SC_OK, response.getStatus());
   // check that we got all tokens
   Map<String, String> tokens = getResponse(response.readEntity(String.class));
   Assert.assertEquals(tokens.size(), 2);
   Assert.assertTrue(tokens.containsKey(OAuth.OAUTH_TOKEN));
   Assert.assertTrue(tokens.get(OAuth.OAUTH_TOKEN).length() > 0);
   Assert.assertTrue(tokens.containsKey(OAuth.OAUTH_TOKEN_SECRET));
   Assert.assertTrue(tokens.get(OAuth.OAUTH_TOKEN_SECRET).length() > 0);
}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:17,代码来源:OAuthTest.java

示例11: registerMessagingService

import net.oauth.OAuth; //导入依赖的package包/类
public String registerMessagingService(String consumerKey) throws Exception
{
   WebTarget target = ClientBuilder.newClient().target(ConsumerRegistrationURL);
   String base64Credentials = new String(Base64.encodeBytes("admin:admin".getBytes()));
   Invocation.Builder builder = target.request();
   builder.header("Authorization", "Basic " + base64Credentials);
   
   Entity<Form> formEntity = Entity.form(new Form(OAuth.OAUTH_CONSUMER_KEY, consumerKey));
   Response response = null;
   try {
      response = builder.post(formEntity);
      if (HttpResponseCodes.SC_OK != response.getStatus()) {
         throw new RuntimeException("Registration failed");
      }
      // check that we got all tokens
      Map<String, String> tokens = OAuth.newMap(OAuth.decodeForm(response.readEntity(String.class)));
      String secret = tokens.get("xoauth_consumer_secret");
      if (secret == null) {
          throw new RuntimeException("No secret available");
      }
      return secret;
   } finally {
      response.close();
   }
}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:26,代码来源:Subscriber.java

示例12: registerMessagingServiceScopes

import net.oauth.OAuth; //导入依赖的package包/类
public void registerMessagingServiceScopes(String consumerKey, String scope) throws Exception
{
   WebTarget target = ClientBuilder.newClient().target(ConsumerScopesRegistrationURL);
   String base64Credentials = new String(Base64.encodeBytes("admin:admin".getBytes()));
   Invocation.Builder builder = target.request();
   builder.header("Authorization", "Basic " + base64Credentials);
   Form form = new Form(OAuth.OAUTH_CONSUMER_KEY, consumerKey);
   form.param("xoauth_scope", scope);
   form.param("xoauth_permission", "sendMessages");
   Response response = null;
   try {
      response = builder.post(Entity.form(form));
      if (HttpResponseCodes.SC_OK != response.getStatus()) {
         throw new RuntimeException("Scopes can not be registered");
      }
   } finally {
      response.close();
   }
}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:20,代码来源:Subscriber.java

示例13: getSharedSecret

import net.oauth.OAuth; //导入依赖的package包/类
public String getSharedSecret(String consumerKey) throws Exception
{
   WebTarget target = ClientBuilder.newClient().target(ConsumerRegistrationURL);
   Invocation.Builder builder = target.request();
   Form form = new Form(OAuth.OAUTH_CONSUMER_KEY, consumerKey);
   Entity<Form> formEntity = Entity.form(form);
   Response response = builder.post(formEntity);
   if (HttpResponseCodes.SC_OK != response.getStatus()) {
      response.close();
      throw new RuntimeException("Registration failed");
   }
   // check that we got all tokens
   Map<String, String> tokens = OAuth.newMap(OAuth.decodeForm(response.readEntity(String.class)));
   String secret = tokens.get("xoauth_consumer_secret");
   if (secret == null) {
      throw new RuntimeException("No secret available");
   }
   return secret;
}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:20,代码来源:ConsumerResource.java

示例14: getRequestToken

import net.oauth.OAuth; //导入依赖的package包/类
public Token getRequestToken(String consumerKey, String consumerSecret, 
                             String callbackURI, String scope, String permission) throws Exception
{
   WebTarget target = ClientBuilder.newClient().target(getRequestURL(consumerKey, consumerSecret, callbackURI, scope, permission));
   Response response = target.request().get();
   if (HttpResponseCodes.SC_OK != response.getStatus()) {
      response.close();
      throw new RuntimeException("Request token can not be obtained");
   }
   // check that we got all tokens
   Map<String, String> tokens = getTokens(response.readEntity(String.class));
   if (tokens.size() != 3
         || !tokens.containsKey(OAuth.OAUTH_TOKEN)
         || !(tokens.get(OAuth.OAUTH_TOKEN).length() > 0)
         || !tokens.containsKey(OAuth.OAUTH_TOKEN_SECRET)
         || !(tokens.get(OAuth.OAUTH_TOKEN_SECRET).length() > 0)
         || !tokens.containsKey(OAuthUtils.OAUTH_CALLBACK_CONFIRMED_PARAM)
         || !tokens.get(OAuthUtils.OAUTH_CALLBACK_CONFIRMED_PARAM).equals("true")) {
      throw new RuntimeException("Wrong request token details");
   }

   return new Token(tokens.get(OAuth.OAUTH_TOKEN), tokens.get(OAuth.OAUTH_TOKEN_SECRET));
}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:24,代码来源:ConsumerResource.java

示例15: getAccessToken

import net.oauth.OAuth; //导入依赖的package包/类
public Token getAccessToken(String consumerKey, String consumerSecret,
        Token requestToken) throws Exception
{
   String url = getAccessURL(consumerKey, consumerSecret, 
                             requestToken.getToken(), requestToken.getSecret(),
                             requestToken.getVerifier());
   WebTarget target = ClientBuilder.newClient().target(url);
   Response response = target.request().get();
   if (HttpResponseCodes.SC_OK != response.getStatus()) {
      response.close();
      throw new RuntimeException("Request token can not be obtained");
   }
   // check that we got all tokens
   Map<String, String> tokens = getTokens(response.readEntity(String.class));
   if (tokens.size() != 2
         || !tokens.containsKey(OAuth.OAUTH_TOKEN)
         || !(tokens.get(OAuth.OAUTH_TOKEN).length() > 0)
         || !tokens.containsKey(OAuth.OAUTH_TOKEN_SECRET)
         || !(tokens.get(OAuth.OAUTH_TOKEN_SECRET).length() > 0)) {
      throw new RuntimeException("Wrong access token details");
   }

   return new Token(tokens.get(OAuth.OAUTH_TOKEN), tokens.get(OAuth.OAUTH_TOKEN_SECRET));
}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:25,代码来源:ConsumerResource.java


注:本文中的net.oauth.OAuth类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。