opencode-codebuddy-external-auth 1.0.19 → 1.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/plugin.js +15 -0
- package/package.json +1 -1
package/dist/plugin.js
CHANGED
|
@@ -82,14 +82,26 @@ function resolveTenantId(accessToken) {
|
|
|
82
82
|
extractTenantIdFromRoles(roles) ||
|
|
83
83
|
extractTenantIdFromIss(payload?.iss));
|
|
84
84
|
}
|
|
85
|
+
function extractEnterpriseIdFromRoles(roles) {
|
|
86
|
+
if (!roles || roles.length === 0)
|
|
87
|
+
return "";
|
|
88
|
+
for (const role of roles) {
|
|
89
|
+
const match = role.match(/group-admin:([A-Za-z0-9-]+)/);
|
|
90
|
+
if (match?.[1])
|
|
91
|
+
return match[1];
|
|
92
|
+
}
|
|
93
|
+
return "";
|
|
94
|
+
}
|
|
85
95
|
function resolveEnterpriseId(accessToken) {
|
|
86
96
|
if (CONFIG.enterpriseId)
|
|
87
97
|
return CONFIG.enterpriseId;
|
|
88
98
|
const payload = decodeJwtPayload(accessToken);
|
|
99
|
+
const roles = payload?.realm_access?.roles || payload?.resource_access?.account?.roles;
|
|
89
100
|
return (payload?.enterprise_id ||
|
|
90
101
|
payload?.enterpriseId ||
|
|
91
102
|
payload?.ent_id ||
|
|
92
103
|
payload?.entId ||
|
|
104
|
+
extractEnterpriseIdFromRoles(roles) ||
|
|
93
105
|
"");
|
|
94
106
|
}
|
|
95
107
|
function resolveUserId(accessToken) {
|
|
@@ -193,6 +205,8 @@ function pickFallbackModel(models) {
|
|
|
193
205
|
return models[0] || "";
|
|
194
206
|
}
|
|
195
207
|
async function buildAuthHeaders(accessToken) {
|
|
208
|
+
const payload = decodeJwtPayload(accessToken);
|
|
209
|
+
const roles = payload?.realm_access?.roles || payload?.resource_access?.account?.roles;
|
|
196
210
|
const tenantId = cachedTenantId || resolveTenantId(accessToken);
|
|
197
211
|
let enterpriseId = cachedEnterpriseId || resolveEnterpriseId(accessToken);
|
|
198
212
|
const userId = cachedUserId || resolveUserId(accessToken);
|
|
@@ -212,6 +226,7 @@ async function buildAuthHeaders(accessToken) {
|
|
|
212
226
|
if (!warnedIdSummary) {
|
|
213
227
|
warnedIdSummary = true;
|
|
214
228
|
console.log(`[codebuddy-external] IDs: tenant=${tenantId ? "ok" : "empty"}, enterprise=${enterpriseId ? "ok" : "empty"}, user=${userId ? "ok" : "empty"}`);
|
|
229
|
+
console.log(`[codebuddy-external] Token payload: iss=${payload?.iss ? "ok" : "empty"}, sub=${payload?.sub ? "ok" : "empty"}, roles=${Array.isArray(roles) ? roles.length : 0}`);
|
|
215
230
|
}
|
|
216
231
|
if (!tenantId && !warnedTenantId) {
|
|
217
232
|
warnedTenantId = true;
|