-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop-backend' into fix/#585
- Loading branch information
Showing
75 changed files
with
2,132 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ on: | |
|
||
jobs: | ||
deploy: | ||
runs-on: [self-hosted, dev] | ||
runs-on: [self-hosted, develop] | ||
|
||
steps: | ||
- name: deploy | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
/frontend/.idea | ||
/backend/htmlReport | ||
*.pem | ||
backend/src/main/resources/auth/AuthKey.p8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,3 @@ build/ | |
out | ||
logs | ||
src/main/resources/firebase | ||
src/main/resources/application-prod.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
backend/src/main/java/mouda/backend/auth/Infrastructure/GoogleOauthClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package mouda.backend.auth.Infrastructure; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.LinkedMultiValueMap; | ||
import org.springframework.util.MultiValueMap; | ||
import org.springframework.web.client.RestClient; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Component | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class GoogleOauthClient implements OauthClient { | ||
|
||
private static final String CLIENT_ID = "630308965506-4eiek02jh2a5fbj7as1o84l4mks3s2tu.apps.googleusercontent.com"; | ||
private static final String GRANT_TYPE = "authorization_code"; | ||
private static final String GOOGLE_API_URL = "https://oauth2.googleapis.com/token"; | ||
|
||
@Value("${oauth.google.client-secret}") | ||
private String clientSecret; | ||
|
||
@Value("${oauth.google.redirect-uri}") | ||
private String redirectUri; | ||
|
||
private final RestClient restClient; | ||
|
||
@Override | ||
public String getIdToken(String code) { | ||
try { | ||
HttpHeaders headers = getHttpHeaders(); | ||
MultiValueMap<String, String> formData = getFormData(code); | ||
|
||
JsonNode oauthResponse = restClient.method(HttpMethod.POST) | ||
.uri(GOOGLE_API_URL) | ||
.headers(httpHeaders -> httpHeaders.addAll(headers)) | ||
.body(formData) | ||
.retrieve() | ||
.body(JsonNode.class); | ||
return oauthResponse.get("id_token").asText(); | ||
} catch (Exception e) { | ||
log.warn(e.getMessage()); | ||
// throw new AuthException(HttpStatus.BAD_GATEWAY, TOKEN_ISSUE_FAILED); | ||
throw e; | ||
} | ||
} | ||
|
||
private HttpHeaders getHttpHeaders() { | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); | ||
return headers; | ||
} | ||
|
||
private MultiValueMap<String, String> getFormData(String code) { | ||
String scope = "https://www.googleapis.com/auth/userinfo.email " + | ||
"https://www.googleapis.com/auth/userinfo.profile " + | ||
"openid"; | ||
|
||
MultiValueMap<String, String> formData = new LinkedMultiValueMap<>(); | ||
formData.add("client_id", CLIENT_ID); | ||
formData.add("client_secret", clientSecret); | ||
formData.add("code", code); | ||
formData.add("grant_type", GRANT_TYPE); | ||
formData.add("redirect_uri", redirectUri); | ||
formData.add("scope", scope); | ||
return formData; | ||
} | ||
} |
4 changes: 0 additions & 4 deletions
4
backend/src/main/java/mouda/backend/auth/Infrastructure/response/TokenResponse.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
backend/src/main/java/mouda/backend/auth/business/GoogleAuthService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package mouda.backend.auth.business; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import mouda.backend.auth.implement.GoogleOauthManager; | ||
import mouda.backend.auth.implement.LoginManager; | ||
import mouda.backend.auth.presentation.request.GoogleOauthReqeust; | ||
import mouda.backend.auth.presentation.response.LoginResponse; | ||
import mouda.backend.member.domain.Member; | ||
import mouda.backend.member.domain.OauthType; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class GoogleAuthService { | ||
|
||
private final GoogleOauthManager googleOauthManager; | ||
private final LoginManager loginManager; | ||
|
||
public LoginResponse oauthLogin(GoogleOauthReqeust googleOauthReqeust) { | ||
String memberName = googleOauthManager.getMemberName(googleOauthReqeust.idToken()); | ||
String socialLoginId = googleOauthManager.getSocialLoginId(googleOauthReqeust.idToken()); | ||
String accessToken = loginManager.processSocialLogin(OauthType.GOOGLE, socialLoginId); | ||
return new LoginResponse(accessToken); | ||
} | ||
|
||
public Member findMember(String token) { | ||
return null; | ||
} | ||
|
||
public void checkAuthentication(String token) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.