Skip to content

Commit

Permalink
🎨 AuthTokenController 구조 및 형식 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
min-0 committed Aug 19, 2024
1 parent 4ce172d commit bf7c372
Showing 1 changed file with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,41 @@

import com.dnd.dndtravel.auth.apple.AppleOauthService;
import com.dnd.dndtravel.auth.apple.dto.AppleUser;
import com.dnd.dndtravel.auth.domain.AuthToken;
import com.dnd.dndtravel.auth.config.JwtProvider;
import com.dnd.dndtravel.auth.repository.AuthTokenRepository;
import com.dnd.dndtravel.auth.service.dto.request.AppleLoginRequest;
import com.dnd.dndtravel.auth.service.dto.response.TokenResponse;
import com.dnd.dndtravel.auth.service.AuthTokenService;
import com.dnd.dndtravel.member.domain.Member;
import com.dnd.dndtravel.member.service.MemberService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
import java.util.Collections;

@RequiredArgsConstructor
@RequestMapping("/api")
@RestController
public class AuthTokenController {

private final AuthTokenService authTokenService;

private final MemberService memberService;

private final AppleOauthService appleOauthService;
private final JwtProvider jwtProvider;
private final AuthTokenRepository authTokenRepository;

@PostMapping("/login/oauth2/apple")
public ResponseEntity<TokenResponse> appleOauthLogin(@RequestBody final AppleLoginRequest appleLoginRequest) {
public TokenResponse appleOauthLogin(@RequestBody final AppleLoginRequest appleLoginRequest) {
AppleUser appleUser = appleOauthService.createAppleUser(appleLoginRequest.getAppleToken());
Member member = memberService.saveMember(appleUser);
AuthToken authToken = authTokenService.issue(member);
return ResponseEntity.ok(new TokenResponse(authToken));

Authentication authentication = new UsernamePasswordAuthenticationToken(member.getId(), null, Collections.emptyList());
String accessToken = jwtProvider.createToken(authentication);
String refreshToken = jwtProvider.createRefreshToken(member.getId());
authTokenRepository.saveRefreshToken(member.getId(), refreshToken); // refreshToken은 DB에 저장

return new TokenResponse(accessToken);
}
}
}

0 comments on commit bf7c372

Please sign in to comment.