Compare commits

...

3 commits

Author SHA1 Message Date
926bd02bfc Added remote address arguments. 2024-08-25 22:53:05 +00:00
6a17a53290 Fixed typo. 2024-08-25 22:24:03 +00:00
7aa640364e Update auth RPC procedures. 2024-08-25 21:53:34 +00:00

View file

@ -28,7 +28,7 @@ final class OAuth2RpcActions extends RpcActionHandler {
} }
#[RpcProcedure('hanyuu:oauth2:attemptAppAuth')] #[RpcProcedure('hanyuu:oauth2:attemptAppAuth')]
public function procAttemptAppAuth(string $clientId, string $clientSecret = ''): array { public function procAttemptAppAuth(string $remoteAddr, string $clientId, string $clientSecret = ''): array {
try { try {
$appInfo = $this->appsCtx->getData()->getAppInfo(clientId: $clientId, deleted: false); $appInfo = $this->appsCtx->getData()->getAppInfo(clientId: $clientId, deleted: false);
} catch(RuntimeException $ex) { } catch(RuntimeException $ex) {
@ -47,16 +47,14 @@ final class OAuth2RpcActions extends RpcActionHandler {
return [ return [
'method' => 'basic', 'method' => 'basic',
'authed' => $authed, 'type' => $authed ? 'confapp' : 'pubapp',
'app_id' => $appInfo->getId(), 'app' => $appInfo->getId(),
'scope' => ['oauth2'],
]; ];
} }
#[RpcProcedure('hanyuu:oauth2:getTokenInfo')] #[RpcProcedure('hanyuu:oauth2:attemptBearerAuth')]
public function procGetTokenInfo(string $type, string $token): array { public function procAttemptBearerAuth(string $remoteAddr, string $token): array {
if(strcasecmp($type, 'Bearer') !== 0)
return ['method' => 'bearer', 'error' => 'type'];
try { try {
$tokenInfo = $this->oauth2Ctx->getTokensData()->getAccessInfo($token, OAuth2TokensData::ACCESS_BY_TOKEN); $tokenInfo = $this->oauth2Ctx->getTokensData()->getAccessInfo($token, OAuth2TokensData::ACCESS_BY_TOKEN);
} catch(RuntimeException $ex) { } catch(RuntimeException $ex) {
@ -64,15 +62,15 @@ final class OAuth2RpcActions extends RpcActionHandler {
} }
if($tokenInfo->hasExpired()) if($tokenInfo->hasExpired())
return ['method' => 'bearer', 'error' => 'expires']; return ['method' => 'bearer', 'error' => 'expired'];
return [ return [
'method' => 'bearer', 'method' => 'bearer',
'authed' => true, 'type' => $tokenInfo->hasUserId() ? 'user' : 'app',
'app_id' => $tokenInfo->getAppId(), 'app' => $tokenInfo->getAppId(),
'user_id' => $tokenInfo->getUserId() ?? '0', 'user' => $tokenInfo->getUserId() ?? '0',
'scope' => $tokenInfo->getScope(), 'scope' => $tokenInfo->getScopes(),
'expires_in' => $tokenInfo->getRemainingLifetime(), 'expires' => $tokenInfo->getExpiresTime(),
]; ];
} }