-
Notifications
You must be signed in to change notification settings - Fork 0
002. 시크릿 키 기반 EasyCodef 객체 생성
Haebin edited this page Nov 26, 2024
·
6 revisions
Important
시크릿 키 값은 Codef 홈페이지 회원가입 후, MY PAGE > 키 관리에서 확인할 수 있어요.
해당 키 값은 Codef API를 사용하기 위한 인증 정보를 포함해요. 외부에 노출되지 않도록 관리해주세요.
Note
EasyCodef 객체
- path: 실제 Codef API에 요청할 경로.
/v1/kr/***/
형태의 String 값
- organization : 모든 Codef API의 필수 값. 각 상품 개발가이드에 적힌 고정 값 입력
- 이 외 요청부를 개발가이드
입력부(Input)
에 맞게 입력해주세요.
EasyCodef easyCodef = EasyCodefBuilder.builder()
.clientType(CodefClientType.DEMO) // 데모버전시 선택 [중복 선택 불가]
.clientType(CodefClientType.API) // 정식버전시 선택 [중복 선택 불가]
.clientId("your-client-id")
.clientSecret("your-client-secret")
.publicKey("your-public-key")
.build();
Note
EasyCodef 객체는 앞으로 모든 상품 요청을 위해 활용될 객체예요.
EasyCodef 객체는 Singletone 객체로 재사용하도록 설계됐어요.
Codef OAuth 서버와 통신하며 Codef API 엑세스 토큰 발급까지 마무리해요.
Tip
Logging
2024-11-25 09:37:59 EasyCodef RSA public key successfully initialized.
2024-11-25 09:37:59 Your Codef clientType DEMO is successfully initialized.
2024-11-25 09:37:59 Codef OAuth Token : MzIwZjdjMDQtM*********WE0ODQzMTBlMTFmMw==
2024-11-25 09:37:59 Codef OAuth Token successfully initialized.
2024-11-25 09:37:59 [1112940474] Codef API Request
2024-11-25 09:37:59 > Request Host : https://oauth.codef.io
2024-11-25 09:37:59 > Requset Uri : /oauth/token?grant_type=client_credentials&scope=read
2024-11-25 09:38:00 [1112940474] Codef API Response
2024-11-25 09:38:00 > Response Status : 200
2024-11-25 09:38:00 > Response → "eyJhbGciO****************_5obQ"
2024-11-25 09:38:00 Codef API AccessToken : "eyJhbGciO****************_5obQ"
2024-11-25 09:38:00 Codef API AccessToken expiry at 2024-12-02T09:38:00.212198.
Also, EasyCodef will handle automatic renewal.
2024-11-25 09:38:00 Codef API AccessToken successfully initialized.
2024-11-25 09:38:00 ==================================================
------. ,-----. ,--. ,---.
| .---' ,--,--. ,---.,--. ,--.' .--./ ,---. ,-| |,---. / .-'
| `--, ' ,-. |( .-' \ ' / | | | .-. |' .-. | .-. :| `-,
| `---.\ '-' |.-' `) \ ' ' '--'\' '-' '\ `-' \ --.| .-'
`------' `--`--'`----'.-' / `-----' `---' `---' `----'`--'
EasyCodef v2.0.0-beta-004 Successfully Initialized! Hello worlds!
Important
객체 내부에 추가인증을 위한 요청/응답/요청 URL
을 컬렉션 형태로 저장하기 때문에
반드시 싱글톤 객체로 선언하여 모든 메소드에서 재사용하도록 설계해야해요.
Warning
EasyCodef 생성자는 아래의 예외 사항들을 같이 검증하고, 검증에 실패하면 예외를 반환해요.
- clientId가 null이거나 유효한 UUID 포맷을 따르지 않을 경우
- clientSecret이 null이거나 유효한 UUID 포맷을 따르지 않을 경우
- publicKey가 null이거나 Base64로 디코딩할 수 없는 포맷일 경우
- codef OAuth API와 통신에 실패하는 경우 (https://oauth.codef.io)
- 유효하지 않은 입력 값 인자로 OAuth API가 401(UNAUTHORIZED) 응답을 반환할 경우
@Configuration
public class EasyCodefConfig {
@Value("${codef.client-id}")
private String codefClientId;
@Value("${codef.client-secret}")
private String codefClientSecret;
@Value("${codef.public-key}")
private String codefPublicKey;
@Bean
public EasyCodef easyCodef = EasyCodefBuilder.builder()
.clientType(CodefClientType.DEMO) // 데모버전일 때 선택
.clientType(CodefClientType.API) // 정식버전일 때 선택
.clientId(codefClientId)
.clientSecret(codefClientSecret)
.publicKey(codefPublicKey)
.build();
}
}
@Service
@RequiredArgsConstructor
public class EasyCodefProductService {
private final EasyCodef easycodef;
public EasyCodefResponse getCodefApiResponse(EasyCodefRequest request) {
return easyCodef.requestProduct(request);
}
}
MIT © Hectodata Co., Ltd | LICENSE