Skip to content

Commit efd9a2c

Browse files
fregataaclaude
andcommitted
fix(BA-5584): sync keypair hook with updated plugin source
- Read sign_params from request body instead of hook params - Use attribute access on Row objects instead of dict access - Select full user row for downstream compatibility Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5c6d7ce commit efd9a2c

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

  • src/ai/backend/manager/plugin/keypair

src/ai/backend/manager/plugin/keypair/hook.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ async def authorize(
113113
plugin_config = nmget(shared_config, "plugins.webapp.keypair_auth")
114114
auth_token_name = self.plugin_config["auth_token_name"]
115115

116+
try:
117+
body = await request.json()
118+
except Exception:
119+
body = {}
120+
116121
stoken = params[auth_token_name]
117122
if stoken:
118123
secret = plugin_config["secret"]
@@ -140,35 +145,31 @@ async def authorize(
140145
keypair = result.fetchone()
141146

142147
sign_params = {
143-
"date": params["date"],
144-
"endpoint": params["endpoint"],
145-
"api_version": params["api_version"],
148+
"date": body.get("date"),
149+
"endpoint": body.get("endpoint"),
150+
"api_version": body.get("api_version"),
146151
}
147152
generated_token = await self.sign_token(
148-
sign_method, keypair["secret_key"], sign_params
153+
sign_method, keypair.secret_key, sign_params
149154
)
150155
if generated_token != signature:
151156
raise Reject("Invalid auth token")
152-
user_id = keypair["user"]
157+
user_id = keypair.user
153158

154159
except Exception as e:
155160
log.error("AUTHORIZE_KEYPAIR_HOOK: invalid auth token {}", stoken)
156161
log.error(repr(e))
157162
raise Reject("Invalid auth token") from None
158163

159164
else:
160-
return None
165+
return None # no-op for normal login
161166

162167
async with db.begin() as conn:
163-
query = (
164-
sa.select(users.c.uuid, users.c.status)
165-
.select_from(users)
166-
.where(users.c.uuid == user_id)
167-
)
168+
query = sa.select(users).select_from(users).where(users.c.uuid == user_id)
168169
result = await conn.execute(query)
169170
user = result.fetchone()
170171
if not user:
171172
raise Reject("No such user with access key")
172-
if user["status"] != UserStatus.ACTIVE:
173+
if user.status != UserStatus.ACTIVE:
173174
raise Reject("user is inactivated with access key")
174175
return user

0 commit comments

Comments
 (0)