dengc367 commented on issue #10749:
URL: https://github.com/apache/gravitino/issues/10749#issuecomment-4231726438
when need support user authentication, we can change the code like below:
```
private static final String PASSWORD = "password";
private static final String USERNAME = "username";
/**
* 擴展後的請求方法,支援 Client Credentials 或 Password Grant 模式
*/
private static Map<String, String> oauthRequest(
String clientId,
String clientSecret,
String username, // 新增:用戶名
String password, // 新增:密碼
List<String> scopes) {
ImmutableMap.Builder<String, String> formData = ImmutableMap.builder();
// 根據是否提供用戶名來判斷 grant_type
if (username != null && password != null) {
formData.put(GRANT_TYPE, PASSWORD);
formData.put(USERNAME, username);
formData.put(PASSWORD, password);
} else {
formData.put(GRANT_TYPE, CLIENT_CREDENTIALS);
}
if (clientId != null) {
formData.put(CLIENT_ID, clientId);
}
if (clientSecret != null) {
formData.put(CLIENT_SECRET, clientSecret);
}
if (scopes != null && !scopes.isEmpty()) {
formData.put(SCOPE, String.join(" ", scopes)); // 確保轉為空格分隔的字串
}
return formData.build();
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]