Class: AuthProviders::OktaJwtProvider
- Inherits:
-
BearerTokenProvider
- Object
- BearerTokenProvider
- AuthProviders::OktaJwtProvider
- Defined in:
- app/services/auth_providers/okta_jwt_provider.rb
Overview
Validates JWTs issued by Okta using the JWKS endpoint
Instance Method Summary collapse
-
#initialize(issuer:, audience:, jwks_uri:, client_id:) ⇒ OktaJwtProvider
constructor
Initializes the OktaJwtProvider with issuer, audience, and JWKS URI.
-
#valid?(token) ⇒ Boolean
Validates the JWT and returns true if valid, false otherwise.
Constructor Details
#initialize(issuer:, audience:, jwks_uri:, client_id:) ⇒ OktaJwtProvider
Initializes the OktaJwtProvider with issuer, audience, and JWKS URI.
18 19 20 21 22 23 24 |
# File 'app/services/auth_providers/okta_jwt_provider.rb', line 18 def initialize(issuer:, audience:, jwks_uri:, client_id:) super() @issuer = issuer @audience = audience @jwks_uri = jwks_uri @client_id = client_id end |
Instance Method Details
#valid?(token) ⇒ Boolean
Validates the JWT and returns true if valid, false otherwise.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/services/auth_providers/okta_jwt_provider.rb', line 30 def valid?(token) payload, _header = decode(token) # verify signature and claims; raises if invalid return false if payload.blank? return false unless valid_client_id?(payload) true rescue StandardError => e Rails.logger.error( "[OKTA JWT] Validation failure: #{e.class.name}: #{e.} " \ "token_prefix=#{token[0, 10]}... token_length=#{token.length}" ) false end |