1313
1414namespace chillerlan \OAuth \Providers ;
1515
16- use chillerlan \OAuth \Core \{CSRFToken , OAuth2Provider , PKCE , PKCETrait , TokenRefresh };
16+ use chillerlan \OAuth \Core \{AuthenticatedUser , CSRFToken , OAuth2Provider , PKCE , PKCETrait , TokenRefresh , UserInfo };
1717use function array_merge , implode ;
1818
1919/**
2020 * @see https://developers.tiktok.com/doc/login-kit-web/
2121 * @see https://developers.tiktok.com/doc/oauth-user-access-token-management/
2222 */
23- class TikTok extends OAuth2Provider implements CSRFToken, PKCE , TokenRefresh{
23+ class TikTok extends OAuth2Provider implements CSRFToken, PKCE , TokenRefresh, UserInfo {
2424 use PKCETrait;
2525
2626 public const IDENTIFIER = 'TIKTOK ' ;
2727
28+ public const SCOPES_DELIMITER = ', ' ;
29+
2830 public const SCOPE_VIDEO_UPLOAD = 'video.upload ' ;
2931 public const SCOPE_VIDEO_LIST = 'video.list ' ;
3032 public const SCOPE_VIDEO_PUBLISH = 'video.publish ' ;
@@ -42,6 +44,9 @@ class TikTok extends OAuth2Provider implements CSRFToken, PKCE, TokenRefresh{
4244
4345 public const DEFAULT_SCOPES = [
4446 self ::SCOPE_USER_INFO_BASIC ,
47+ self ::SCOPE_USER_INFO_PROFILE ,
48+ self ::SCOPE_USER_INFO_STATS ,
49+ self ::SCOPE_VIDEO_LIST ,
4550 ];
4651
4752 protected string $ authorizationURL = 'https://www.tiktok.com/v2/auth/authorize/ ' ;
@@ -52,9 +57,6 @@ class TikTok extends OAuth2Provider implements CSRFToken, PKCE, TokenRefresh{
5257 protected string |null $ applicationURL = 'https://developers.tiktok.com/apps/ ' ;
5358 protected string |null $ userRevokeURL = 'https://example.com/user/settings/connections ' ;
5459
55- /**
56- * @inheritDoc
57- */
5860 protected function getAuthorizationURLRequestParams (array $ params , array $ scopes ):array {
5961
6062 unset($ params ['client_secret ' ]);
@@ -74,9 +76,6 @@ protected function getAuthorizationURLRequestParams(array $params, array $scopes
7476 return $ this ->setState ($ params );
7577 }
7678
77- /**
78- * @inheritDoc
79- */
8079 protected function getAccessTokenRequestBodyParams (string $ code ):array {
8180
8281 $ params = [
@@ -90,9 +89,6 @@ protected function getAccessTokenRequestBodyParams(string $code):array{
9089 return $ this ->setCodeVerifier ($ params );
9190 }
9291
93- /**
94- * @inheritDoc
95- */
9692 protected function getRefreshAccessTokenRequestBodyParams (string $ refreshToken ):array {
9793 return [
9894 'client_key ' => $ this ->options ->key ,
@@ -102,4 +98,19 @@ protected function getRefreshAccessTokenRequestBodyParams(string $refreshToken):
10298 ];
10399 }
104100
101+ public function me ():AuthenticatedUser {
102+ $ json = $ this ->getMeResponseData ('/v2/user/info/ ' , ['fields ' => 'open_id,avatar_url,display_name,profile_deep_link,username,is_verified ' ]);
103+
104+ $ userdata = [
105+ 'avatar ' => $ json ['data ' ]['user ' ]['avatar_url ' ],
106+ 'data ' => $ json ,
107+ 'displayName ' => $ json ['data ' ]['user ' ]['display_name ' ],
108+ 'handle ' => $ json ['data ' ]['user ' ]['username ' ],
109+ 'id ' => $ json ['data ' ]['user ' ]['open_id ' ],
110+ 'url ' => $ json ['data ' ]['user ' ]['profile_deep_link ' ],
111+ ];
112+
113+ return new AuthenticatedUser ($ userdata );
114+ }
115+
105116}
0 commit comments