-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-authorization-code.js
More file actions
31 lines (27 loc) · 1.14 KB
/
get-authorization-code.js
File metadata and controls
31 lines (27 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { ResponseUtil } from './util';
import { AppDao, OauthDao, ScopeDao, ProfileDao } from "./dao";
import { AuthCodeRequest, Scopes } from './domain';
import { AuthApiFactory } from "./service";
import { AppIds } from '@hypha-dao/ppp-common';
const appDao = new AppDao();
const oauthDao = new OauthDao();
const scopeDao = new ScopeDao();
const profileDao = new ProfileDao();
const scopes = new Scopes(scopeDao);
export async function main(event, context) {
try {
console.log('event: ', event);
console.log('context: ', context);
const body = JSON.parse(event.body);
const authApi = AuthApiFactory.getInstance(event, body);
const eosAccount = await authApi.getUserName();
const authCodeRequest = new AuthCodeRequest(appDao, oauthDao, scopes);
const profile = await profileDao.getProfile(AppIds.BASE_PROFILE_APP, eosAccount, false);
const oauth = await authCodeRequest.processCodeRequest(body, profile);
console.log('Oauth: ', oauth);
return ResponseUtil.success({ status: true, oauth });
} catch (e) {
console.error(e);
return ResponseUtil.failure(e);
}
}