Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class CustomOAuth2UserService(
val oAuthUserInfo =
when (provider) {
"google" -> parseGoogle(attributes)
"naver" -> parseNaver(attributes)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저희 네이버 안한다고하지 않았었나요?

"kakao" -> parseKakao(attributes)
else -> throw IllegalArgumentException("지원하지 않는 소셜 로그인입니다.")
}

Expand Down Expand Up @@ -57,6 +59,33 @@ class CustomOAuth2UserService(
profileImageUrl = attributes["picture"] as String?,
)
}

private fun parseNaver(attributes: Map<String, Any>): OAuthUserInfo {
val response = attributes["response"] as Map<String, Any>

return OAuthUserInfo(
oauthId = response["id"] as String,
email = response["email"] as String,
nickname = response["name"] as String,
profileImageUrl = response["profile_image"] as String?,
)
}

private fun parseKakao(attributes: Map<String, Any>): OAuthUserInfo {
val kakaoAccount = attributes["kakao_account"] as? Map<String, Any>
val profile = kakaoAccount?.get("profile") as? Map<String, Any>
val kakaoId = attributes["id"].toString()

// 카카오는 이메일 못받아서 이렇게 처리했음
val email = kakaoAccount?.get("email") as? String ?: "kakao_$kakaoId@social.login"

return OAuthUserInfo(
oauthId = kakaoId,
email = email,
nickname = profile?.get("nickname") as? String ?: "사용자",
profileImageUrl = profile?.get("profile_image_url") as? String,
)
}
}

data class OAuthUserInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class SecurityConfig(
}

if (!isDev) {
addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter::class.java)
addFilterBefore<UsernamePasswordAuthenticationFilter>(jwtAuthenticationFilter)
}
}

Expand Down
42 changes: 41 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,53 @@ spring:
session:
store-type: none # Redis 없어도 실행 가능하도록 변경
timeout: 30m

# Redis 자동 설정 비활성화 (세션 비활성화용)
autoconfigure:
exclude:
- org.springframework.boot.autoconfigure.session.SessionAutoConfiguration
- org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration

security:
oauth2:
client:
registration:
google:
client-id: 11962659605-optp0eb5h1c1ob1b9qie53s83j165qt8.apps.googleusercontent.com
client-secret: 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

env 파일에 올라가야할 내용같습니다 이거는. 시크릿 키 아닌가요?

scope:
- profile
- email
naver:
client-id: At2KDxDK_ppHMuMYqEDL
client-secret: osKwSljl9i
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

시크릿 키는 전부 삭제하시고 다시 PR 부탁드립니다

authorization-grant-type: authorization_code
redirect-uri: "{baseUrl}/login/oauth2/code/{registrationId}"
scope:
- name
- email
- profile_image
client-name: Naver
kakao:
client-id: da170def761db299a36665bbcf50817b
client-secret: SoEKP391vVXvrMy3nANjdWZA7RrheBJW
client-authentication-method: client_secret_post
authorization-grant-type: authorization_code
redirect-uri: "{baseUrl}/login/oauth2/code/{registrationId}"
scope:
- profile_nickname
- profile_image
client-name: Kakao
provider:
naver:
authorization-uri: https://nid.naver.com/oauth2.0/authorize
token-uri: https://nid.naver.com/oauth2.0/token
user-info-uri: https://openapi.naver.com/v1/nid/me
user-name-attribute: response
kakao:
authorization-uri: https://kauth.kakao.com/oauth/authorize
token-uri: https://kauth.kakao.com/oauth/token
user-info-uri: https://kapi.kakao.com/v2/user/me
user-name-attribute: id
# Swagger API 문서 설정 (주니어 개발자용)
springdoc:
api-docs:
Expand Down