Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Github OAuth feature to backend application #222

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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://localhost: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
Loading