Skip to content

Commit

Permalink
Merge pull request #14 from GSM-MSG/13-file-structure-and-code-refactor
Browse files Browse the repository at this point in the history
🔀 :: 파일 구조 변경 및 코드 리팩토링
  • Loading branch information
Umjiseung authored Apr 15, 2024
2 parents 467048b + c115243 commit 3bee680
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/main/java/gauth/GAuth.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package gauth;

import gauth.response.GAuthCode;
import gauth.response.GAuthToken;
import gauth.response.GAuthUserInfo;

public interface GAuth {
GAuthToken generateToken(String email, String password, String clientId, String clientSecret, String redirectUri);

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/gauth/enums/TokenType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package gauth.enums;

public enum TokenType {
ACCESS, REFRESH
}
21 changes: 9 additions & 12 deletions src/main/java/gauth/impl/GAuthImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import gauth.GAuth;
import gauth.GAuthCode;
import gauth.GAuthToken;
import gauth.GAuthUserInfo;
import gauth.enums.TokenType;
import gauth.response.GAuthCode;
import gauth.response.GAuthToken;
import gauth.response.GAuthUserInfo;
import gauth.exception.GAuthException;
import gauth.exception.InvalidEncodingException;
import gauth.exception.JsonNotParseException;
Expand All @@ -27,10 +28,6 @@ public class GAuthImpl implements GAuth {
private final String GAuthServerURL = "https://port-0-gauth-backend-85phb42bluutn9a7.sel5.cloudtype.app/oauth";
private final String ResourceServerURL = "https://port-0-gauth-resource-server-71t02clq411q18.sel4.cloudtype.app";

private enum Auth{
ACCESS,
REFRESH
}
public GAuthToken generateToken(String email, String password, String clientId, String clientSecret, String redirectUri) {
String code = generateCode(email, password).getCode();
return new GAuthToken(getToken(code, clientId, clientSecret, redirectUri));
Expand All @@ -51,7 +48,7 @@ public GAuthCode generateCode(String email, String password) {
public GAuthToken refresh(String refreshToken) {
if(!refreshToken.startsWith("Bearer "))
refreshToken = "Bearer "+refreshToken;
return new GAuthToken(sendPatchGAuthServer(null, refreshToken, "/token", Auth.REFRESH));
return new GAuthToken(sendPatchGAuthServer(null, refreshToken, "/token", TokenType.REFRESH));
}

public GAuthUserInfo getUserInfo(String accessToken) {
Expand All @@ -74,8 +71,8 @@ private Map<String, String> sendPostGAuthServer(Map<String, String> body, String
return sendPost(body, token, GAuthServerURL+url);
}

private Map<String, String> sendPatchGAuthServer(Map<String, String> body, String token, String url, Auth auth) {
return sendPatch(body, token, GAuthServerURL+ url, auth);
private Map<String, String> sendPatchGAuthServer(Map<String, String> body, String token, String url, TokenType tokenType) {
return sendPatch(body, token, GAuthServerURL+ url, tokenType);
}

private Map<String, Object> sendGetResourceServer(String token, String url) {
Expand Down Expand Up @@ -107,12 +104,12 @@ private Map<String, Object> sendGet(String token, String url) {
}
}

private Map<String, String> sendPatch(Map<String, String> body, String token, String url, Auth auth) {
private Map<String, String> sendPatch(Map<String, String> body, String token, String url, TokenType tokenType) {
HttpPatch request = new HttpPatch(url);
request.setHeader("Accept", "application/json");
request.setHeader("Connection", "keep-alive");
request.setHeader("Content-Type", "application/json");
if(auth == Auth.ACCESS)
if(tokenType == TokenType.ACCESS)
request.setHeader("Authorization", token);
else
request.addHeader("refreshToken", token);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gauth;
package gauth.response;

public class GAuthCode {
private String code;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gauth;
package gauth.response;

import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gauth;
package gauth.response;

import java.util.Map;

Expand Down

0 comments on commit 3bee680

Please sign in to comment.