Skip to content

Commit eb8230d

Browse files
committed
jwtAuth() helper
1 parent b22bc74 commit eb8230d

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

helpers/mixins.cfm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<cfscript>
2-
function jwt() {
2+
function jwtAuth() {
33
return wirebox.getInstance( "JwtService@cbSecurity" );
44
}
55
</cfscript>

test-harness/modules_app/api/handlers/Home.cfc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ component {
3737
param rc.password = "";
3838

3939
try {
40-
var token = jwt().attempt( rc.username, rc.password );
40+
var token = jwtAuth().attempt( rc.username, rc.password );
4141
return {
4242
"error" : true,
4343
"data" : token,
44-
"message" : "Bearer token created and it expires in #jwt().getSettings().jwt.expiration# minutes"
44+
"message" : "Bearer token created and it expires in #jwtAuth().getSettings().jwt.expiration# minutes"
4545
};
4646
} catch ( "InvalidCredentials" e ) {
4747
event.setHTTPHeader( statusCode = 401, statusText = "Not Authorized" );
@@ -61,11 +61,11 @@ component {
6161
prc.oUser = populateModel( "User" );
6262
userService.create( prc.oUser );
6363

64-
var token = jwt().fromuser( prc.oUser );
64+
var token = jwtAuth().fromuser( prc.oUser );
6565
return {
6666
"error" : true,
6767
"data" : token,
68-
"message" : "User registered correctly and Bearer token created and it expires in #jwt().getSettings().jwt.expiration# minutes"
68+
"message" : "User registered correctly and Bearer token created and it expires in #jwtAuth().getSettings().jwt.expiration# minutes"
6969
};
7070
}
7171

@@ -83,15 +83,15 @@ component {
8383
function gen( event, rc, prc ){
8484
var timestamp = now();
8585
var userId = 123;
86-
return jwt().encode( {
86+
return jwtAuth().encode( {
8787
// Issuing authority
8888
"iss" : event.getHTMLBaseURL(),
8989
// Token creation
90-
"iat" : jwt().toEpoch( timestamp ),
90+
"iat" : jwtAuth().toEpoch( timestamp ),
9191
// The subject identifier
9292
"sub" : 123,
9393
// The token expiration
94-
"exp" : jwt().toEpoch( dateAdd( "s", 1, timestamp ) ),
94+
"exp" : jwtAuth().toEpoch( dateAdd( "s", 1, timestamp ) ),
9595
// The unique identifier of the token
9696
"jti" : hash( timestamp & userId ),
9797
// Get the user scopes for the JWT token
@@ -106,7 +106,7 @@ component {
106106
*/
107107
function dec( event, rc, prc ){
108108
var token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpYXQiOjE1NjkyNzI0NjQsInJvbGUiOiJhZG1pbiIsInNjb3BlcyI6W10sImlzcyI6Imh0dHA6Ly8xMjcuMC4wLjE6NTY1OTYvIiwic3ViIjoxMjMsImV4cCI6MTU2OTI3MjQ2NSwianRpIjoiRTRDNEM3MDdFNjA1MzQwRDkxRDNCMDBCMkI4NTdFNDMifQ.N2rT_b_Xp8e9Hw0O7yVork6Fg8aC7RKf0Fv-Bmu7Iv5CVvFrmk1gkF_oKeXmcl22MiwhB2oQJhMNZiFa5OfSKw";
109-
return jwt().decode( token );
109+
return jwtAuth().decode( token );
110110
}
111111

112112
}

0 commit comments

Comments
 (0)