-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 추후 검증 추가 예정 Related to: #16
- Loading branch information
Showing
4 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/main/java/com/umc5th/muffler/domain/member/service/KakaoService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.umc5th.muffler.domain.member.service; | ||
|
||
import com.umc5th.muffler.global.security.jwt.JwtOICDProvider; | ||
import io.jsonwebtoken.Claims; | ||
import io.jsonwebtoken.Header; | ||
import io.jsonwebtoken.Jwt; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class KakaoService { | ||
|
||
private final String ISS = "https://kauth.kakao.com"; | ||
@Value("${jwt.aud}") | ||
private String AUD; | ||
|
||
private final JwtOICDProvider jwtOICDProvider; | ||
|
||
public String login(String idToken) { | ||
Jwt<Header, Claims> jwt = jwtOICDProvider.getUnsignedTokenClaims(idToken, ISS, AUD); | ||
return jwt.getBody().getSubject(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/com/umc5th/muffler/global/security/jwt/JwtOICDProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.umc5th.muffler.global.security.jwt; | ||
|
||
import static com.umc5th.muffler.global.response.code.ErrorCode.INVALID_TOKEN; | ||
|
||
import com.umc5th.muffler.global.response.exception.CommonException; | ||
import io.jsonwebtoken.Claims; | ||
import io.jsonwebtoken.ExpiredJwtException; | ||
import io.jsonwebtoken.Header; | ||
import io.jsonwebtoken.Jwt; | ||
import io.jsonwebtoken.Jwts; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Slf4j | ||
@Component | ||
public class JwtOICDProvider { | ||
private String getUnsignedToken(String token) { | ||
String[] splitToken = token.split("\\."); | ||
if (splitToken.length != 3) { | ||
throw new CommonException(INVALID_TOKEN, "Invalid KakaoIdToken"); | ||
} | ||
return splitToken[0] + "." + splitToken[1] + "."; | ||
} | ||
|
||
public Jwt<Header, Claims> getUnsignedTokenClaims(String token, String iss, String aud) { | ||
try { | ||
return Jwts.parserBuilder() | ||
.requireAudience(aud) | ||
.requireIssuer(iss) | ||
.build() | ||
.parseClaimsJwt(getUnsignedToken(token)); | ||
} catch (ExpiredJwtException e) { | ||
log.error("Expired JWT Token", e); | ||
throw new CommonException(INVALID_TOKEN, "Expired JWT Token"); | ||
} catch (Exception e) { | ||
log.error(e.toString()); | ||
throw new CommonException(INVALID_TOKEN, "Invalid KakaoIdToken"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,8 @@ spring: | |
enable: true | ||
jwt: | ||
secret: ${JWT_SECRET} | ||
aud: ${JWT_AUD} | ||
|
||
server: | ||
servlet: | ||
encoding: | ||
|