use of org.glassfish.jersey.oauth1.signature.OAuth1Secrets 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";
}
use of org.glassfish.jersey.oauth1.signature.OAuth1Secrets 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";
}
Aggregations