Skip to content

Commit

Permalink
Merge pull request #130 from SW13-Monstera/dev
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
kshired authored Oct 15, 2023
2 parents 3f8c501 + e887d6d commit dd908e1
Show file tree
Hide file tree
Showing 95 changed files with 1,326 additions and 192 deletions.
195 changes: 195 additions & 0 deletions src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,53 @@ include::{snippets}/problems/v2/challenge/path-parameters.adoc[]
include::{snippets}/problems/v2/challenge/response-body.adoc[]
include::{snippets}/problems/v2/challenge/response-fields.adoc[]

==== 문제 좋아요 API ( /api/v2/problems/{postId}/like )

.description
[source]
----
문제를 좋아요하기 위한 API입니다.
HTTP Method : POST
End-Point : /api/v2/problems/{postId}/like
----

.Sample Request
include::{snippets}/problem/v2/like/http-request.adoc[]

.Path parameters
include::{snippets}/problem/v2/like/path-parameters.adoc[]

.Sample Response
include::{snippets}/problem/v2/like/http-response.adoc[]

.Response Body
include::{snippets}/problem/v2/like/response-body.adoc[]
include::{snippets}/problem/v2/like/response-fields.adoc[]

==== 문제 북마크 API ( /api/v2/problems/{postId}/bookmark )

.description
[source]
----
문제를 북마크하기 위한 API입니다.
HTTP Method : POST
End-Point : /api/v2/problems/{postId}/bookmark
----

.Sample Request
include::{snippets}/problem/v2/bookmark/http-request.adoc[]

.Path parameters
include::{snippets}/problem/v2/bookmark/path-parameters.adoc[]

.Sample Response
include::{snippets}/problem/v2/bookmark/http-response.adoc[]

.Response Body
include::{snippets}/problem/v2/bookmark/response-body.adoc[]
include::{snippets}/problem/v2/bookmark/response-fields.adoc[]


=== User API ( /api/v1/users )

==== 유저 조회
Expand Down Expand Up @@ -1013,6 +1060,154 @@ include::{snippets}/problem-sets-find/http-response.adoc[]
include::{snippets}/problem-sets-find/response-body.adoc[]
include::{snippets}/problem-sets-find/response-fields.adoc[]

=== 게시판 API

==== 글 작성 API ( /api/v1/posts )
.description
[source]
----
글을 생성하기 위한 API입니다.
HTTP Method : POST
End-Point : /api/v1/posts
----

.Sample Request
include::{snippets}/posts/create/http-request.adoc[]

.Sample Response
include::{snippets}/posts/create/http-response.adoc[]

.Request Body
include::{snippets}/posts/create/request-body.adoc[]
include::{snippets}/posts/create/request-fields.adoc[]

.Response Body
include::{snippets}/posts/create/response-body.adoc[]
include::{snippets}/posts/create/response-fields.adoc[]

==== 글 조회 API ( /api/v1/problems/{problemId}/posts )
.description
[source]
----
글을 조회하기 위한 API입니다.
HTTP Method : GET
End-Point : /api/v1/problems/{problemId}/posts
----

.Sample Request
include::{snippets}/posts/get/http-request.adoc[]

.Path parameters
include::{snippets}/posts/get/path-parameters.adoc[]

.Sample Response
include::{snippets}/posts/get/http-response.adoc[]

.Response Body
include::{snippets}/posts/get/response-body.adoc[]
include::{snippets}/posts/get/response-fields.adoc[]


==== 글 삭제 API ( /api/v1/posts/{postId} )
.description
[source]
----
글을 삭제하기 위한 API입니다.
HTTP Method : DELETE
End-Point : /api/v1/posts/{postId}
----

.Sample Request
include::{snippets}/posts/delete/http-request.adoc[]

.Path parameters
include::{snippets}/posts/delete/path-parameters.adoc[]

.Sample Response
include::{snippets}/posts/delete/http-response.adoc[]

.Response Body
include::{snippets}/posts/delete/response-body.adoc[]
include::{snippets}/posts/delete/response-fields.adoc[]


==== 글 좋아요 API ( /api/v1/posts/{postId}/like )

.description
[source]
----
글을 좋아요하기 위한 API입니다.
HTTP Method : POST
End-Point : /api/v1/posts/{postId}/like
----

.Sample Request
include::{snippets}/posts/like/http-request.adoc[]

.Path parameters
include::{snippets}/posts/like/path-parameters.adoc[]

.Sample Response
include::{snippets}/posts/like/http-response.adoc[]

.Response Body
include::{snippets}/posts/like/response-body.adoc[]
include::{snippets}/posts/like/response-fields.adoc[]

==== 댓글 작성 API ( /api/v1/comments )
.description
[source]
----
댓글을 생성하기 위한 API입니다.
HTTP Method : POST
End-Point : /api/v1/comments
----

.Sample Request
include::{snippets}/posts/comments/create/http-request.adoc[]

.Path parameters
include::{snippets}/posts/comments/create/path-parameters.adoc[]

.Sample Response
include::{snippets}/posts/comments/create/http-response.adoc[]

.Request Body
include::{snippets}/posts/comments/create/request-body.adoc[]
include::{snippets}/posts/comments/create/request-fields.adoc[]

.Response Body
include::{snippets}/posts/comments/create/response-body.adoc[]
include::{snippets}/posts/comments/create/response-fields.adoc[]

==== 댓글 삭제 API ( /api/v1/comments/{commentId} )
.description
[source]
----
댓글을 삭제하기 위한 API입니다.
HTTP Method : DELETE
End-Point : /api/v1/comments/{commentId}
----

.Sample Request
include::{snippets}/posts/comments/delete/http-request.adoc[]

.Path parameters
include::{snippets}/posts/comments/delete/path-parameters.adoc[]

.Sample Response
include::{snippets}/posts/comments/delete/http-response.adoc[]

.Response Body
include::{snippets}/posts/comments/delete/response-body.adoc[]
include::{snippets}/posts/comments/delete/response-fields.adoc[]

== Back-Office APIs

