Compare commits
3 commits
eafe5b3776
...
926bd02bfc
Author | SHA1 | Date | |
---|---|---|---|
926bd02bfc | |||
6a17a53290 | |||
7aa640364e |
1 changed files with 12 additions and 14 deletions
|
@ -28,7 +28,7 @@ final class OAuth2RpcActions extends RpcActionHandler {
|
|||
}
|
||||
|
||||
#[RpcProcedure('hanyuu:oauth2:attemptAppAuth')]
|
||||
public function procAttemptAppAuth(string $clientId, string $clientSecret = ''): array {
|
||||
public function procAttemptAppAuth(string $remoteAddr, string $clientId, string $clientSecret = ''): array {
|
||||
try {
|
||||
$appInfo = $this->appsCtx->getData()->getAppInfo(clientId: $clientId, deleted: false);
|
||||
} catch(RuntimeException $ex) {
|
||||
|
@ -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 $remoteAddr, string $token): array {
|
||||
try {
|
||||
$tokenInfo = $this->oauth2Ctx->getTokensData()->getAccessInfo($token, OAuth2TokensData::ACCESS_BY_TOKEN);
|
||||
} catch(RuntimeException $ex) {
|
||||
|
@ -64,15 +62,15 @@ final class OAuth2RpcActions extends RpcActionHandler {
|
|||
}
|
||||
|
||||
if($tokenInfo->hasExpired())
|
||||
return ['method' => 'bearer', 'error' => 'expires'];
|
||||
return ['method' => 'bearer', 'error' => 'expired'];
|
||||
|
||||
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(),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue