Module: JWTEasy
- Defined in:
- lib/jwt_easy.rb,
lib/jwt_easy/result.rb,
lib/jwt_easy/decoder.rb,
lib/jwt_easy/encoder.rb,
lib/jwt_easy/version.rb,
lib/jwt_easy/constants.rb,
lib/jwt_easy/configuration.rb
Overview
JWTEasy is a simple wrapper for the JWT gem that hopes to make generating and consuming various types of JSON web tokens a little easier.
Usage
Generating a plain token without encryption might look something like:
token = JWTEasy.encode(id: 'some-identifying-information')
You’d likely want to configure things before though:
# config/initializers/jwt_easy.rb
JWTEasy.configure do |config|
config.not_before_time = 3_600
config.secret = ENV['JWT_EASY_SECRET']
config.algorithm = JWTEasy::ALGORITHM_HMAC_HS256
end
Of course you’re able to consume tokens just as easily:
JWTEasy.decode(token).id #=> 'some-identifying-information'
Defined Under Namespace
Classes: Configuration, Decoder, Encoder, Result
Constant Summary collapse
- VERSION =
'1.0.0'
- CLAIM_EXPIRATION_TIME =
Short-names for various supported claim types.
:exp
- CLAIM_NOT_BEFORE_TIME =
:nbf
- ALGORITHM_HMAC_HS256 =
Algorithm identifiers for supported algorithms.
'HS256'
Class Method Summary collapse
-
.configuration ⇒ Configuration
Gets the configuration object.
-
.configure {|configuration| ... } ⇒ Object
Allows for configuring the library using a block.
-
.decode(token) ⇒ Result
Instantiates a new decoder with the provided data and the global configuration object.
-
.encode(data) ⇒ String
Instantiates a new encoder and encodes the provided data and the global configuration object.
Class Method Details
.configuration ⇒ Configuration
Gets the configuration object.
If none was set, a new configuration object is instantiated and returned.
47 48 49 |
# File 'lib/jwt_easy.rb', line 47 def configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
Allows for configuring the library using a block.
59 60 61 |
# File 'lib/jwt_easy.rb', line 59 def configure yield(configuration) if block_given? end |