백오피스에서 사용되는 API입니다.
Expand Down
24 changes: 11 additions & 13 deletions src/main/kotlin/io/csbroker/apiserver/auth/AuthToken.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,17 @@ class AuthToken(
private val key: Key,
) {
constructor(email: String, expiry: Date, key: Key, role: String? = null) : this("", key) {
if (role != null) {
token = createAuthToken(email, expiry, role)
token = if (role != null) {
createAuthToken(email, expiry, role)
} else {
token = createAuthToken(email, expiry)
createAuthToken(email, expiry)
}
}

val tokenClaims: Claims?
get() {
try {
return Jwts.parserBuilder()
.setSigningKey(key)
.build()
.parseClaimsJws(token)
.body
return parseJwt()
} catch (e: SecurityException) {
log.error("Invalid JWT signature.")
} catch (e: MalformedJwtException) {
Expand All @@ -52,11 +48,7 @@ class AuthToken(
val expiredTokenClaims: Claims?
get() {
try {
Jwts.parserBuilder()
.setSigningKey(key)
.build()
.parseClaimsJws(token)
.body
parseJwt()
} catch (e: ExpiredJwtException) {
log.info("Expired JWT token.")
return e.claims
Expand All @@ -77,6 +69,12 @@ class AuthToken(
val isValid: Boolean
get() = tokenClaims != null

private fun parseJwt(): Claims? = Jwts.parserBuilder()
.setSigningKey(key)
.build()
.parseClaimsJws(token)
.body

private fun createAuthToken(email: String, expiry: Date): String {
return Jwts.builder()
.setSubject(email)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class AuthTokenProvider(
.map(::SimpleGrantedAuthority)
.toList()
return UsernamePasswordAuthenticationToken(User(claims.subject, "", authorities), authToken, authorities)
} else {
throw UnAuthorizedException(ErrorCode.TOKEN_INVALID, "올바르지 않은 Token입니다.")
}

throw UnAuthorizedException(ErrorCode.TOKEN_INVALID, "올바르지 않은 Token입니다.")
}
}
24 changes: 6 additions & 18 deletions src/main/kotlin/io/csbroker/apiserver/auth/GithubOAuth2UserInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,9 @@ package io.csbroker.apiserver.auth

class GithubOAuth2UserInfo(
attributes: MutableMap<String, Any>,
) : OAuth2UserInfo(attributes) {

override fun getId(): String {
return (attributes["id"] as Int).toString()
}

override fun getName(): String {
return attributes["login"] as String
}

override fun getEmail(): String {
return attributes["email"] as String
}

override fun getImageUrl(): String {
return attributes["avatar_url"] as String
}
}
) : OAuth2UserInfo(
id = (attributes["id"] as Int).toString(),
name = attributes["login"] as String,
email = attributes["email"] as String,
imageUrl = attributes["avatar_url"] as String,
)
24 changes: 6 additions & 18 deletions src/main/kotlin/io/csbroker/apiserver/auth/GoogleOAuth2UserInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,9 @@ package io.csbroker.apiserver.auth

class GoogleOAuth2UserInfo(
attributes: MutableMap<String, Any>,
) : OAuth2UserInfo(attributes) {

override fun getId(): String {
return attributes["sub"] as String
}

override fun getName(): String {
return attributes["name"] as String
}

override fun getEmail(): String {
return attributes["email"] as String
}

override fun getImageUrl(): String {
return attributes["picture"] as String
}
}
) : OAuth2UserInfo(
id = attributes["sub"] as String,
name = attributes["name"] as String,
email = attributes["email"] as String,
imageUrl = attributes["picture"] as String,
)
15 changes: 5 additions & 10 deletions src/main/kotlin/io/csbroker/apiserver/auth/OAuth2UserInfo.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package io.csbroker.apiserver.auth

abstract class OAuth2UserInfo(
val attributes: MutableMap<String, Any>,
) {
abstract fun getId(): String

abstract fun getName(): String

abstract fun getEmail(): String

abstract fun getImageUrl(): String
}
val id: String,
val name: String,
val email: String,
val imageUrl: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ class OAuth2UserInfoFactory {
return when (providerType) {
ProviderType.GOOGLE -> GoogleOAuth2UserInfo(attributes)
ProviderType.GITHUB -> GithubOAuth2UserInfo(attributes)
else -> throw OAuthProviderMissMatchException(
"프로바이더 타입이 일치하지 않습니다. ${providerType.name}",
)
else -> throw OAuthProviderMissMatchException("프로바이더 타입이 일치하지 않습니다. ${providerType.name}")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TokenAuthenticationFilter(
response: HttpServletResponse,
filterChain: FilterChain,
) {
val tokenStr = getAccessToken(request)
val tokenStr = request.getAccessToken()

tokenStr ?: run {
filterChain.doFilter(request, response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ class OAuth2AuthenticationSuccessHandler(
val user = authentication.principal as OidcUser
val userInfo = OAuth2UserInfoFactory.getOauth2UserInfo(providerType, user.attributes)

return userRepository.findByEmailOrProviderId(userInfo.getEmail(), userInfo.getId())
return userRepository.findByEmailOrProviderId(userInfo.email, userInfo.id)
?: throw EntityNotFoundException(
"유저를 찾을 수 없습니다. email = [${userInfo.getEmail()}], providerId = [${userInfo.getId()}] )",
"유저를 찾을 수 없습니다. email = [${userInfo.email}], providerId = [${userInfo.id}] )",
)
}

Expand Down
Loading

0 comments on commit dd908e1

Please sign in to comment.