module Cloudenvoy::Authenticator
Manage token generation and verification
Constants
- JWT_ALG
Algorithm used to sign the verification token
Public Instance Methods
config()
click to toggle source
Return the cloudenvoy configuration. See Cloudenvoy#configure.
@return [Cloudenvoy::Config] The library configuration.
# File lib/cloudenvoy/authenticator.rb, line 18 def config Cloudenvoy.config end
verification_token()
click to toggle source
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.
@return [String] The jwt token
# 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)
click to toggle source
Verify a bearer token (jwt token)
@param [String] bearer_token The token to verify.
@return [Boolean] Return true if the token is valid
# 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)
click to toggle source
Verify a bearer token and raise a `Cloudenvoy::AuthenticationError` if the token is invalid.
@param [String] bearer_token The token to verify.
@return [Boolean] Return true if the token is valid
# File lib/cloudenvoy/authenticator.rb, line 53 def verify!(bearer_token) verify(bearer_token) || raise(AuthenticationError) end