File tree Expand file tree Collapse file tree 3 files changed +21
-7
lines changed Expand file tree Collapse file tree 3 files changed +21
-7
lines changed Original file line number Diff line number Diff line change 11import {
2+ AUTHORIZATION_TOKEN_TYPE ,
23 KAKAO_ACCESS_TOKEN_URL ,
34 KAKAO_AUTHORIZE_PAGE_URL ,
5+ KAKAO_PROFILE_API_URL ,
46 OAUTH_CALLBACK_URL ,
57 OAUTH_TYPE ,
68} from '@constant' ;
@@ -36,7 +38,19 @@ export class OauthKakaoService implements OauthService {
3638 console . log ( access_token ) ;
3739 return access_token ;
3840 }
39- getSocialInfoByAccessToken ( accessToken : string ) : Promise < UserSocialInfo > {
40- throw new Error ( 'Method not implemented.' ) ;
41+
42+ /**
43+ * @link https://developers.kakao.com/docs/latest/ko/kakaologin/rest-api#req-user-info
44+ * @param accessToken
45+ * @returns userInfo
46+ */
47+ async getSocialInfoByAccessToken ( accessToken : string ) : Promise < UserSocialInfo > {
48+ const headers = { Authorization : `${ AUTHORIZATION_TOKEN_TYPE } ${ accessToken } ` } ;
49+ const res = await axios . get ( KAKAO_PROFILE_API_URL , { headers } ) . then ( ( res ) => res . data ) ;
50+
51+ const user = res [ 'kakao_account' ] as UserSocialInfo ;
52+ user . id = res . id ;
53+ user . oauthType = OAUTH_TYPE . KAKAO ;
54+ return user ;
4155 }
4256}
Original file line number Diff line number Diff line change @@ -22,13 +22,11 @@ export class OauthNaverService implements OauthService {
2222 ] . join ( '/' ) ;
2323
2424 getSocialUrl ( ) : string {
25- const queryString = `?response_type=token &client_id=${ this . clientId } &redirect_uri=${ this . callbackUrl } ` ;
25+ const queryString = `?response_type=code &client_id=${ this . clientId } &redirect_uri=${ this . callbackUrl } ` ;
2626 return NAVER_AUTHORIZE_PAGE_URL + queryString ;
2727 }
2828
2929 async getAccessTokenByAuthorizationCode ( authorizationCode : string ) : Promise < string > {
30- if ( ! authorizationCode ) throw new Error ( ) ;
31-
3230 const queryString =
3331 `?grant_type=authorization_code` +
3432 `&client_id=${ this . clientId } &client_secret=${ this . clientSecret } ` +
@@ -57,7 +55,8 @@ export class OauthNaverService implements OauthService {
5755 if ( res . resultcode !== '00' ) {
5856 throw new Error ( res . message ) ;
5957 }
60-
61- return res . response ;
58+ const user = res . response as UserSocialInfo ;
59+ user . oauthType = OAUTH_TYPE . NAVER ;
60+ return user ;
6261 }
6362}
Original file line number Diff line number Diff line change @@ -16,3 +16,4 @@ export const NAVER_PROFILE_API_URL = 'https://openapi.naver.com/v1/nid/me';
1616// KAKAO
1717export const KAKAO_AUTHORIZE_PAGE_URL = 'https://kauth.kakao.com/oauth/authorize' ;
1818export const KAKAO_ACCESS_TOKEN_URL = 'https://kauth.kakao.com/oauth/token' ;
19+ export const KAKAO_PROFILE_API_URL = 'https://kapi.kakao.com/v2/user/me' ;
You can’t perform that action at this time.
0 commit comments