Skip to content

Commit

Permalink
#32 refactor: application-secret.yml 에서 중요 데이터 보관, 사용"
Browse files Browse the repository at this point in the history
  • Loading branch information
ahah525 committed Mar 15, 2023
1 parent 87e2321 commit eb649f8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
2 changes: 2 additions & 0 deletions playwithme/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ out/

### VS Code ###
.vscode/

/**/application-secret.yml
18 changes: 16 additions & 2 deletions playwithme/src/main/java/com/idea5/playwithme/KakaoAddress.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
package com.idea5.playwithme;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component("KakaoAddress")
public class KakaoAddress {
private static String now;

private String host = "https://kauth.kakao.com";
private String loginRequestUri = "/oauth/authorize";
private String logoutRequestUri = "/oauth/logout";

@Value("${oauth2.kakao.rest-api-key}")
private String restApiKey;

@Value("${oauth2.kakao.login.redirect-uri}")
private String loginRedirectUri;

@Value("${oauth2.kakao.logout.redirect-uri}")
private String logoutRedirectUri;

public String kakaoLogin(String now){
this.now = now;
return "https://kauth.kakao.com/oauth/authorize?client_id=0c7de4f37c334c2d42105c51f0b9ab12&redirect_uri=http://localhost:8080/member/login/oauth/kakao/callback&response_type=code";
return "%s%s?client_id=%s&redirect_uri=%s&response_type=code".formatted(host, loginRequestUri, restApiKey, loginRedirectUri);
}
public String kakaoLogout(String now){
this.now = now;
return "https://kauth.kakao.com/oauth/logout?client_id=0c7de4f37c334c2d42105c51f0b9ab12&logout_redirect_uri=http://localhost:8080/member/logout/oauth/kakao";
return "%s%s?client_id=%s&logout_redirect_uri=%s".formatted(host, logoutRequestUri, restApiKey, logoutRedirectUri);
}

public static String getNow() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
import com.idea5.playwithme.member.domain.Member;
import com.idea5.playwithme.member.domain.MemberRole;
import com.idea5.playwithme.member.dto.KakaoUser;
import com.idea5.playwithme.member.repository.MemberRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
Expand All @@ -19,9 +18,7 @@
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
Expand All @@ -33,9 +30,14 @@
@Service
public class KakaoService {

@Value("${oauth2.kakao.rest-api-key}")
private String restApiKey;

@Value("${oauth2.kakao.login.redirect-uri}")
private String redirectUri;

public String getAccessToken(String code) throws JsonProcessingException {
String host = "https://kauth.kakao.com/oauth/token";
String redirectUrl = "http://localhost:8080/member/login/oauth/kakao/callback";

// HttpHeader 오브젝트 생성
HttpHeaders headers = new HttpHeaders();
Expand All @@ -44,8 +46,8 @@ public String getAccessToken(String code) throws JsonProcessingException {
// HttpBody 오브젝트 생성
MultiValueMap<String, String> body = new LinkedMultiValueMap<>();
body.add("grant_type", "authorization_code");
body.add("client_id", "0c7de4f37c334c2d42105c51f0b9ab12");
body.add("redirect_uri", redirectUrl);
body.add("client_id", restApiKey);
body.add("redirect_uri", redirectUri);
body.add("code", code);

// HttpHeader, HttpBody 하나의 오브젝트에 담기
Expand Down
6 changes: 5 additions & 1 deletion playwithme/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#Database
spring:
profiles:
include:
- secret # 중요 정보가 담긴 yml

datasource:
url: jdbc:mariadb://localhost:3306/playwithme?useUnicode=true&characterEncoding=utf8&serverTimeZone=Asia/Seoul&allowPublicKeyRetrieval=true&useSSL=false
username: root
password:
password: '0114'

driver-class-name: org.mariadb.jdbc.Driver

Expand Down

0 comments on commit eb649f8

Please sign in to comment.