Record Class DeviceCodeResponse

java.lang.Object
java.lang.Record
cloud.opencode.base.oauth2.grant.DeviceCodeResponse

public record DeviceCodeResponse(String deviceCode, String userCode, String verificationUri, String verificationUriComplete, int expiresIn, int interval, Instant createdAt) extends Record
Device Code Response Record 设备码响应记录

Represents the response from a device authorization endpoint (RFC 8628).

表示设备授权端点的响应(RFC 8628)。

Usage Examples | 使用示例:

// Get device code response
DeviceCodeResponse response = client.requestDeviceCode();

// Display to user
System.out.println("Please visit: " + response.verificationUri());
System.out.println("Enter code: " + response.userCode());

// Poll for token
while (!response.isExpired()) {
    Thread.sleep(response.interval() * 1000);
    Optional<OAuth2Token> token = client.pollToken(response.deviceCode());
    if (token.isPresent()) {
        // Success!
        break;
    }
}

Features | 主要功能:

  • Represents OAuth2 device code grant response - 表示OAuth2设备码授权响应
  • Contains device code, user code, and verification URI - 包含设备码、用户码和验证URI

Security | 安全性:

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

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    DeviceCodeResponse Builder DeviceCodeResponse 构建器
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Default polling interval in seconds 默认轮询间隔(秒)
  • Constructor Summary

    Constructors
    Constructor
    Description
    DeviceCodeResponse(String deviceCode, String userCode, String verificationUri, String verificationUriComplete, int expiresIn, int interval, Instant createdAt)
    Compact constructor with validation 带验证的紧凑构造器
  • Method Summary

    Modifier and Type
    Method
    Description
    Create a new builder 创建新的构建器
    Returns the value of the createdAt record component.
    Returns the value of the deviceCode 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.
    Get the best verification URI (complete if available, otherwise basic) 获取最佳验证 URI(如果可用则返回完整的,否则返回基本的)
    final int
    Returns a hash code value for this object.
    boolean
    Check if verification URI complete is available 检查完整验证 URI 是否可用
    int
    Returns the value of the interval record component.
    boolean
    Check if the device code has expired 检查设备码是否已过期
    long
    Get remaining time in seconds 获取剩余时间(秒)
    final String
    Returns a string representation of this record class.
    Returns the value of the userCode record component.
    Returns the value of the verificationUri record component.
    Returns the value of the verificationUriComplete record component.

    Methods inherited from class Object

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

    • DEFAULT_INTERVAL

      public static final int DEFAULT_INTERVAL
      Default polling interval in seconds 默认轮询间隔(秒)
      See Also:
  • Constructor Details

    • DeviceCodeResponse

      public DeviceCodeResponse(String deviceCode, String userCode, String verificationUri, String verificationUriComplete, int expiresIn, int interval, Instant createdAt)
      Compact constructor with validation 带验证的紧凑构造器
  • Method Details

    • isExpired

      public boolean isExpired()
      Check if the device code has expired 检查设备码是否已过期
      Returns:
      true if expired | 已过期返回 true
    • expiresAt

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

      public long remainingSeconds()
      Get remaining time in seconds 获取剩余时间(秒)
      Returns:
      remaining seconds, or 0 if expired | 剩余秒数,已过期则返回 0
    • hasVerificationUriComplete

      public boolean hasVerificationUriComplete()
      Check if verification URI complete is available 检查完整验证 URI 是否可用
      Returns:
      true if available | 可用返回 true
    • getBestVerificationUri

      public String getBestVerificationUri()
      Get the best verification URI (complete if available, otherwise basic) 获取最佳验证 URI(如果可用则返回完整的,否则返回基本的)
      Returns:
      the verification URI | 验证 URI
    • builder

      public static DeviceCodeResponse.Builder builder()
      Create a new builder 创建新的构建器
      Returns:
      the builder | 构建器
    • 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.
    • deviceCode

      public String deviceCode()
      Returns the value of the deviceCode record component.
      Returns:
      the value of the deviceCode record component
    • userCode

      public String userCode()
      Returns the value of the userCode record component.
      Returns:
      the value of the userCode record component
    • verificationUri

      public String verificationUri()
      Returns the value of the verificationUri record component.
      Returns:
      the value of the verificationUri record component
    • verificationUriComplete

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

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

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

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