Class: OAuth2::MCP::JWTValidator
- Inherits:
-
Object
- Object
- OAuth2::MCP::JWTValidator
- Defined in:
- lib/oauth2/mcp.rb
Overview
Validates JWT bearer tokens with a configured JWKS.
Instance Attribute Summary collapse
-
#algorithms ⇒ Object
readonly
Returns the value of attribute algorithms.
-
#audience ⇒ Object
readonly
Returns the value of attribute audience.
-
#issuer ⇒ Object
readonly
Returns the value of attribute issuer.
-
#leeway ⇒ Object
readonly
Returns the value of attribute leeway.
Instance Method Summary collapse
-
#call(token) ⇒ Object
-
#initialize(jwks:, issuer: nil, audience: nil, algorithms: ["RS256"], leeway: 60) ⇒ JWTValidator
constructor
A new instance of JWTValidator.
Constructor Details
#initialize(jwks:, issuer: nil, audience: nil, algorithms: ["RS256"], leeway: 60) ⇒ JWTValidator
Returns a new instance of JWTValidator.
140 141 142 143 144 145 146 |
# File 'lib/oauth2/mcp.rb', line 140 def initialize(jwks:, issuer: nil, audience: nil, algorithms: ["RS256"], leeway: 60) @jwk_set = build_jwk_set(jwks) @issuer = issuer @audience = audience @algorithms = Array(algorithms).map(&:to_s).freeze @leeway = leeway end |
Instance Attribute Details
#algorithms ⇒ Object (readonly)
Returns the value of attribute algorithms.
138 139 140 |
# File 'lib/oauth2/mcp.rb', line 138 def algorithms @algorithms end |
#audience ⇒ Object (readonly)
Returns the value of attribute audience.
138 139 140 |
# File 'lib/oauth2/mcp.rb', line 138 def audience @audience end |
#issuer ⇒ Object (readonly)
Returns the value of attribute issuer.
138 139 140 |
# File 'lib/oauth2/mcp.rb', line 138 def issuer @issuer end |
#leeway ⇒ Object (readonly)
Returns the value of attribute leeway.
138 139 140 |
# File 'lib/oauth2/mcp.rb', line 138 def leeway @leeway end |
Instance Method Details
#call(token) ⇒ Object
148 149 150 151 152 153 |
# File 'lib/oauth2/mcp.rb', line 148 def call(token) decoded, = JWT.decode(token, nil, true, ) TokenClaims.from_hash(decoded) rescue JWT::DecodeError => e raise InvalidToken, e. end |