Compare commits
No commits in common. "926bd02bfcc8f2fdd0f23c05d36bc584e5f91598" and "eafe5b3776e28fac561d2ed9e185061c3178a256" have entirely different histories.
926bd02bfc
...
eafe5b3776
1 changed files with 14 additions and 12 deletions
|
@ -28,7 +28,7 @@ final class OAuth2RpcActions extends RpcActionHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[RpcProcedure('hanyuu:oauth2:attemptAppAuth')]
|
#[RpcProcedure('hanyuu:oauth2:attemptAppAuth')]
|
||||||
public function procAttemptAppAuth(string $remoteAddr, string $clientId, string $clientSecret = ''): array {
|
public function procAttemptAppAuth(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,14 +47,16 @@ final class OAuth2RpcActions extends RpcActionHandler {
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'method' => 'basic',
|
'method' => 'basic',
|
||||||
'type' => $authed ? 'confapp' : 'pubapp',
|
'authed' => $authed,
|
||||||
'app' => $appInfo->getId(),
|
'app_id' => $appInfo->getId(),
|
||||||
'scope' => ['oauth2'],
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
#[RpcProcedure('hanyuu:oauth2:attemptBearerAuth')]
|
#[RpcProcedure('hanyuu:oauth2:getTokenInfo')]
|
||||||
public function procAttemptBearerAuth(string $remoteAddr, string $token): array {
|
public function procGetTokenInfo(string $type, 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) {
|
||||||
|
@ -62,15 +64,15 @@ final class OAuth2RpcActions extends RpcActionHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
if($tokenInfo->hasExpired())
|
if($tokenInfo->hasExpired())
|
||||||
return ['method' => 'bearer', 'error' => 'expired'];
|
return ['method' => 'bearer', 'error' => 'expires'];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'method' => 'bearer',
|
'method' => 'bearer',
|
||||||
'type' => $tokenInfo->hasUserId() ? 'user' : 'app',
|
'authed' => true,
|
||||||
'app' => $tokenInfo->getAppId(),
|
'app_id' => $tokenInfo->getAppId(),
|
||||||
'user' => $tokenInfo->getUserId() ?? '0',
|
'user_id' => $tokenInfo->getUserId() ?? '0',
|
||||||
'scope' => $tokenInfo->getScopes(),
|
'scope' => $tokenInfo->getScope(),
|
||||||
'expires' => $tokenInfo->getExpiresTime(),
|
'expires_in' => $tokenInfo->getRemainingLifetime(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue