Record Class ClientCredentialsRequest

java.lang.Object
java.lang.Record
io.leandev.appfuse.security.auth.ClientCredentialsRequest
Record Components:
grantType - grant_type
clientId - client_id
clientSecret - client_secret
scope - scope(本端點尚未支援;非空即拒,見 OAuth2TokenException.invalidScope()

public record ClientCredentialsRequest(String grantType, String clientId, String clientSecret, String scope) extends Record

client_credentials 的請求參數(RFC 6749 §4.4.2

線格式的解析歸 capabilityADR-025 決策二)——RFC 6749 是標準、不是 per-project 決策,讓每個消費端各自實作解析與 client 認證方式,就是線格式漂移的來源。消費端的殼只負責把 HTTP 請求的參數 map 與 Authorization 標頭交進來,並選擇錯誤序列化的方言。

這與登入刻意不對稱:「登入」沒有標準,故其路徑與 DTO 形狀歸殼(ADR-023)。

  • Constructor Details

    • ClientCredentialsRequest

      public ClientCredentialsRequest(String grantType, String clientId, String clientSecret, String scope)
      Creates an instance of a ClientCredentialsRequest record class.
      Parameters:
      grantType - the value for the grantType record component
      clientId - the value for the clientId record component
      clientSecret - the value for the clientSecret record component
      scope - the value for the scope record component
  • Method Details

    • of

      public static ClientCredentialsRequest of(Map<String,String> params, String authorizationHeader)

      由請求參數與 Authorization 標頭組出請求

      支援 RFC 6749 §2.3.1 的兩種 client 認證方式:

      • client_secret_basicAuthorization: Basic base64(urlencode(id) ":" urlencode(secret)) ——規範要求 AS MUST 支援,多數 client library 的預設
      • client_secret_postclient_id / client_secret 置於請求參數

      兩者不得並用(§2.3「client MUST NOT use more than one authentication method」)→ invalid_request

      Parameters:
      params - 請求參數(form-urlencoded 或等價的 JSON 欄位);null 視為空
      authorizationHeader - Authorization 標頭原值;null/非 Basic 則忽略
      Throws:
      OAuth2TokenException - Basic 標頭格式錯誤,或兩種認證方式並用
    • 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.
    • grantType

      public String grantType()
      Returns the value of the grantType record component.
      Returns:
      the value of the grantType record component
    • clientId

      public String clientId()
      Returns the value of the clientId record component.
      Returns:
      the value of the clientId record component
    • clientSecret

      public String clientSecret()
      Returns the value of the clientSecret record component.
      Returns:
      the value of the clientSecret record component
    • scope

      public String scope()
      Returns the value of the scope record component.
      Returns:
      the value of the scope record component