From 7aa640364e39851a1949705c98f7f3e7f1554420 Mon Sep 17 00:00:00 2001 From: flashwave Date: Sun, 25 Aug 2024 21:53:34 +0000 Subject: [PATCH] Update auth RPC procedures. --- src/OAuth2/OAuth2RpcActions.php | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/OAuth2/OAuth2RpcActions.php b/src/OAuth2/OAuth2RpcActions.php index 57617dd..78e6115 100644 --- a/src/OAuth2/OAuth2RpcActions.php +++ b/src/OAuth2/OAuth2RpcActions.php @@ -47,16 +47,14 @@ final class OAuth2RpcActions extends RpcActionHandler { return [ 'method' => 'basic', - 'authed' => $authed, - 'app_id' => $appInfo->getId(), + 'type' => $authed ? 'confapp' : 'pubapp', + 'app' => $appInfo->getId(), + 'scope' => ['oauth2'], ]; } - #[RpcProcedure('hanyuu:oauth2:getTokenInfo')] - public function procGetTokenInfo(string $type, string $token): array { - if(strcasecmp($type, 'Bearer') !== 0) - return ['method' => 'bearer', 'error' => 'type']; - + #[RpcProcedure('hanyuu:oauth2:attemptBearerAuth')] + public function procAttemptBearerAuth(string $token): array { try { $tokenInfo = $this->oauth2Ctx->getTokensData()->getAccessInfo($token, OAuth2TokensData::ACCESS_BY_TOKEN); } catch(RuntimeException $ex) { @@ -68,11 +66,11 @@ final class OAuth2RpcActions extends RpcActionHandler { return [ 'method' => 'bearer', - 'authed' => true, - 'app_id' => $tokenInfo->getAppId(), - 'user_id' => $tokenInfo->getUserId() ?? '0', - 'scope' => $tokenInfo->getScope(), - 'expires_in' => $tokenInfo->getRemainingLifetime(), + 'type' => $tokenInfo->hasUserId() ? 'user' : 'app', + 'app' => $tokenInfo->getAppId(), + 'user' => $tokenInfo->getUserId() ?? '0', + 'scope' => $tokenInfo->getScopes(), + 'expires' => $tokenInfo->getExpiresTime(), ]; }