A Ruby library for validating Frontegg JWT tokens. This library fetches the JSON Web Key Set (JWKS) from Frontegg's well-known OIDC endpoint and uses it to validate JWT tokens.
Add this line to your application's Gemfile:
gem 'frontegg_jwt_validator'And then execute:
bundle installOr install it yourself as:
gem install frontegg_jwt_validatorrequire 'frontegg_jwt_validator'
# Initialize the validator with your Frontegg domain
validator = FronteggJWTValidator.new('acme.frontegg.com')
# Fetch the JWKS
validator.fetch_jwks
# Validate a token
begin
payload = validator.validate_token('your.jwt.token')
puts "Token is valid!"
puts "Payload: #{payload}"
rescue => e
puts "Error: #{e.message}"
endCreate a .env file in your project root:
FRONTEGG_DOMAIN=your-frontegg-domain
FRONTEGG_TOKEN=your-jwt-token
Then use the example script:
ruby examples/validate_token.rbAfter checking out the repo, run bundle install to install dependencies.
Run the test suite:
bundle exec rspec- The validator fetches the JSON Web Key Set (JWKS) from Frontegg's well-known OIDC endpoint
- It extracts the appropriate signing key based on the token's
kid(Key ID) - The token is validated using the public key
- If valid, the token payload is returned
The validator will raise exceptions for:
- Invalid tokens
- Missing or invalid JWKS
- Missing or invalid signing keys
- Network errors when fetching JWKS
- Always validate tokens in a secure environment
- Keep your tokens secure and never expose them in logs or error messages
- Use HTTPS for all communications
- Regularly update the JWKS as keys may rotate
Bug reports and pull requests are welcome on GitHub at https://github.com/yourusername/frontegg_jwt_validator.
The gem is available as open source under the terms of the MIT License.