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 ClassesModifier and TypeClassDescriptionstatic classDeviceCodeResponse Builder DeviceCodeResponse 构建器 -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault polling interval in seconds 默认轮询间隔(秒) -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DeviceCodeResponse.Builderbuilder()Create a new builder 创建新的构建器Returns the value of thecreatedAtrecord component.Returns the value of thedeviceCoderecord component.final booleanIndicates whether some other object is "equal to" this one.Get the expiration time 获取过期时间intReturns the value of theexpiresInrecord component.Get the best verification URI (complete if available, otherwise basic) 获取最佳验证 URI(如果可用则返回完整的,否则返回基本的)final inthashCode()Returns a hash code value for this object.booleanCheck if verification URI complete is available 检查完整验证 URI 是否可用intinterval()Returns the value of theintervalrecord component.booleanCheck if the device code has expired 检查设备码是否已过期longGet remaining time in seconds 获取剩余时间(秒)final StringtoString()Returns a string representation of this record class.userCode()Returns the value of theuserCoderecord component.Returns the value of theverificationUrirecord component.Returns the value of theverificationUriCompleterecord component.
-
Field Details
-
DEFAULT_INTERVAL
public static final int DEFAULT_INTERVALDefault polling interval in seconds 默认轮询间隔(秒)- See Also:
-
-
Constructor Details
-
DeviceCodeResponse
-
-
Method Details
-
isExpired
public boolean isExpired()Check if the device code has expired 检查设备码是否已过期- Returns:
- true if expired | 已过期返回 true
-
expiresAt
-
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
Get the best verification URI (complete if available, otherwise basic) 获取最佳验证 URI(如果可用则返回完整的,否则返回基本的)- Returns:
- the verification URI | 验证 URI
-
builder
Create a new builder 创建新的构建器- Returns:
- the builder | 构建器
-
toString
-
hashCode
-
equals
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 withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
deviceCode
Returns the value of thedeviceCoderecord component.- Returns:
- the value of the
deviceCoderecord component
-
userCode
Returns the value of theuserCoderecord component.- Returns:
- the value of the
userCoderecord component
-
verificationUri
Returns the value of theverificationUrirecord component.- Returns:
- the value of the
verificationUrirecord component
-
verificationUriComplete
Returns the value of theverificationUriCompleterecord component.- Returns:
- the value of the
verificationUriCompleterecord component
-
expiresIn
public int expiresIn()Returns the value of theexpiresInrecord component.- Returns:
- the value of the
expiresInrecord component
-
interval
public int interval()Returns the value of theintervalrecord component.- Returns:
- the value of the
intervalrecord component
-
createdAt
Returns the value of thecreatedAtrecord component.- Returns:
- the value of the
createdAtrecord component
-