You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Looking through the code, the expiry for a JWT has no means of handling when the expires_at, expires_in, and expires options are set. In order to have them match, you must set both.
I'd expect that if options[:expiry] isn't defined, then it would be overwritten by the same value if expires_in or expires is set, or from options[:expires_at] - Time.current] if expires_at is set.
Environment details
OS: macOS 12.5
Ruby version: 3.1.2
Gem name and version: signet, 0.17.0
Steps to reproduce
Create an OAuth2 client with an expires_at of 1.hour.from_now against a Google Cloud Endpoints API
Use token to make an authenticated API call
Get the error JWT validation failed: TIME_CONSTRAINT_FAILURE
Code example
email=service_account_emailservice_account=JSON.parse(ENV["service_account_json"])oauth=Signet::OAuth2::Client.new({expires_at: 1.hour.from_now,audience: "<redacted>",issuer: email,scope: "email",authorization_uri: "https://accounts.google.com/o/oauth2/auth",token_credential_uri: "https://www.googleapis.com/oauth2/v4/token",client_id: service_account["client_id"],signing_key: OpenSSL::PKey::RSA.new(service_account["private_key"]),sub: email,})jwt=oauth.generate_jwthttp_client=Faraday.new(headers: {"Content-Type"=>"application/json","Authorization"=>"Bearer #{@token}"},request: {timeout: timeout})do |f|
f.request(:json)endres=http_client.get("https://cloudapiendpoint.com")# Successful response hereputsres.success?# true# Wait for 2-3 minutes (to mimic 60 seconds passing and the skew)sleep(150)res=http_client.get("https://cloudapiendpoint.com")//Gettheerrorhere,wewouldexpecttoseethisasavalidrequestputsres.success?# falseputsJSON.parse(res.body)# You can see error output here.
The text was updated successfully, but these errors were encountered:
Looking through the code, the expiry for a JWT has no means of handling when the
expires_at
,expires_in
, andexpires
options are set. In order to have them match, you must set both.I'd expect that if
options[:expiry]
isn't defined, then it would be overwritten by the same value ifexpires_in
orexpires
is set, or fromoptions[:expires_at] - Time.current]
ifexpires_at
is set.Environment details
signet, 0.17.0
Steps to reproduce
expires_at
of1.hour.from_now
against a Google Cloud Endpoints APIJWT validation failed: TIME_CONSTRAINT_FAILURE
Code example
The text was updated successfully, but these errors were encountered: