Skip to content

Commit

Permalink
Merge pull request #56 from ttoklip/54-fix-web-로그인-방식-sdk-로그인-방식-활용
Browse files Browse the repository at this point in the history
54 fix web 로그인 방식 sdk 로그인 방식 활용
  • Loading branch information
toychip authored Feb 12, 2024
2 parents 15384bc + 752af78 commit aba7db0
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.api.ttoklip.domain.privacy.constant;

public class PrivacyConstant {
public static final String PROFILE_RESPONSE = """
{
"time": "2024-02-13T04:20:45.021367",
"status": 200,
"code": "200",
"message": "요청에 성공하였습니다.",
"result": {
"message": "회원가입 후 개인정보를 추가했습니다."
}
}
""";
public static final String VALIDATE_NICKNAME = """
{
"time": "2024-02-13T04:20:31.659223",
"status": 200,
"code": "200",
"message": "요청에 성공하였습니다.",
"result": {
"message": "닉네임 중복 확인에 통과하였습니다."
}
}
""";
public static final String LOGIN_SUCCESS = """
{
"time": "2024-02-13T04:19:22.753484",
"status": 200,
"code": "200",
"message": "요청에 성공하였습니다.",
"result": {
"jwtToken": "eyJhbGciiJ9.eyJzdWIiY29tIiwiaWF0IjoxNzA3NzY1NTYyLCJleHAiOjjY0NjJ9.UyT8aH-Wjc2Qx7xBWA",
"ifFirstLogin": true
}
}
""";
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package com.api.ttoklip.domain.privacy.controller;

import com.api.ttoklip.domain.privacy.constant.PrivacyConstant;
import com.api.ttoklip.domain.privacy.dto.PrivacyCreateRequest;
import com.api.ttoklip.domain.privacy.service.ProfileService;
import com.api.ttoklip.global.success.Message;
import com.api.ttoklip.global.success.SuccessResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
Expand All @@ -22,12 +30,34 @@ public class ProfileController {

private final ProfileService profileService;

@Operation(summary = "회원가입 직후 개인정보 입력", description = "프로필 사진, 똑립 전용 닉네임, 자취 경력 설정")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "개인정보 입력",
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = SuccessResponse.class),
examples = @ExampleObject(
name = "SuccessResponse",
value = PrivacyConstant.PROFILE_RESPONSE,
description = "개인정보를 추가했습니다."
)))})
@PostMapping("/insert")
public SuccessResponse<Message> register(@ModelAttribute @Validated final PrivacyCreateRequest request) {
Message message = profileService.insert(request);
return new SuccessResponse<>(message);
}

@Operation(summary = "똑립 전용 닉네임 중복 확인", description = "개인정보 입력 전 닉네임 중복 확인")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "닉네임 중복 확인",
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = SuccessResponse.class),
examples = @ExampleObject(
name = "SuccessResponse",
value = PrivacyConstant.VALIDATE_NICKNAME,
description = "닉네임 중복 통과 여부"
)))})
@GetMapping("/check-nickname")
public SuccessResponse<Message> checkNickname(@RequestParam final String nickname) {
Message message = profileService.validNickname(nickname);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
"/favicon.ico"
, "/health"
, "/swagger-ui/**"
, "/oauth/**"
, "/login/**"
,"/api/v1/auth"
, "/**"
).permitAll()
.anyRequest().permitAll());
.anyRequest().authenticated());
http.exceptionHandling(e -> e.accessDeniedHandler(tokenErrorHandler));
http.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
package com.api.ttoklip.global.security.auth.controller;

import com.api.ttoklip.domain.privacy.constant.PrivacyConstant;
import com.api.ttoklip.global.security.auth.dto.LoginRequest;
import com.api.ttoklip.global.security.auth.dto.LoginResponse;
import com.api.ttoklip.global.security.auth.service.AuthService;
import com.api.ttoklip.global.success.SuccessResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -16,6 +24,17 @@
public class AuthController {
private final AuthService authService;

@Operation(summary = "Server 자체 로그인", description = "oauth accessToken으로 로그인")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "oauth accessToken으로 로그인",
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = SuccessResponse.class),
examples = @ExampleObject(
name = "SuccessResponse",
value = PrivacyConstant.LOGIN_SUCCESS,
description = "로그인"
)))})
@PostMapping
public SuccessResponse<LoginResponse> login(final @RequestBody LoginRequest request) {
LoginResponse loginResponse = authService.authenticate(request);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.api.ttoklip.global.security.auth.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class LoginRequest {

@Schema(type = "string", description = "oauth accessToken", example = "AAAAux5O0y30x7G1twup/hPQIdsu/B3i3WL490lghVyU=")
private String accessToken;

@Schema(type = "string", description = "provider", example = "kakao or naver")
private String provider;
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ private boolean isBearer(final String authorizationHeader) {
private boolean isPublicUri(final String requestURI) {
return
requestURI.startsWith("/swagger-ui/**") ||
requestURI.startsWith("/api/health") ||
requestURI.startsWith("/health") ||
requestURI.startsWith("/favicon.ico") ||
requestURI.startsWith("/api/v1/auth/**");
requestURI.startsWith("/api/v1/auth");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@RequiredArgsConstructor
public class JwtProvider {

public static final long ACCESS_TOKEN_VALID_TIME = 15 * 60 * 1000L;
// 24시간 ToDo 개발 편의를 위해 늘려놓음 추후 수정
public static final long ACCESS_TOKEN_VALID_TIME = 24 * 60 * 60 * 1000L;
private final MemberService memberService;
@Value("${jwt.secret.key}")
private String SECRET_KEY;
Expand Down
39 changes: 0 additions & 39 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,45 +27,6 @@ spring:
hibernate:
dialect: org.hibernate.dialect.MySQL8Dialect

security:
oauth2:
client:
registration:
kakao:
client-id: ${KAKAO_CLIENT_ID}
client-secret: ${KAKAO_CLIENT_SECREET}
redirect-uri: ${REDIRECT_URI}
authorization-grant-type: authorization_code
client-authentication-method: client_secret_post
client-name: Kakao
scope:
- profile_nickname
- profile_image

naver:
client-id: ${NAVER_CLIENT_ID}
client-secret: ${NAVER_CLIENT_SECREET}
redirect-uri: ${REDIRECT_URI}
authorization-grant-type: authorization_code
client-name: Naver
scope:
- name
- email
- profile_image

provider:
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

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

cloud:
aws:
credentials:
Expand Down

0 comments on commit aba7db0

Please sign in to comment.