Skip to content

Commit 3bf548f

Browse files
committed
finalized all storage services
1 parent 52889d9 commit 3bf548f

File tree

5 files changed

+39
-10
lines changed

5 files changed

+39
-10
lines changed

interfaces/jwt/IJwtStorage.cfc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@ interface{
1919
* @key The cache key
2020
* @token The token to store
2121
* @expiration The token expiration
22+
* @payload The payload
2223
*
2324
* @return JWTStorage
2425
*/
25-
any function set( required key, required token, required expiration );
26+
any function set(
27+
required key,
28+
required token,
29+
required expiration,
30+
required payload
31+
);
2632

2733
/**
2834
* Verify if the passed in token key exists

models/jwt/JwtService.cfc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,12 @@ component accessors="true" singleton{
109109

110110
// Store it with the expiration as well if enabled
111111
if( variables.settings.jwt.tokenStorage.enabled ){
112-
getTokenStorage().set( payload.jti, jwtToken, variables.settings.jwt.expiration );
112+
getTokenStorage().set(
113+
key = payload.jti,
114+
token = jwtToken,
115+
expiration = variables.settings.jwt.expiration,
116+
payload = payload
117+
);
113118
}
114119

115120
// Return it

models/jwt/storages/CacheTokenStorage.cfc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,23 @@ component accessors="true" singleton{
5555
* @key The cache key
5656
* @token The token to store
5757
* @expiration The token expiration
58+
* @payload The payload
5859
*
5960
* @return JWTStorage
6061
*/
61-
any function set( required key, required token, required expiration ){
62+
any function set(
63+
required key,
64+
required token,
65+
required expiration,
66+
required payload
67+
){
6268
variables.cache.set(
6369
buildKey( arguments.key ),
6470
{
6571
token : arguments.token,
6672
expiration : arguments.expiration,
67-
created : now()
73+
created : now(),
74+
payload : arguments.payload
6875
},
6976
arguments.expiration
7077
);

models/jwt/storages/DBTokenStorage.cfc

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* - cacheKey : varchar 255
1717
* - token : text
1818
* - expiration : varchar 255 (unix timestamp)
19+
* - subject : varchar 255
1920
*
2021
*/
2122
component accessors="true" singleton{
@@ -40,7 +41,7 @@ component accessors="true" singleton{
4041
*/
4142
property name="keyPrefix";
4243

43-
variables.COLUMNS = "id,cacheKey,token,expiration,created";
44+
variables.COLUMNS = "id,cacheKey,token,expiration,created,subject";
4445

4546
/**
4647
* Constructor
@@ -93,26 +94,34 @@ component accessors="true" singleton{
9394
* @key The cache key
9495
* @token The token to store
9596
* @expiration The token expiration
97+
* @payload The payload
9698
*
9799
* @return JWTStorage
98100
*/
99-
any function set( required key, required token, required expiration ){
101+
any function set(
102+
required key,
103+
required token,
104+
required expiration,
105+
required payload
106+
){
100107
queryExecute(
101108
"INSERT INTO #getTable()# (#variables.COLUMNS#)
102109
VALUES (
103110
:uuid,
104111
:cacheKey,
105112
:token,
106113
:expiration,
107-
:created
114+
:created,
115+
:subject
108116
)
109117
",
110118
{
111119
uuid = { cfsqltype="varchar", value="#variables.uuid.randomUUID().toString()#" },
112120
cacheKey = { cfsqltype="varchar", value=arguments.key },
113121
token = { cfsqltype="longvarchar",value=arguments.token },
114122
expiration = { cfsqltype="varchar", value=arguments.expiration },
115-
created = { cfsqltype="timestamp", value=now() }
123+
created = { cfsqltype="timestamp", value=now() },
124+
subject = { cfsqltype="varchar", value=arguments.payload.sub },
116125
},
117126
{
118127
datasource = variables.properties.dsn
@@ -316,6 +325,7 @@ component accessors="true" singleton{
316325
break;
317326
}
318327
}
328+
319329
// create it
320330
if( NOT tableFound ){
321331
transaction{
@@ -326,6 +336,7 @@ component accessors="true" singleton{
326336
expiration VARCHAR(255) NOT NULL,
327337
created #getDateTimeColumnType()# NOT NULL,
328338
token #getTextColumnType()# NOT NULL,
339+
subject VARCHAR(255) NOT NULL,
329340
PRIMARY KEY (id)
330341
)",
331342
{},

test-harness/config/Coldbox.cfc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@
138138
"tokenStorage" : {
139139
"enabled" : true,
140140
"keyPrefix" : "cbjwt_",
141-
"driver" : "db",
141+
"driver" : "cachebox",
142142
"properties" : {
143-
"table" : "jwtTokens"
143+
"cacheName" : "default"
144144
}
145145
}
146146
}

0 commit comments

Comments
 (0)