Added setNonce to JwtClaims.
parent
02d0471acf
commit
8b10b83516
|
@ -22,6 +22,7 @@ public class JwtClaims extends ClaimSet {
|
||||||
public static final String ISSUED_AT = "iat";
|
public static final String ISSUED_AT = "iat";
|
||||||
public static final String NOT_BEFORE = "nbf";
|
public static final String NOT_BEFORE = "nbf";
|
||||||
public static final String EXPIRATION = "exp";
|
public static final String EXPIRATION = "exp";
|
||||||
|
public static final String NONCE = "nonce";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ISO8601 / RFC3339 Date Format
|
* ISO8601 / RFC3339 Date Format
|
||||||
|
@ -63,7 +64,9 @@ public class JwtClaims extends ClaimSet {
|
||||||
setJwtId(element.getValue().getAsString());
|
setJwtId(element.getValue().getAsString());
|
||||||
} else if (element.getKey().equals(TYPE)) {
|
} else if (element.getKey().equals(TYPE)) {
|
||||||
setType(element.getValue().getAsString());
|
setType(element.getValue().getAsString());
|
||||||
} else {
|
} else if (element.getKey().equals(NONCE)){
|
||||||
|
setType(element.getValue().getAsString());
|
||||||
|
}else {
|
||||||
pass.add(element.getKey(), element.getValue());
|
pass.add(element.getKey(), element.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -184,5 +187,18 @@ public class JwtClaims extends ClaimSet {
|
||||||
setClaim(TYPE, type);
|
setClaim(TYPE, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the nonce
|
||||||
|
*/
|
||||||
|
public String getNonce() {
|
||||||
|
return getClaimAsString(NONCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param nonce the nonce to set
|
||||||
|
*/
|
||||||
|
public void setNonce(String nonce) {
|
||||||
|
setClaim(NONCE, nonce);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,6 +106,7 @@ public class ConnectAuthCodeTokenGranter implements TokenGranter {
|
||||||
|
|
||||||
String authorizationCode = parameters.get("code");
|
String authorizationCode = parameters.get("code");
|
||||||
String redirectUri = parameters.get("redirect_uri");
|
String redirectUri = parameters.get("redirect_uri");
|
||||||
|
String nonce = parameters.get("nonce");
|
||||||
|
|
||||||
if (authorizationCode == null) {
|
if (authorizationCode == null) {
|
||||||
throw new OAuth2Exception("An authorization code must be supplied.");
|
throw new OAuth2Exception("An authorization code must be supplied.");
|
||||||
|
@ -144,9 +145,7 @@ public class ConnectAuthCodeTokenGranter implements TokenGranter {
|
||||||
OAuth2AccessTokenEntity token = (OAuth2AccessTokenEntity) tokenServices.createAccessToken(new OAuth2Authentication(authorizationRequest, userAuth));
|
OAuth2AccessTokenEntity token = (OAuth2AccessTokenEntity) tokenServices.createAccessToken(new OAuth2Authentication(authorizationRequest, userAuth));
|
||||||
|
|
||||||
token.getJwt().getClaims().setAudience(clientId);
|
token.getJwt().getClaims().setAudience(clientId);
|
||||||
|
|
||||||
//TODO: need to get base url, but Utility.findBaseUrl() needs access to a request object, which we don't have
|
|
||||||
//See github issue #1
|
|
||||||
token.getJwt().getClaims().setIssuer(configBean.getIssuer());
|
token.getJwt().getClaims().setIssuer(configBean.getIssuer());
|
||||||
|
|
||||||
token.getJwt().getClaims().setIssuedAt(new Date());
|
token.getJwt().getClaims().setIssuedAt(new Date());
|
||||||
|
@ -168,6 +167,9 @@ public class ConnectAuthCodeTokenGranter implements TokenGranter {
|
||||||
idToken.getClaims().setAudience(clientId);
|
idToken.getClaims().setAudience(clientId);
|
||||||
idToken.getClaims().setIssuedAt(new Date());
|
idToken.getClaims().setIssuedAt(new Date());
|
||||||
idToken.getClaims().setIssuer(configBean.getIssuer());
|
idToken.getClaims().setIssuer(configBean.getIssuer());
|
||||||
|
if (nonce != null && nonce.length() > 0) {
|
||||||
|
idToken.getClaims().setNonce(nonce);
|
||||||
|
}
|
||||||
// TODO: expiration? other fields?
|
// TODO: expiration? other fields?
|
||||||
|
|
||||||
//Sign
|
//Sign
|
||||||
|
|
Loading…
Reference in New Issue