Skip to content

Parse JWT exp claim from token to set expires_at_millis_#10

Open
wgtmac wants to merge 3 commits intomainfrom
parse-jwt-exp-claim-409089801954026600
Open

Parse JWT exp claim from token to set expires_at_millis_#10
wgtmac wants to merge 3 commits intomainfrom
parse-jwt-exp-claim-409089801954026600

Conversation

@wgtmac
Copy link
Copy Markdown
Owner

@wgtmac wgtmac commented Mar 24, 2026

This change implements parsing of the JWT exp (expiration) claim from the OAuth2 token in AuthProperties.

Key changes:

  1. TransformUtil: Added Base64UrlDecode to handle RFC 4648 Base64Url encoding, which is used in JWT payloads. The implementation is robust against integer overflow and handles both standard and URL-safe Base64 characters.
  2. AuthProperties:
    • Updated FromProperties to detect if a token is present.
    • If present and formatted as a JWT (three parts separated by dots), it decodes the payload part and extracts the exp claim.
    • The expiration time is converted from seconds to milliseconds and stored in expires_at_millis_.
    • Added a public getter expires_at_millis().
  3. Tests:
    • Added tests for Base64UrlDecode with various test vectors, including edge cases and invalid characters.
    • Added tests in AuthManagerTest to verify that AuthProperties correctly parses the expiration time from a mock JWT token and handles invalid tokens gracefully.

PR created automatically by Jules for task 409089801954026600 started by @wgtmac

- Implement Base64UrlDecode in TransformUtil.
- Update AuthProperties::FromProperties to parse the JWT exp claim from the token and set expires_at_millis_.
- Add expires_at_millis() getter to AuthProperties.
- Add unit tests for Base64UrlDecode and JWT expiration parsing.

Co-authored-by: wgtmac <4684607+wgtmac@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

- Implement robust Base64UrlDecode in TransformUtil using unsigned integers to avoid undefined behavior.
- Update AuthProperties::FromProperties to parse the JWT exp claim from the token and set expires_at_millis_.
- Add expires_at_millis() getter to AuthProperties.
- Add unit tests for Base64UrlDecode and JWT expiration parsing, using standard matchers and explicit type casting for Windows/MSVC compatibility.

Co-authored-by: wgtmac <4684607+wgtmac@users.noreply.github.com>
@wgtmac
Copy link
Copy Markdown
Owner Author

wgtmac commented Mar 24, 2026

@jules fix all ci failures

- Implement robust Base64UrlDecode in TransformUtil using unsigned integers to avoid undefined behavior.
- Update AuthProperties::FromProperties to parse the JWT exp claim from the token and set expires_at_millis_.
- Add expires_at_millis() getter to AuthProperties.
- Add unit tests for Base64UrlDecode and JWT expiration parsing.
- Improve HasValue matcher to support non-matcher arguments and fix MSVC template issues by using SafeMatcherCast and DescribeMatcher.

Co-authored-by: wgtmac <4684607+wgtmac@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant