Skip to content
This repository was archived by the owner on Jan 20, 2024. It is now read-only.

Commit 0026ce2

Browse files
committed
fixes #77 switch to JwtIssuer for token generation
1 parent affaa3e commit 0026ce2

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

token/src/main/java/com/networknt/oauth/token/handler/Oauth2TokenPostHandler.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import com.networknt.oauth.cache.model.User;
1414
import com.networknt.oauth.token.helper.HttpAuth;
1515
import com.networknt.security.JwtConfig;
16-
import com.networknt.security.JwtHelper;
16+
import com.networknt.security.JwtIssuer;
1717
import com.networknt.status.Status;
1818
import com.networknt.utility.CodeVerifierUtil;
1919
import com.networknt.utility.HashUtil;
@@ -139,7 +139,7 @@ private Map<String, Object> handleClientCredentials(HttpServerExchange exchange,
139139
if(customClaim != null && customClaim.length() > 0) {
140140
customMap = Config.getInstance().getMapper().readValue(customClaim, new TypeReference<Map<String, Object>>(){});
141141
}
142-
jwt = JwtHelper.getJwt(mockCcClaims(client.getClientId(), scope, customMap));
142+
jwt = JwtIssuer.getJwt(mockCcClaims(client.getClientId(), scope, customMap));
143143
} catch (Exception e) {
144144
logger.error("Exception:", e);
145145
throw new ApiException(new Status(GENERIC_EXCEPTION, e.getMessage()));
@@ -233,7 +233,7 @@ private Map<String, Object> handleAuthorizationCode(HttpServerExchange exchange,
233233
if(customClaim != null && customClaim.length() > 0) {
234234
customMap = Config.getInstance().getMapper().readValue(customClaim, new TypeReference<Map<String, Object>>(){});
235235
}
236-
jwt = JwtHelper.getJwt(mockAcClaims(client.getClientId(), scope, userId, user.getUserType().toString(), customMap));
236+
jwt = JwtIssuer.getJwt(mockAcClaims(client.getClientId(), scope, userId, user.getUserType().toString(), customMap));
237237
} catch (Exception e) {
238238
throw new ApiException(new Status(GENERIC_EXCEPTION, e.getMessage()));
239239
}
@@ -296,7 +296,7 @@ private Map<String, Object> handlePassword(HttpServerExchange exchange, Map<Stri
296296
if(customClaim != null && customClaim.length() > 0) {
297297
customMap = Config.getInstance().getMapper().readValue(customClaim, new TypeReference<Map<String, Object>>(){});
298298
}
299-
String jwt = JwtHelper.getJwt(mockAcClaims(client.getClientId(), scope, userId, user.getUserType().toString(), customMap));
299+
String jwt = JwtIssuer.getJwt(mockAcClaims(client.getClientId(), scope, userId, user.getUserType().toString(), customMap));
300300
// generate a refresh token and associate it with userId and clientId
301301
String refreshToken = UUID.randomUUID().toString();
302302
RefreshToken token = new RefreshToken();
@@ -366,7 +366,7 @@ private Map<String, Object> handleRefreshToken(HttpServerExchange exchange, Map<
366366
if(customClaim != null && customClaim.length() > 0) {
367367
customMap = Config.getInstance().getMapper().readValue(customClaim, new TypeReference<Map<String, Object>>(){});
368368
}
369-
jwt = JwtHelper.getJwt(mockAcClaims(client.getClientId(), scope, userId, user.getUserType().toString(), customMap));
369+
jwt = JwtIssuer.getJwt(mockAcClaims(client.getClientId(), scope, userId, user.getUserType().toString(), customMap));
370370
} catch (Exception e) {
371371
throw new ApiException(new Status(GENERIC_EXCEPTION, e.getMessage()));
372372
}
@@ -438,7 +438,7 @@ private Map<String, Object> handleClientAuthenticatedUser(HttpServerExchange exc
438438
}
439439
String jwt;
440440
try {
441-
jwt = JwtHelper.getJwt(mockAcClaims(client.getClientId(), scope, userId, userType, formMap));
441+
jwt = JwtIssuer.getJwt(mockAcClaims(client.getClientId(), scope, userId, userType, formMap));
442442
} catch (Exception e) {
443443
throw new ApiException(new Status(GENERIC_EXCEPTION, e.getMessage()));
444444
}
@@ -513,7 +513,7 @@ private Client validateClientSecret(String clientId, String clientSecret) throws
513513
}
514514

515515
private JwtClaims mockCcClaims(String clientId, String scopeString, Map<String, Object> formMap) {
516-
JwtClaims claims = JwtHelper.getDefaultJwtClaims();
516+
JwtClaims claims = JwtIssuer.getDefaultJwtClaims();
517517
claims.setClaim("client_id", clientId);
518518
List<String> scope = Arrays.asList(scopeString.split("\\s+"));
519519
claims.setStringListClaim("scope", scope); // multi-valued claims work too and will end up as a JSON array
@@ -526,7 +526,7 @@ private JwtClaims mockCcClaims(String clientId, String scopeString, Map<String,
526526
}
527527

528528
private JwtClaims mockAcClaims(String clientId, String scopeString, String userId, String userType, Map<String, Object> formMap) {
529-
JwtClaims claims = JwtHelper.getDefaultJwtClaims();
529+
JwtClaims claims = JwtIssuer.getDefaultJwtClaims();
530530
claims.setClaim("user_id", userId);
531531
claims.setClaim("user_type", userType);
532532
claims.setClaim("client_id", clientId);

token/src/test/java/com/networknt/oauth/token/handler/JwtGeneratorTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.networknt.oauth.token.handler;
22

3-
import com.networknt.security.JwtHelper;
3+
import com.networknt.security.JwtIssuer;
44
import org.jose4j.jwt.JwtClaims;
55
import org.junit.Assert;
66
import org.junit.Test;
@@ -15,14 +15,14 @@ public class JwtGeneratorTest {
1515

1616
@Test
1717
public void testJwtGen() throws Exception {
18-
JwtClaims claims = JwtHelper.getDefaultJwtClaims();
18+
JwtClaims claims = JwtIssuer.getDefaultJwtClaims();
1919
claims.setClaim("user_id", "steve");
2020
claims.setClaim("user_type", "EMPLOYEE");
2121
claims.setClaim("client_id", "ddcaf0ba-1131-2232-3313-d6f2753f25dc");
2222
List<String> scope = Arrays.asList("api.r", "api.w");
2323
claims.setStringListClaim("scope", scope); // multi-valued claims work too and will end up as a JSON array
2424

25-
String jwt = JwtHelper.getJwt(claims);
25+
String jwt = JwtIssuer.getJwt(claims);
2626
Assert.assertNotNull(jwt);
2727
System.out.println(jwt);
2828
}

token/src/test/resources/config/jwt.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Signature private key that used to sign JWT tokens.
55
key:
66
kid: '100' # kid that used to sign the JWT tokens. It will be shown up in the token header.
7-
filename: "/config/oauth/primary.jks" # private key that is used to sign JWT tokens.
7+
filename: "oauth/primary.jks" # private key that is used to sign JWT tokens.
88
password: password # password for the private key. It should be set during deployment time along with pk
99
keyName: selfsigned # key name that is used to identify the right key in keystore.
1010
issuer: urn:com:networknt:oauth2:v1 # default issuer of the JWT token

0 commit comments

Comments
 (0)