File tree Expand file tree Collapse file tree 4 files changed +26
-6
lines changed Expand file tree Collapse file tree 4 files changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ interface{
9
9
/**
10
10
* A struct of custom claims to add to the JWT token
11
11
*/
12
- struct function getJwtCustomClaims ();
12
+ struct function getJwtCustomClaims ( required struct payload );
13
13
14
14
/**
15
15
* This function returns an array of all the scopes that should be attached to the JWT token that will be used for authorization.
Original file line number Diff line number Diff line change @@ -791,7 +791,7 @@ component accessors="true" singleton threadsafe {
791
791
// Append user custom claims with override, they take prescedence
792
792
structAppend (
793
793
payload ,
794
- arguments .user .getJwtCustomClaims (),
794
+ arguments .user .getJwtCustomClaims ( payload ),
795
795
true
796
796
);
797
797
@@ -864,7 +864,7 @@ component accessors="true" singleton threadsafe {
864
864
*
865
865
* @return The discovered refresh token or an empty string
866
866
*/
867
- private string function discoverRefreshToken (){
867
+ public string function discoverRefreshToken (){
868
868
var event = variables .requestService .getContext ();
869
869
870
870
// Discover api token from headers using a custom header or the incoming RC
Original file line number Diff line number Diff line change 1
- component accessors = " true" {
1
+ component accessors = " true" implements = " cbsecurity.interfaces.jwt.IJwtSubject " {
2
2
3
3
property name = " auth" inject = " authenticationService@cbauth" ;
4
4
@@ -27,8 +27,11 @@ component accessors="true" {
27
27
/**
28
28
* A struct of custom claims to add to the JWT token
29
29
*/
30
- struct function getJWTCustomClaims (){
31
- return { " role" : " admin" };
30
+ struct function getJWTCustomClaims ( required struct payload ){
31
+ return {
32
+ " duplicatedJTI" : arguments .payload .jti ,
33
+ " role" : " admin"
34
+ };
32
35
}
33
36
34
37
/**
Original file line number Diff line number Diff line change @@ -189,6 +189,23 @@ component extends="coldbox.system.testing.BaseTestCase" appMapping="/root" {
189
189
} );
190
190
} );
191
191
192
+ given ( " a getJwtCustomClaims method on user" , function (){
193
+ then ( " it should pass the current payload in to the function" , function (){
194
+ var oUser = variables .userService .retrieveUserByUsername ( " test" );
195
+ var tokens = variables .jwtService .fromUser ( oUser );
196
+ expect ( tokens ).toBeStruct ().toHaveKey ( " access_token" );
197
+
198
+ var decodedAccessToken = variables .jwtService .decode (
199
+ tokens .access_token
200
+ );
201
+ expect ( decodedAccessToken ).toHaveKey ( " jti" );
202
+ expect ( decodedAccessToken ).toHaveKey ( " duplicatedJTI" );
203
+ expect ( decodedAccessToken .duplicatedJTI ).toBe (
204
+ decodedAccessToken .jti
205
+ );
206
+ } );
207
+ } );
208
+
192
209
given ( " an invalid refresh token" , function (){
193
210
then ( " an exception should be thrown" , function (){
194
211
expect ( function (){
You can’t perform that action at this time.
0 commit comments