Record Class ParResponse

java.lang.Object
java.lang.Record
cloud.opencode.base.oauth2.par.ParResponse

public record ParResponse(String requestUri, int expiresIn, Instant createdAt) extends Record
Pushed Authorization Request Response (RFC 9126) 推送授权请求响应(RFC 9126)

Immutable record representing the response from a Pushed Authorization Request (PAR) endpoint as defined in RFC 9126. Contains the request_uri that the client uses to reference the authorization request in a subsequent authorization request.

不可变记录,表示 RFC 9126 定义的推送授权请求(PAR)端点的响应。包含客户端在后续授权请求中 用于引用授权请求的 request_uri。

Features | 主要功能:

  • RFC 9126 compliant PAR response - 符合 RFC 9126 的 PAR 响应
  • Expiration tracking with createdAt timestamp - 通过 createdAt 时间戳跟踪过期
  • Convenience methods for expiration checking - 便捷的过期检查方法

Usage Examples | 使用示例:

// Check PAR response validity
// 检查 PAR 响应的有效性
ParResponse response = par.push(params);
if (!response.isExpired()) {
    String authUrl = par.buildAuthorizationUrl(authEndpoint, response, clientId);
    // Redirect user to authUrl
}

Security | 安全性:

  • Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
  • Null-safe: Yes (validates requestUri) - 空值安全: 是(验证 requestUri)
Since:
JDK 25, opencode-base-oauth2 V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    ParResponse(String requestUri, int expiresIn, Instant createdAt)
    Compact constructor with validation.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the value of the createdAt record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    Get the expiration time.
    int
    Returns the value of the expiresIn record component.
    final int
    Returns a hash code value for this object.
    boolean
    Check if the PAR response has expired.
    long
    Get the remaining time in seconds before expiration.
    Returns the value of the requestUri record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ParResponse

      public ParResponse(String requestUri, int expiresIn, Instant createdAt)
      Compact constructor with validation. 带验证的紧凑构造器。
  • Method Details

    • isExpired

      public boolean isExpired()
      Check if the PAR response has expired. 检查 PAR 响应是否已过期。
      Returns:
      true if expired | 已过期返回 true
    • expiresAt

      public Instant expiresAt()
      Get the expiration time. 获取过期时间。
      Returns:
      the expiration instant | 过期时间
    • remainingSeconds

      public long remainingSeconds()
      Get the remaining time in seconds before expiration. 获取过期前的剩余时间(秒)。
      Returns:
      remaining seconds, or 0 if expired | 剩余秒数,已过期则返回 0
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • requestUri

      public String requestUri()
      Returns the value of the requestUri record component.
      Returns:
      the value of the requestUri record component
    • expiresIn

      public int expiresIn()
      Returns the value of the expiresIn record component.
      Returns:
      the value of the expiresIn record component
    • createdAt

      public Instant createdAt()
      Returns the value of the createdAt record component.
      Returns:
      the value of the createdAt record component