forked from codesquad-members-2022/airbnb
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adapter를 통해 각 OAuth 제공 벤더별로 Provider 객체를 생성하고 전달한다 (#35)
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
BE/src/main/java/org/team4/airbnb/auth/config/OauthAdapter.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,20 @@ | ||
package org.team4.airbnb.auth.config; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class OauthAdapter { | ||
|
||
public static Map<String, OauthProvider> getOauthProviders(OauthProperties properties) { | ||
Map<String, OauthProvider> oauthProviders = new HashMap<>(); | ||
|
||
properties.getUsers().forEach( | ||
(vendor, user) -> oauthProviders.put(vendor, OauthProvider.from(user, properties.getProviders() | ||
.get(vendor)))); | ||
return oauthProviders; | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
BE/src/main/java/org/team4/airbnb/auth/config/OauthProvider.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,35 @@ | ||
package org.team4.airbnb.auth.config; | ||
|
||
import lombok.Builder; | ||
import org.team4.airbnb.auth.config.OauthProperties.Provider; | ||
import org.team4.airbnb.auth.config.OauthProperties.User; | ||
|
||
|
||
public class OauthProvider { | ||
|
||
private final String clientId; | ||
private final String clientSecret; | ||
private final String redirectUrl; | ||
private final String tokenUrl; | ||
private final String userInfoUrl; | ||
|
||
public static OauthProvider from(User user, Provider provider) { | ||
return OauthProvider.builder() | ||
.clientId(user.getClientId()) | ||
.clientSecret(user.getClientSecret()) | ||
.redirectUrl(user.getRedirectUri()) | ||
.tokenUrl(provider.getTokenUri()) | ||
.userInfoUrl(provider.getUserInfoUri()) | ||
.build(); | ||
} | ||
|
||
@Builder | ||
private OauthProvider(String clientId, String clientSecret, String redirectUrl, String tokenUrl, | ||
String userInfoUrl) { | ||
this.clientId = clientId; | ||
this.clientSecret = clientSecret; | ||
this.redirectUrl = redirectUrl; | ||
this.tokenUrl = tokenUrl; | ||
this.userInfoUrl = userInfoUrl; | ||
} | ||
} |