Skip to content

Commit 8b1e448

Browse files
committed
checks for secret key, allow for jwt secret to come from env variable.
1 parent d9a8ad2 commit 8b1e448

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

ModuleConfig.cfc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,12 @@ component {
6969
"enableSecurityVisualizer" : false,
7070
// JWT Settings
7171
"jwt" : {
72-
// The jwt secret encoding key, defaults to getSystemEnv( "JWT_SECRET", "" )
73-
"secretKey" : "",
74-
75-
// by default it uses the authorization bearer header, but you can also pass a custom one as well.
72+
// The jwt secret encoding key to use
73+
"secretKey" : getSystemSetting( "JWT_SECRET", "" ),
74+
// by default it uses the authorization bearer header, but you can also pass a custom one as well or as an rc variable.
7675
"customAuthHeader" : "x-auth-token",
77-
7876
// The expiration in minutes for the jwt tokens
7977
"expiration" : 60,
80-
8178
// If true, enables refresh tokens, longer lived tokens (not implemented yet)
8279
"enableRefreshTokens" : false,
8380
// The default expiration for refresh tokens, defaults to 30 days

models/jwt/JwtService.cfc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ component accessors="true" singleton{
4040
return this;
4141
}
4242

43+
/**
44+
* Runs after DI
45+
*/
46+
function onDIComplete(){
47+
// Verify a few settings just in case
48+
if ( isNull( variables.settings.jwt.secretKey ) || !len( variables.settings.jwt.secretKey ) ){
49+
throw(
50+
message = "The JWT secret key cannot be empty, please fill this out in your `config/ColdBox.cfc` under your cbsecurity settings",
51+
detail = "cbsecurity.jwt.secretKey",
52+
type = "InvalidSecretKey"
53+
)
54+
}
55+
}
56+
4357
/************************************************************************************/
4458
/****************************** TOKEN CREATION METHODS ******************************/
4559
/************************************************************************************/

0 commit comments

Comments
 (0)