Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(oauth2): simple userinfo endpoint #43684

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0b9253b
feat(oauth2): simple userinfo endpoint
hardviper Feb 20, 2024
bbbfe42
feat(oauth2): fix check null value, added more user_info field
hardviper Feb 21, 2024
21a1825
feat(oauth2): fix lint
hardviper Feb 21, 2024
fb8b061
feat(oauth2): fix deprecated method
hardviper Feb 22, 2024
4a645fc
Update apps/oauth2/lib/Controller/OauthApiController.php
hardviper Feb 26, 2024
fecc3ef
Update apps/oauth2/lib/Controller/OauthApiController.php
hardviper Feb 26, 2024
a54d0cd
Update apps/oauth2/lib/Controller/OauthApiController.php
hardviper Feb 26, 2024
c6efbee
feat(oauth2): user not found exception
hardviper Feb 26, 2024
3407a92
feat(oauth2): replace getAvatar with a named route
hardviper Feb 26, 2024
6405b27
feat(oauth2): parted name for ru locale
hardviper Feb 26, 2024
d6e0ddf
feat(oauth2): fix avatar absolute url
hardviper Feb 26, 2024
1ee8a1a
feat(oauth2): fix early return
hardviper Feb 28, 2024
81a92b8
Merge branch 'master' into feat/oauth2/userinfo
hardviper Mar 11, 2024
03cf5d9
feat(oauth2): separation name feature config
hardviper Mar 11, 2024
1e264ac
feat(oauth2): optional separate name
hardviper Mar 11, 2024
bf42920
feat(oauth2): add unit-test for GetUserInfo
hardviper Mar 13, 2024
b6f6651
feat(oauth2): add unit-test for GetUserInfo separate mode
hardviper Mar 13, 2024
a424e96
Update apps/oauth2/lib/Controller/OauthApiController.php
hardviper Mar 13, 2024
1c1fa9e
Update apps/oauth2/lib/Controller/OauthApiController.php
hardviper Mar 13, 2024
dd9edb8
Update apps/oauth2/tests/Controller/OauthApiControllerTest.php
hardviper Mar 13, 2024
16edc40
Update apps/oauth2/tests/Controller/OauthApiControllerTest.php
hardviper Mar 13, 2024
b077248
Update config/config.sample.php
hardviper Mar 13, 2024
540eb16
feat(oauth2): fix var name
hardviper Mar 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/oauth2/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,10 @@
'url' => '/api/v1/token',
'verb' => 'POST'
],
[
'name' => 'OauthApi#getUserInfo',
'url' => '/api/v1/userinfo',
'verb' => 'GET'
],
],
];
32 changes: 32 additions & 0 deletions apps/oauth2/lib/Controller/OauthApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
use OCP\Authentication\Exceptions\InvalidTokenException;
use OCP\DB\Exception;
use OCP\IRequest;
use OCP\IUserSession;
use OCP\IURLGenerator;
use OCP\Security\Bruteforce\IThrottler;
use OCP\Security\ICrypto;
use OCP\Security\ISecureRandom;
Expand All @@ -62,6 +64,8 @@ public function __construct(
private LoggerInterface $logger,
private IThrottler $throttler,
private ITimeFactory $timeFactory,
private IUserSession $userSession,
private IURLGenerator $urlGenerator,
) {
parent::__construct($appName, $request);
}
Expand Down Expand Up @@ -226,4 +230,32 @@ public function getToken(
]
);
}

/**
* @PublicPage
* @NoCSRFRequired
*
* @return JSONResponse
*/
public function getUserInfo() {
hardviper marked this conversation as resolved.
Show resolved Hide resolved
$user = $this->userSession->getUser();
if ($user) {
hardviper marked this conversation as resolved.
Show resolved Hide resolved
$displayName = $user->getDisplayName();
$partedName = explode(' ', $displayName);
$userId = $user->getUID();
$response = new JSONResponse([
'sub' => $userId,
'name' => $displayName,
'given_name' => $partedName[0],
'family_name' => $partedName[1] ?? $partedName[0],
hardviper marked this conversation as resolved.
Show resolved Hide resolved
'email' => $user->getEMailAddress(),
'picture' => $this->urlGenerator->getAbsoluteURL("index.php/avatar/$userId/512"),
hardviper marked this conversation as resolved.
Show resolved Hide resolved
]);
}else{
hardviper marked this conversation as resolved.
Show resolved Hide resolved
$response = new JSONResponse([
'error' => 'user_not_found',
], Http::STATUS_NOT_FOUND);
}
return $response;
}
}