Skip to content

Commit

Permalink
feat: Adapter를 통해 각 OAuth 제공 벤더별로 Provider 객체를 생성하고 전달한다 (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
mybloom committed Jun 7, 2022
1 parent d315903 commit 09eb50d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
20 changes: 20 additions & 0 deletions BE/src/main/java/org/team4/airbnb/auth/config/OauthAdapter.java
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 BE/src/main/java/org/team4/airbnb/auth/config/OauthProvider.java
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;
}
}

0 comments on commit 09eb50d

Please sign in to comment.