Module: Cloudtasker::Authenticator
- Defined in:
- lib/cloudtasker/authenticator.rb
Overview
Manage token generation and verification
Constant Summary collapse
- JWT_ALG =
Algorithm used to sign the verification token
'HS256'
Class Method Summary collapse
-
.config ⇒ Cloudtasker::Config
Return the cloudtasker configuration.
-
.verification_token ⇒ String
A Json Web Token (JWT) which will be used by the processor to authenticate the job.
-
.verify(bearer_token) ⇒ Boolean
Verify a bearer token (jwt token).
-
.verify!(bearer_token) ⇒ Boolean
Verify a bearer token and raise a ‘Cloudtasker::AuthenticationError` if the token is invalid.
Class Method Details
.config ⇒ Cloudtasker::Config
Return the cloudtasker configuration. See Cloudtasker#configure.
16 17 18 |
# File 'lib/cloudtasker/authenticator.rb', line 16 def config Cloudtasker.config end |
.verification_token ⇒ String
A Json Web Token (JWT) which will be used by the processor to authenticate the job.
26 27 28 |
# File 'lib/cloudtasker/authenticator.rb', line 26 def verification_token JWT.encode({ iat: Time.now.to_i }, config.secret, JWT_ALG) end |
.verify(bearer_token) ⇒ Boolean
Verify a bearer token (jwt token)
37 38 39 40 41 |
# File 'lib/cloudtasker/authenticator.rb', line 37 def verify(bearer_token) JWT.decode(bearer_token, config.secret) rescue JWT::VerificationError, JWT::DecodeError false end |
.verify!(bearer_token) ⇒ Boolean
Verify a bearer token and raise a ‘Cloudtasker::AuthenticationError` if the token is invalid.
51 52 53 |
# File 'lib/cloudtasker/authenticator.rb', line 51 def verify!(bearer_token) verify(bearer_token) || raise(AuthenticationError) end |