class Signet::OAuth2::Client

def expires_at_from_id_token id_token

def expires_at_from_id_token id_token
  match = /^[\w=-]+\.([\w=-]+)\.[\w=-]+$/.match id_token.to_s
  return unless match
  json = JSON.parse Base64.urlsafe_decode64 match[1]
  return unless json.key? "exp"
  Time.at json["exp"].to_i
rescue StandardError
  # Shouldn't happen unless we get a garbled ID token
  nil
end