Skip to content

Commit

Permalink
Adjust documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
anakinj committed Oct 4, 2024
1 parent dcbd9d3 commit 6f91412
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 16 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,10 @@ puts decoded_token
An alternative to the `JWT.encode` and `JWT.decode` is to use the `JWT::Token` and `JWT::EncodedToken` objects to verify and sign JWTs.

```ruby
token = JWT::Token.new(payload: { exp: Time.now.to_i + 60, jti: '1234', sub: "my-subject" }, header: {kid: 'hmac'})
token = JWT::Token.new(payload: { exp: Time.now.to_i + 60, jti: '1234', sub: "my-subject" }, header: { kid: 'hmac' })
token.sign!(algorithm: 'HS256', key: "secret")

token.jwt # => "eyJhbGciOiJIUzI1N..."

token.verify_signature!(algorithm: 'HS256', key: "secret")
```

The `JWT::EncodedToken` can be used to create a token object that allows verification of signatures and claims
Expand Down
2 changes: 1 addition & 1 deletion lib/jwt/claims/audience.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module JWT
module Claims
class Audience # :nodoc:
class Audience
def initialize(expected_audience:)
@expected_audience = expected_audience
end
Expand Down
4 changes: 3 additions & 1 deletion lib/jwt/claims/decode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

module JWT
module Claims
module Decode # :nodoc:
# @api private
module Decode
VERIFIERS = {
verify_expiration: ->(options) { Claims::Expiration.new(leeway: options[:exp_leeway] || options[:leeway]) },
verify_not_before: ->(options) { Claims::NotBefore.new(leeway: options[:nbf_leeway] || options[:leeway]) },
Expand All @@ -15,6 +16,7 @@ module Decode # :nodoc:
}.freeze

class << self
# @api private
def verify!(token, options)
VERIFIERS.each do |key, verifier_builder|
next unless options[key]
Expand Down
6 changes: 3 additions & 3 deletions lib/jwt/claims/decode_verifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ module JWT
module Claims
# Context class to contain the data passed to individual claim validators
#
# @private
# @api private
VerificationContext = Struct.new(:payload, keyword_init: true)

# Verifiers to support the ::JWT.decode method
#
# @private
# @api private
module DecodeVerifier
VERIFIERS = {
verify_expiration: ->(options) { Claims::Expiration.new(leeway: options[:exp_leeway] || options[:leeway]) },
Expand All @@ -25,7 +25,7 @@ module DecodeVerifier
private_constant(:VERIFIERS)

class << self
# @private
# @api private
def verify!(payload, options)
VERIFIERS.each do |key, verifier_builder|
next unless options[key] || options[key.to_s]
Expand Down
2 changes: 1 addition & 1 deletion lib/jwt/claims/expiration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module JWT
module Claims
class Expiration # :nodoc:
class Expiration
def initialize(leeway:)
@leeway = leeway || 0
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jwt/claims/issued_at.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module JWT
module Claims
class IssuedAt # :nodoc:
class IssuedAt
def verify!(context:, **_args)
return unless context.payload.is_a?(Hash)
return unless context.payload.key?('iat')
Expand Down
2 changes: 1 addition & 1 deletion lib/jwt/claims/issuer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module JWT
module Claims
class Issuer # :nodoc:
class Issuer
def initialize(issuers:)
@issuers = Array(issuers).map { |item| item.is_a?(Symbol) ? item.to_s : item }
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jwt/claims/jwt_id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module JWT
module Claims
class JwtId # :nodoc:
class JwtId
def initialize(validator:)
@validator = validator
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jwt/claims/not_before.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module JWT
module Claims
class NotBefore # :nodoc:
class NotBefore
def initialize(leeway:)
@leeway = leeway || 0
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jwt/claims/required.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module JWT
module Claims
class Required # :nodoc:
class Required
def initialize(required_claims:)
@required_claims = required_claims
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jwt/claims/subject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module JWT
module Claims
class Subject # :nodoc:
class Subject
def initialize(expected_subject:)
@expected_subject = expected_subject.to_s
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jwt/claims/verification_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module JWT
module Claims
# @private
# @api private
module VerificationMethods
def verify_claims!(*options)
Verifier.verify!(self, *options)
Expand Down

0 comments on commit 6f91412

Please sign in to comment.