Skip to content

Commit

Permalink
Add Github OAuth feature to backend application
Browse files Browse the repository at this point in the history
Signed-off-by: Taewan Kim <[email protected]>
  • Loading branch information
tiokim committed Sep 27, 2023
1 parent 4df6c93 commit 0447c03
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
19 changes: 16 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,33 @@ services:
ports:
- "7896:7896"
environment:
# - frontend.main-page.url=http://localhost:3000
# - cors.allowed-origin=http://localhost:3000
## Required if frontend and backend are different
#- frontend.main-page.url=http://localhost:3000
#- cors.allowed-origin=http://localhost:3000
## Database Configuration
- spring.datasource.url=jdbc:mysql://mysqldb:3306/lpvs
- spring.datasource.username=root
- spring.datasource.password=
## github data
## Github data for fetching code
- github.login=
- github.token=
- github.api.url=https://api.github.com
- github.secret=LPVS
## Google OAuth Login
- spring.security.oauth2.client.registration.google.client-id=GOOGLE_CLIENT_ID
- spring.security.oauth2.client.registration.google.client-secret=GOOGLE_CLIENT_SECRET
- spring.security.oauth2.client.registration.google.redirect-uri=http://localhost:7896/login/oauth2/code/google
- spring.security.oauth2.client.registration.google.scope=profile, email
## Github OAuth Login
- spring.security.oauth2.client.registration.github.client-id=GITHUB_CLIENT_ID
- spring.security.oauth2.client.registration.github.client-secret=GITHUB_CLIENT_SECRET
- spring.security.oauth2.client.registration.github.redirect-uri=http://lpvstest.com:7896/login/oauth2/code/github
- spring.security.oauth2.client.registration.github.scope=user
## Github Enterprise Configuration if necessary
#- spring.security.oauth2.client.provider.github.authorization-uri=https://HOSTNAME/login/oauth/authorize
#- spring.security.oauth2.client.provider.github.token-uri=https://HOSTNAME/login/oauth/access_token
#- spring.security.oauth2.client.provider.github.user-info-uri=https://HOSTNAME/api/v3/user

depends_on:
mysqldb:
condition: service_healthy
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/lpvs/auth/OAuthAttributes.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ public enum OAuthAttributes {
memberProfile.setName((String) kakaoProfile.get("nickname"));
memberProfile.setEmail((String) kakaoAccount.get("email"));
return memberProfile;
}),

GITHUB("github", (attributes) -> {
MemberProfile memberProfile = new MemberProfile();
memberProfile.setName((String) attributes.get("name"));
// TODO: The email from Github can be null, so place the login value for a while.
// Changing unique key from the member table is required.
memberProfile.setEmail((String) attributes.get("login"));
return memberProfile;
});

private final String registrationId;
Expand Down

0 comments on commit 0447c03

Please sign in to comment.