forked from jwt/ruby-jwt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signing and verification of tokens to a token class
- Loading branch information
Showing
14 changed files
with
382 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
module JWT | ||
module Claims | ||
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]) }, | ||
verify_iss: ->(options) { options[:iss] && Claims::Issuer.new(issuers: options[:iss]) }, | ||
verify_iat: ->(*) { Claims::IssuedAt.new }, | ||
verify_jti: ->(options) { Claims::JwtId.new(validator: options[:verify_jti]) }, | ||
verify_aud: ->(options) { options[:aud] && Claims::Audience.new(expected_audience: options[:aud]) }, | ||
verify_sub: ->(options) { options[:sub] && Claims::Subject.new(expected_subject: options[:sub]) }, | ||
required_claims: ->(options) { Claims::Required.new(required_claims: options[:required_claims]) } | ||
}.freeze | ||
|
||
class << self | ||
def verify!(token, options) | ||
VERIFIERS.each do |key, verifier_builder| | ||
next unless options[key] | ||
|
||
verifier_builder&.call(options)&.verify!(context: token) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.