Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support jwt aud validation for hosted apps #117

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions lib/passageidentity/auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,21 @@ def validate_jwt(token)
)
end

audiences = [@auth_origin, @app_id]

claims =
JWT.decode(
token,
nil,
true,
{
aud: @auth_origin,
aud: audiences,
verify_aud: true,
algorithms: ['RS256'],
jwks: @jwks
}
)

claims[0]['sub']
rescue JWT::InvalidIssuerError, JWT::InvalidAudError, JWT::ExpiredSignature, JWT::IncorrectAlgorithm,
JWT::DecodeError => e
Expand Down Expand Up @@ -237,11 +240,6 @@ def get_cache(key)
def set_cache(key:, jwks:)
@app_cache.write(key, jwks, expires_in: 86_400)
end

def jwk_exists(token)
kid = JWT.decode(token, nil, false)[1]['kid']
@jwks['keys'].any? { |jwk| jwk['kid'] == kid }
end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't being used. I forgot to remove it in the previous work.

# rubocop:enable Metrics/AbcSize

deprecate(:authenticate_request, :validate_jwt, 2025, 1)
Expand Down
Loading