Core JS library for Lemoncloud; written by Typescript
$ npm install @lemoncloud/lemon-front-lib
// or
$ yarn add @lemoncloud/lemon-front-lib
import { AuthService } from '@lemoncloud/lemon-front-lib';
const oAuthEndpoint = 'http://localhost:8086'; // refresh 때 필요
const project = 'LEMON';
const authService = new AuthService({ project, oAuthEndpoint });
oauth api
를 통해 발급 받은 token으로 AWS Credentials 생성
const ENDPOINT = 'https://..../oauth/kakao/token'; // lemoncloud oauth-api
const body = { code }; // get from kakao, naver, google...
const credentials = authService.requestWithSign('POST', ENDPOINT, '/', {}, body)
.then(data => authService.buildCredentialsByToken(data));
AWS Credentials 데이터 유무로 로그인 체크
AuthService.isAuthenticated();
AWS Credentials 리턴. 로그인하지 않았을 경우 null
리턴
AuthService.getCredentials();
axios
를 이용한 HTTP 요청. AWS Credentials이 있을 경우, Signature V4 Signing 과정을 거쳐 요청
AuthService.request('GET', 'YOUR_URL', '/');
AuthService.request('GET', 'YOUR_URL', '/', { page: 0 });
AuthService.request('POST', 'YOUR_URL', '/', {}, { mock: 'MOCK_VALUE' });
내부에서 getCredentials()
을 호출 후 request()
진행
AuthService.requestWithCredentials('GET', 'YOUR_URL', '/');
AuthService.requestWithCredentials('GET', 'YOUR_URL', '/', { page: 0 });
AuthService.requestWithCredentials('POST', 'YOUR_URL', '/', {}, { mock: 'MOCK_VALUE' });
AWS Credentials 데이터 삭제
AuthService.logout();
$ node example/example.js
# open localhost:8888 on browser