Skip to content

Commit

Permalink
Merge pull request #12 from Central-MakeUs/1-social-login-구현하기
Browse files Browse the repository at this point in the history
📝 fix: swagger에 login annotation 제외
  • Loading branch information
tmddus2 authored Jul 29, 2024
2 parents b716dac + 2230ccd commit 2954f6d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package com.example.purithm.global.auth.annotation;

import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Schema;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Parameter(
name = "Authorization",
description = "JWT 인증 토큰",
in = ParameterIn.HEADER,
schema = @Schema(type = "string", example = "Bearer YOUR_JWT_TOKEN")
)
public @interface LoginInfo {

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import com.example.purithm.global.auth.annotation.LoginInfo;
import com.example.purithm.global.auth.entity.CustomOAuth2User;
import com.example.purithm.global.exception.CustomException;
import com.example.purithm.global.exception.Error;
import com.example.purithm.global.response.SuccessResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
Expand All @@ -16,9 +17,10 @@ public SuccessResponse healthCheck() {
}

@GetMapping("/api")
@ResponseBody
public String checkToken(@LoginInfo CustomOAuth2User user) {
return user.getName();
public SuccessResponse checkLoginUser(@LoginInfo CustomOAuth2User user) {
if (user == null) {
throw CustomException.of(Error.INVALID_TOKEN_ERROR);
}
return SuccessResponse.of();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.media.Content;
import io.swagger.v3.oas.models.media.MediaType;
import io.swagger.v3.oas.models.parameters.Parameter;
import io.swagger.v3.oas.models.responses.ApiResponse;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.security.SecurityScheme.In;
import io.swagger.v3.oas.models.security.SecurityScheme.Type;
import java.util.List;
import org.springdoc.core.customizers.OpenApiCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -68,11 +66,6 @@ public OpenApiCustomizer openApiCustomiser() {

operation.getResponses().addApiResponse("401", unauthorizedResponse);
operation.getResponses().addApiResponse("404", notFoundResponse);

List<Parameter> parameters = operation.getParameters();
if (parameters != null) {
operation.getParameters().removeIf(param -> param.getName().equals("LoginInfo"));
}
}));
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.Builder;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;

@Getter
@RequiredArgsConstructor
Expand All @@ -22,10 +21,10 @@ public class SuccessResponse<T> {

public static SuccessResponse of() {

return new SuccessResponse<>(HttpStatus.OK.value(), "ok");
return new SuccessResponse<>(20000, "정상 처리 되었습니다.");
}

public static <T> SuccessResponse<T> of(T data) {
return new SuccessResponse<>(HttpStatus.OK.value(), "ok", data);
return new SuccessResponse<>(20000, "정상 처리 되었습니다.", data);
}
}

0 comments on commit 2954f6d

Please sign in to comment.