Module: Cloudenvoy::Authenticator
- Defined in:
- lib/cloudenvoy/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 ⇒ Cloudenvoy::Config
Return the cloudenvoy configuration.
-
.verification_token ⇒ String
A Json Web Token (JWT) which is embedded as part of the receiving endpoint and will be used by the processor to authenticate the source of the message.
-
.verify(bearer_token) ⇒ Boolean
Verify a bearer token (jwt token).
-
.verify!(bearer_token) ⇒ Boolean
Verify a bearer token and raise a ‘Cloudenvoy::AuthenticationError` if the token is invalid.
Class Method Details
.config ⇒ Cloudenvoy::Config
Return the cloudenvoy configuration. See Cloudenvoy#configure.
18 19 20 |
# File 'lib/cloudenvoy/authenticator.rb', line 18 def config Cloudenvoy.config end |
.verification_token ⇒ String
A Json Web Token (JWT) which is embedded as part of the receiving endpoint and will be used by the processor to authenticate the source of the message.
28 29 30 |
# File 'lib/cloudenvoy/authenticator.rb', line 28 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)
39 40 41 42 43 |
# File 'lib/cloudenvoy/authenticator.rb', line 39 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 ‘Cloudenvoy::AuthenticationError` if the token is invalid.
53 54 55 |
# File 'lib/cloudenvoy/authenticator.rb', line 53 def verify!(bearer_token) verify(bearer_token) || raise(AuthenticationError) end |