-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JWT::EnocdedToken and JWT::Token for verifying and signing JWT tokens
- Loading branch information
Showing
26 changed files
with
520 additions
and
154 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ coverage/ | |
.byebug_history | ||
*.gem | ||
doc/ | ||
.yardoc/ |
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
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,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module JWT | ||
module Claims | ||
# @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]) }, | ||
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 | ||
# @api private | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module JWT | ||
module Claims | ||
# @api private | ||
module VerificationMethods | ||
def verify_claims!(*options) | ||
Verifier.verify!(self, *options) | ||
end | ||
|
||
def claim_errors(*options) | ||
Verifier.errors(self, *options) | ||
end | ||
|
||
def valid_claims?(*options) | ||
claim_errors(*options).empty? | ||
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
Oops, something went wrong.