lucee.Componentmodels.jwt.JwtService
Copyright since 2016 by Ortus Solutions, Corp www.ortussolutions.com --- This is the JWT Services that will provide you with glorious JWT capabilities. Learn more about Json Web Tokens here: https://jwt.io/
Property Summary | ||||
---|---|---|---|---|
type | property | default | serializable | required |
any
|
cbsecurity
|
true
|
false
|
|
any
|
interceptorService
|
true
|
false
|
|
any
|
jwt
|
true
|
false
|
|
any
|
log
|
true
|
false
|
|
any
|
requestService
|
true
|
false
|
|
any
|
settings
|
true
|
false
|
|
any
|
tokenStorage
The token storage provider.
|
true
|
false
|
|
any
|
wirebox
|
true
|
false
|
Constructor Summary | |
---|---|
init()
Constructor. |
Method Summary | |
---|---|
struct
|
annotationValidator(any securedValue, any controller)
DEPRECATED: USE JwtAuthValidator@cbsecurity. |
any
|
attempt(any username, any password, [struct customClaims='[runtime expression]'], [struct refreshCustomClaims='[runtime expression]'])
Attempt to authenticate a user with the auth service and if succesful return a jwt token. |
any
|
authenticate([any payload='[runtime expression]'])
Authenticates a payload that is passed in or auto-discovered if not passed. |
struct
|
decode(any token)
Decode a jwt token. |
string
|
discoverRefreshToken()
Try to discover the jwt refresh token from many incoming resources:. |
string
|
discoverToken()
Try to discover the jwt token from many incoming resources:. |
string
|
encode(struct payload)
Create a jwt token according to the passed in payload. |
any
|
fromEpoch(any target)
Convert an epoch timestamp to local timestamp. |
any
|
fromUser(any user, [struct customClaims='[runtime expression]'], [struct refreshCustomClaims='[runtime expression]'])
Create an access or an access/refresh token(s) according to the passed user object and custom claims. |
private any
|
generateToken(any user, [struct customClaims='[runtime expression]'], [boolean refresh='false'])
Generate an access or refresh token bound to the passed user and custom claims. |
string
|
getCbsecurity()
|
string
|
getInterceptorService()
|
string
|
getJwt()
|
string
|
getLog()
|
struct
|
getPayload()
Get the stored token from `prc. |
string
|
getRequestService()
|
string
|
getSettings()
|
string
|
getToken()
Get the stored token from `prc. |
any
|
getTokenStorage([boolean force='false'])
Get the appropriate token storage provider. |
any
|
getUser()
Get the authenticated user stored on `prc` via the variables. |
string
|
getWirebox()
|
boolean
|
invalidate(any token)
Invalidates the incoming token by removing it from the permanent storage, no key in storage, it's invalid. |
JwtService
|
invalidateAll([boolean async='false'])
Invalidates all tokens in the connected storage provider. |
boolean
|
isLoggedIn()
Shortcut function to our authentication services to check if we are logged in. |
boolean
|
isTokenInStorage(any token)
Verifies if the passed in token exists in the storage provider. |
any
|
logout()
Logout a user and invalidate their access token. |
any
|
onDIComplete()
Runs after DI, here is where we setup the jwt settings for operation. |
struct
|
parseToken([string token='[runtime expression]'], [boolean storeInContext='true'], [boolean authenticate='true'])
Try's to get a jwt token from the authorization header or the custom header. |
struct
|
refreshToken([any token='[runtime expression]'], [struct customClaims='[runtime expression]'], [struct refreshCustomClaims='[runtime expression]'])
Manually refresh tokens by passing a valid refresh token and returning two new tokens:. |
struct
|
ruleValidator(any rule, any controller)
DEPRECATED: USE JwtAuthValidator@cbsecurity. |
any
|
setCbsecurity(any cbsecurity)
|
any
|
setInterceptorService(any interceptorService)
|
any
|
setJwt(any jwt)
|
any
|
setLog(any log)
|
any
|
setRequestService(any requestService)
|
any
|
setSettings(any settings)
|
any
|
setToken(any token)
Store a manual token in `prc. |
any
|
setTokenStorage(any tokenStorage)
|
any
|
setWirebox(any wirebox)
|
any
|
toEpoch(any target)
Convert a target local timestamp to epoch. |
boolean
|
verify(any token)
Verify an incoming token against our jwt library to check if it is valid token only. |
Methods inherited from class lucee.Component |
---|
None |
Constructor Detail |
---|
Constructor
Property Detail |
---|
access
- publicrequired
- falsereturntype
- anyinject
- @cbSecurityserializable
- trueaccess
- publicrequired
- falsereturntype
- anyinject
- coldbox:interceptorServiceserializable
- trueaccess
- publicrequired
- falsereturntype
- anyinject
- provider:jwt@jwtcfmlserializable
- trueaccess
- publicrequired
- falsereturntype
- anyinject
- logbox:logger:{this}serializable
- trueaccess
- publicrequired
- falsereturntype
- anyinject
- coldbox:requestServiceserializable
- trueaccess
- publicrequired
- falsereturntype
- anyinject
- coldbox:moduleSettings:cbSecurityserializable
- trueThe token storage provider
access
- publicrequired
- falsereturntype
- anyserializable
- trueaccess
- publicrequired
- falsereturntype
- anyinject
- wireboxserializable
- trueMethod Detail |
---|
DEPRECATED: USE JwtAuthValidator@cbsecurity
securedValue
controller
Attempt to authenticate a user with the auth service and if succesful return a jwt token
using the information in the authenticated user. If refresh tokens are enabled then you will
get a struct of { access_token : "", refresh_token : "" }
username
- The username to usepassword
- The password to usecustomClaims
- A struct of custom claims to add to the jwt token if successful.refreshCustomClaims
- A struct of custom claims to add to the refresh token if successful.Authenticates a payload that is passed in or auto-discovered if not passed. This will return the user the payload represents via the `sub` claim
payload
- The authentication payload to authenticate, by default we auto discover itDecode a jwt token
token
- The token to decodeTry to discover the jwt refresh token from many incoming resources: - The custom auth header: x-refresh-token - URL/FORM: x-refresh-token
Try to discover the jwt token from many incoming resources: - The custom auth header: x-auth-token - URL/FORM: x-auth-token - Authorization Header
Create a jwt token according to the passed in payload. This method does not store the token in the storage
payload
- The payload to encodeConvert an epoch timestamp to local timestamp
target
- The epoch timestampCreate an access or an access/refresh token(s) according to the passed user object and custom claims.
We are assuming the user is a valid and authenticated user.
If the setting enableRefreshTokens is true, then we will return a struct of tokens:
{ access_token : "", refresh_token : "" }
user
- The user to generate the token for, must implement IAuth and IJwtSubjectcustomClaims
- A struct of custom claims to add to the jwt token if successful.refreshCustomClaims
- A struct of custom claims to add to the refresh token if successful.Generate an access or refresh token bound to the passed user and custom claims.
user
- The user to generate the token for, must implement IAuth and IJwtSubjectcustomClaims
- A struct of custom claims to add to the jwt token if successful.refresh
Get the stored token from `prc.jwt_payload`, if it doesn't exist, it tries to parse it via `parseToken()`, if no token is set this will be an empty struct.
Get the stored token from `prc.jwt_token`, if it doesn't exist, it tries to parse it via `parseToken()`, if not token is set then this will be an empty string.
Get the appropriate token storage provider
force
- If true, it will rebuild the storage using the settings, else it does lazy loading checksGet the authenticated user stored on `prc` via the variables.settings.authentication.prcUserVariable setting. if it doesn't exist, then call parseToken() and try to load it and authenticate it.
Invalidates the incoming token by removing it from the permanent storage, no key in storage, it's invalid.
token
- The token to invalidateInvalidates all tokens in the connected storage provider
async
- Run the clearing asynchronously or not, default is falseShortcut function to our authentication services to check if we are logged in
Verifies if the passed in token exists in the storage provider
token
- The token to checkLogout a user and invalidate their access token
Runs after DI, here is where we setup the jwt settings for operation
Try's to get a jwt token from the authorization header or the custom header defined in the configuration or passed in by you. If it is a valid token and it decodes we will then continue to validate the subject it represents. Once those are satisfied, then it will store it in the `prc` as `prc.jwt_token` and the payload as `prc.jwt_payload`.
token
- The token to parse and validate, if not passed we call the discoverToken() method for you.storeInContext
- By default, the token will be stored in the request contextauthenticate
- By default, the token will be authenticated, you can disable it and do manual authentication.Manually refresh tokens by passing a valid refresh token and returning two new tokens:
{ access_token : "", refresh_token : "" }
token
customClaims
- A struct of custom claims to apply to the new tokensrefreshCustomClaims
- A struct of custom claims to add to the refresh tokenDEPRECATED: USE JwtAuthValidator@cbsecurity
rule
controller
cbsecurity
interceptorService
jwt
log
requestService
settings
Store a manual token in `prc.jwt_token`, and store the decoded version in `prc.jwt_payload`
token
- A custom token to store in the ColdBox event bustokenStorage
wirebox
Convert a target local timestamp to epoch
target
- The local timestampVerify an incoming token against our jwt library to check if it is valid token only No expiration or claim verification
token
- The token to validate