Search in sources :

Example 6 with OAuth1Parameters

use of org.glassfish.jersey.oauth1.signature.OAuth1Parameters in project jersey by jersey.

the class AccessTokenResource method post.

@POST
@Produces("text/plain")
public String post(@Context ContainerRequestContext request) {
    OAuthServerRequest osr = new OAuthServerRequest(request);
    OAuth1Secrets secrets = new OAuth1Secrets().consumerSecret("kd94hf93k423kf44").tokenSecret("hdhd0244k9j7ao03");
    OAuth1Parameters params = new OAuth1Parameters().readRequest(osr);
    // ensure query parameters correctly parsed into OAuth parameters object
    assertEquals(params.getConsumerKey(), "dpf43f3p2l4k3l03");
    assertEquals(params.getToken(), "hh5s93j4hdidpola");
    assertEquals(params.getSignatureMethod(), "PLAINTEXT");
    assertEquals(params.getSignature(), secrets.getConsumerSecret() + "&" + secrets.getTokenSecret());
    assertEquals(params.getTimestamp(), "1191242092");
    assertEquals(params.getNonce(), "dji430splmx33448");
    assertEquals(params.getVersion(), "1.0");
    try {
        // verify the plaintext signature
        assertTrue(oAuth1Signature.verify(osr, params, secrets));
    } catch (OAuth1SignatureException ose) {
        fail(ose.getMessage());
    }
    return "oauth_token=nnch734d00sl2jdk&oauth_token_secret=pfkkdhi9sl3r4s00";
}
Also used : OAuthServerRequest(org.glassfish.jersey.server.oauth1.internal.OAuthServerRequest) OAuth1Parameters(org.glassfish.jersey.oauth1.signature.OAuth1Parameters) OAuth1SignatureException(org.glassfish.jersey.oauth1.signature.OAuth1SignatureException) OAuth1Secrets(org.glassfish.jersey.oauth1.signature.OAuth1Secrets) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 7 with OAuth1Parameters

use of org.glassfish.jersey.oauth1.signature.OAuth1Parameters in project jersey by jersey.

the class PhotosResource method handle.

@GET
@Produces("text/plain")
public String handle(@QueryParam("file") String file, @QueryParam("size") String size, @Context ContainerRequestContext request) {
    OAuthServerRequest osr = new OAuthServerRequest(request);
    OAuth1Secrets secrets = new OAuth1Secrets().consumerSecret("kd94hf93k423kf44").tokenSecret("pfkkdhi9sl3r4s00");
    OAuth1Parameters params = new OAuth1Parameters().readRequest(osr);
    // ensure query parameters are as expected
    assertEquals(file, "vacation.jpg");
    assertEquals(size, "original");
    // ensure query parameters correctly parsed into OAuth parameters object
    assertEquals(params.getConsumerKey(), "dpf43f3p2l4k3l03");
    assertEquals(params.getToken(), "nnch734d00sl2jdk");
    assertEquals(params.getSignatureMethod(), "HMAC-SHA1");
    assertEquals(params.getTimestamp(), "1191242096");
    assertEquals(params.getNonce(), "kllo9940pd9333jh");
    assertEquals(params.getVersion(), "1.0");
    try {
        // verify the HMAC-SHA1 signature
        assertTrue(oAuth1Signature.verify(osr, params, secrets));
    } catch (OAuth1SignatureException ose) {
        fail(ose.getMessage());
    }
    return "PHOTO";
}
Also used : OAuthServerRequest(org.glassfish.jersey.server.oauth1.internal.OAuthServerRequest) OAuth1Parameters(org.glassfish.jersey.oauth1.signature.OAuth1Parameters) OAuth1SignatureException(org.glassfish.jersey.oauth1.signature.OAuth1SignatureException) OAuth1Secrets(org.glassfish.jersey.oauth1.signature.OAuth1Secrets) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 8 with OAuth1Parameters

use of org.glassfish.jersey.oauth1.signature.OAuth1Parameters in project jersey by jersey.

the class RequestTokenResource method get.

@POST
@Produces("text/plain")
public String get(@Context ContainerRequestContext request) {
    OAuthServerRequest osr = new OAuthServerRequest(request);
    OAuth1Secrets secrets = new OAuth1Secrets().consumerSecret("kd94hf93k423kf44");
    OAuth1Parameters params = new OAuth1Parameters().readRequest(osr);
    // ensure parameters correctly parsed into OAuth parameters object
    assertEquals(params.getConsumerKey(), "dpf43f3p2l4k3l03");
    assertEquals(params.getSignatureMethod(), "PLAINTEXT");
    assertEquals(params.getSignature(), secrets.getConsumerSecret() + "&");
    assertEquals(params.getTimestamp(), "1191242090");
    assertEquals(params.getNonce(), "hsu94j3884jdopsl");
    assertEquals(params.getVersion(), "1.0");
    try {
        // verify the plaintext signature
        assertTrue(oAuth1Signature.verify(osr, params, secrets));
    } catch (OAuth1SignatureException ose) {
        fail(ose.getMessage());
    }
    return "oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03";
}
Also used : OAuthServerRequest(org.glassfish.jersey.server.oauth1.internal.OAuthServerRequest) OAuth1Parameters(org.glassfish.jersey.oauth1.signature.OAuth1Parameters) OAuth1SignatureException(org.glassfish.jersey.oauth1.signature.OAuth1SignatureException) OAuth1Secrets(org.glassfish.jersey.oauth1.signature.OAuth1Secrets) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Aggregations

OAuth1Parameters (org.glassfish.jersey.oauth1.signature.OAuth1Parameters)8 OAuth1Secrets (org.glassfish.jersey.oauth1.signature.OAuth1Secrets)7 OAuth1SignatureException (org.glassfish.jersey.oauth1.signature.OAuth1SignatureException)6 Produces (javax.ws.rs.Produces)5 POST (javax.ws.rs.POST)4 OAuthServerRequest (org.glassfish.jersey.server.oauth1.internal.OAuthServerRequest)4 Consumes (javax.ws.rs.Consumes)2 Form (javax.ws.rs.core.Form)2 OAuth1Consumer (org.glassfish.jersey.server.oauth1.OAuth1Consumer)2 OAuth1Exception (org.glassfish.jersey.server.oauth1.OAuth1Exception)2 OAuth1Token (org.glassfish.jersey.server.oauth1.OAuth1Token)2 TokenResource (org.glassfish.jersey.server.oauth1.TokenResource)2 Field (java.lang.reflect.Field)1 GET (javax.ws.rs.GET)1 ProcessingException (javax.ws.rs.ProcessingException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Client (javax.ws.rs.client.Client)1 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)1 AccessToken (org.glassfish.jersey.client.oauth1.AccessToken)1 ConsumerCredentials (org.glassfish.jersey.client.oauth1.ConsumerCredentials)1