Record Class UserInfo

java.lang.Object
java.lang.Record
cloud.opencode.base.oauth2.oidc.UserInfo

public record UserInfo(String sub, String name, String givenName, String familyName, String middleName, String nickname, String preferredUsername, String profile, String picture, String website, String email, Boolean emailVerified, String gender, String birthdate, String zoneinfo, String locale, String phoneNumber, Boolean phoneNumberVerified, Map<String,Object> claims) extends Record
OpenID Connect User Info OpenID Connect 用户信息

Represents user information from the OIDC userinfo endpoint.

表示来自 OIDC userinfo 端点的用户信息。

Standard Claims | 标准声明:

  • sub - Subject identifier - 主题标识符
  • name - Full name - 全名
  • email - Email address - 电子邮件地址
  • picture - Profile picture URL - 头像 URL
  • And more... - 更多...

Usage Examples | 使用示例:

UserInfo userInfo = client.getUserInfo(token);

String userId = userInfo.sub();
String email = userInfo.email();
String name = userInfo.name();

// Get custom claim
Optional<String> locale = userInfo.getClaim("locale");

Features | 主要功能:

  • OIDC UserInfo endpoint response representation - OIDC用户信息端点响应表示
  • Standard profile, email, address claims - 标准配置文件、电子邮件、地址声明

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:
  • Constructor Details

  • Method Details

    • getClaim

      public Optional<Object> getClaim(String name)
      Get a custom claim value 获取自定义声明值
      Parameters:
      name - the claim name | 声明名称
      Returns:
      the claim value | 声明值
    • getClaimAsString

      public Optional<String> getClaimAsString(String name)
      Get a custom claim value as string 获取自定义声明值作为字符串
      Parameters:
      name - the claim name | 声明名称
      Returns:
      the claim value as string | 声明值作为字符串
    • isEmailVerified

      public boolean isEmailVerified()
      Check if email is verified 检查电子邮件是否已验证
      Returns:
      true if email is verified | 如果电子邮件已验证返回 true
    • isPhoneNumberVerified

      public boolean isPhoneNumberVerified()
      Check if phone number is verified 检查电话号码是否已验证
      Returns:
      true if phone number is verified | 如果电话号码已验证返回 true
    • displayName

      public String displayName()
      Get display name (name or preferredUsername or email) 获取显示名称(姓名或首选用户名或电子邮件)
      Returns:
      the display name | 显示名称
    • builder

      public static UserInfo.Builder builder()
      Create a new builder 创建新的构建器
      Returns:
      the builder | 构建器
    • fromJson

      public static UserInfo fromJson(String json)
      Parse user info from JSON response 从 JSON 响应解析用户信息
      Parameters:
      json - the JSON string | JSON 字符串
      Returns:
      the user info | 用户信息
    • 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • sub

      public String sub()
      Returns the value of the sub record component.
      Returns:
      the value of the sub record component
    • name

      public String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • givenName

      public String givenName()
      Returns the value of the givenName record component.
      Returns:
      the value of the givenName record component
    • familyName

      public String familyName()
      Returns the value of the familyName record component.
      Returns:
      the value of the familyName record component
    • middleName

      public String middleName()
      Returns the value of the middleName record component.
      Returns:
      the value of the middleName record component
    • nickname

      public String nickname()
      Returns the value of the nickname record component.
      Returns:
      the value of the nickname record component
    • preferredUsername

      public String preferredUsername()
      Returns the value of the preferredUsername record component.
      Returns:
      the value of the preferredUsername record component
    • profile

      public String profile()
      Returns the value of the profile record component.
      Returns:
      the value of the profile record component
    • picture

      public String picture()
      Returns the value of the picture record component.
      Returns:
      the value of the picture record component
    • website

      public String website()
      Returns the value of the website record component.
      Returns:
      the value of the website record component
    • email

      public String email()
      Returns the value of the email record component.
      Returns:
      the value of the email record component
    • emailVerified

      public Boolean emailVerified()
      Returns the value of the emailVerified record component.
      Returns:
      the value of the emailVerified record component
    • gender

      public String gender()
      Returns the value of the gender record component.
      Returns:
      the value of the gender record component
    • birthdate

      public String birthdate()
      Returns the value of the birthdate record component.
      Returns:
      the value of the birthdate record component
    • zoneinfo

      public String zoneinfo()
      Returns the value of the zoneinfo record component.
      Returns:
      the value of the zoneinfo record component
    • locale

      public String locale()
      Returns the value of the locale record component.
      Returns:
      the value of the locale record component
    • phoneNumber

      public String phoneNumber()
      Returns the value of the phoneNumber record component.
      Returns:
      the value of the phoneNumber record component
    • phoneNumberVerified

      public Boolean phoneNumberVerified()
      Returns the value of the phoneNumberVerified record component.
      Returns:
      the value of the phoneNumberVerified record component
    • claims

      public Map<String,Object> claims()
      Returns the value of the claims record component.
      Returns:
      the value of the claims record component