This repository has been archived by the owner on Apr 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
177 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
exports.ISSUER_HEADER = 'x-oauth-reverse-proxy-jwt-issuer'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.cimpress.mcp.jwt</groupId> | ||
<artifactId>JWTClient</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>JWT Client Test</name> | ||
<url>http://maven.apache.org</url> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.bitbucket.b_c</groupId> | ||
<artifactId>jose4j</artifactId> | ||
<version>0.4.4</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-io</artifactId> | ||
<version>1.3.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient</artifactId> | ||
<version>4.5</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<version>1.1.3</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<version>2.4</version> | ||
<configuration> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
|
||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>assemble-all</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
73 changes: 73 additions & 0 deletions
73
test/clients/java/JWTClient/src/main/java/com/cimpress/mcp/jwt/JWTClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.cimpress.mcp.jwt; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.net.URL; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.NameValuePair; | ||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.client.methods.HttpPost; | ||
import org.apache.http.impl.client.HttpClientBuilder; | ||
import org.apache.http.message.BasicNameValuePair; | ||
import org.jose4j.base64url.Base64; | ||
import org.jose4j.jwk.JsonWebKey; | ||
import org.jose4j.jws.AlgorithmIdentifiers; | ||
import org.jose4j.jws.JsonWebSignature; | ||
import org.jose4j.jwt.JwtClaims; | ||
|
||
public class JWTClient { | ||
private static final String CONSUMER_KEY = "java-test-key"; | ||
|
||
public static void main(String[] args) throws Exception { | ||
|
||
File keyFile = new File("../../../keys/8008/8080/" + CONSUMER_KEY); | ||
String secret = Base64.encode(IOUtils.toString(new FileInputStream(keyFile)).getBytes()); | ||
|
||
URL url = new URL("http://localhost:7070/job?this=is&fun=right"); | ||
|
||
HttpPost request = new HttpPost(url.toURI()); | ||
List<NameValuePair> params = new LinkedList<NameValuePair>(); | ||
// NOTE: The below line doesn't work because Java SignPost can't handle query and post | ||
// params with the same name. | ||
// params.add(new BasicNameValuePair("this", "post")); | ||
params.add(new BasicNameValuePair("post", "happy")); | ||
params.add(new BasicNameValuePair("wow", "so")); | ||
params.add(new BasicNameValuePair("signposty", "a")); | ||
params.add(new BasicNameValuePair("signposty", "b")); | ||
params.add(new BasicNameValuePair("signposty", "rad")); | ||
//request.setEntity(new UrlEncodedFormEntity(params)); | ||
|
||
// sign the request | ||
JwtClaims claims = new JwtClaims(); | ||
claims.setIssuer("java-test-key"); | ||
claims.setGeneratedJwtId(); | ||
|
||
// A JWT is a JWS and/or a JWE with JSON claims as the payload. | ||
// In this example it is a JWS so we create a JsonWebSignature object. | ||
JsonWebSignature jws = new JsonWebSignature(); | ||
|
||
// The payload of the JWS is JSON content of the JWT Claims | ||
jws.setPayload(claims.toJson()); | ||
|
||
// The JWT is signed using the private key | ||
String jwkJson = "{\"kty\":\"oct\",\"k\":\""+ secret +"\"}"; | ||
JsonWebKey key = JsonWebKey.Factory.newJwk(jwkJson); | ||
jws.setKey(key.getKey()); | ||
jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.HMAC_SHA256); | ||
|
||
String jwt = jws.getCompactSerialization(); | ||
|
||
request.setHeader("Authorization", "Bearer " + jwt); | ||
|
||
// send the request | ||
HttpClient httpClient = HttpClientBuilder.create().build(); | ||
HttpResponse response = httpClient.execute(request); | ||
|
||
// Print the result | ||
System.out.println(IOUtils.toString(response.getEntity().getContent())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters