Skip to content

Commit

Permalink
Merge pull request #1341 from VirajSalaka/jwt-fix
Browse files Browse the repository at this point in the history
populate api tier and api name in backend jwt header
  • Loading branch information
menakajl authored Jul 16, 2020
2 parents 49648b5 + cb76a6f commit cc2ac1e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function createAPIDetailsMap (runtime:InvocationContext invocationContext) retur
if (apiConfig is APIConfiguration) {
apiDetails["apiName"] = apiConfig.name;
apiDetails["apiVersion"] = apiConfig.apiVersion;
apiDetails["apiTier"] = apiConfig.apiTier;
apiDetails["apiTier"] = (apiConfig.apiTier != "") ? apiConfig.apiTier : UNLIMITED_TIER;
apiDetails["apiContext"] = <string> invocationContext.attributes[API_CONTEXT];
apiDetails["apiPublisher"] = apiConfig.publisher;
apiDetails["subscriberTenantDomain"] = authenticationContext.subscriberTenantDomain;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
public class MGWJWTGeneratorImpl extends AbstractMGWJWTGenerator {
private static final Logger logger = LogManager.getLogger(MGWJWTGeneratorImpl.class);
private static final String AUTH_APPLICATION_USER_LEVEL_TOKEN = "Application_user";
private static final String AUTH_APPLICATION_USER_LEVEL_TOKEN = "Application_User";

public MGWJWTGeneratorImpl(String dialectURI,
String signatureAlgorithm,
Expand All @@ -56,11 +56,6 @@ public Map<String, Object> populateStandardClaims(Map<String, Object> jwtInfo) {
Map<String, Object> claims = new HashMap<>();
HashMap<String, Object> customClaims = (HashMap<String, Object>) jwtInfo.get("customClaims");
claims.put("iss", getTokenIssuer());
if (getTokenAudience().length == 1) {
claims.put("aud", getTokenAudience()[0]);
} else if (getTokenAudience().length != 0) {
claims.put("aud", arrayToJSONArray(getTokenAudience()));
}
claims.put("jti", UUID.randomUUID().toString());
claims.put("iat", (int) (currentTime / 1000));
claims.put("exp", (int) (expireIn / 1000));
Expand All @@ -86,6 +81,9 @@ public Map<String, Object> populateStandardClaims(Map<String, Object> jwtInfo) {
claims.put(dialect + "/applicationtier", ((HashMap) customClaims.get("application")).get("tier"));
}
}
if (StringUtils.isNotEmpty((CharSequence) getApiDetails().get("apiName"))) {
claims.put(dialect + "/apiName", getApiDetails().get("apiName"));
}
if (StringUtils.isNotEmpty((CharSequence) getApiDetails().get("apiContext"))) {
claims.put(dialect + "/apicontext", getApiDetails().get("apiContext"));
}
Expand Down

0 comments on commit cc2ac1e

Please sign in to comment.