Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
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
10 changes: 9 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,12 @@ REDIS_PASSWORD=
# DB_PASSWORD=your-db-password

# 🔧 개발 모드 설정
SPRING_PROFILES_ACTIVE=dev
SPRING_PROFILES_ACTIVE=dev

# 🔐 OAuth 2.0 Client Credentials
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
NAVER_CLIENT_ID=your-naver-client-id
NAVER_CLIENT_SECRET=your-naver-client-secret
KAKAO_CLIENT_ID=your-kakao-client-id
KAKAO_CLIENT_SECRET=your-kakao-client-secret
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: ${GOOGLE_CLIENT_ID}
client-secret: ${GOOGLE_CLIENT_SECRET}
scope:
- profile
- email
naver:
client-id: ${NAVER_CLIENT_ID}
client-secret: ${NAVER_CLIENT_SECRET}
authorization-grant-type: authorization_code
redirect-uri: "{baseUrl}/login/oauth2/code/{registrationId}"
scope:
- name
- email
- profile_image
client-name: Naver
kakao:
client-id: ${KAKAO_CLIENT_ID}
client-secret: ${KAKAO_CLIENT_SECRET}
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