This repository has been archived by the owner on Oct 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
168 lines (120 loc) · 5.93 KB
/
index.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**
* Handler that will be called during the execution of a PostLogin flow.
*
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
*/
exports.onExecutePostLogin = async (event, api) => {
// if (!event.user.email_verified) {
// api.access.deny(`Please verify your email before logging in.`);
// }
if (event.authorization) {
let transaction_input = event.request.query.transaction_input
transaction_input = JSON.parse(transaction_input)
if (transaction_input.othentFunction === 'sendTransaction') {
const contract_input = {
function: transaction_input.warpData.function,
data: transaction_input.warpData.data,
}
api.idToken.setCustomClaim(`contract_input`, contract_input)
api.idToken.setCustomClaim(`contract_id`, event.user.user_metadata.contract_id)
api.idToken.setCustomClaim(`email`, '')
api.idToken.setCustomClaim(`email_verified`, '')
api.idToken.setCustomClaim(`family_name`, '')
api.idToken.setCustomClaim(`given_name`, '')
api.idToken.setCustomClaim(`locale`, '')
api.idToken.setCustomClaim(`name`, 'Othent User')
api.idToken.setCustomClaim(`nickname`, '')
api.idToken.setCustomClaim(`picture`, 'https://othent.io/user.png')
if (transaction_input.testNet && event.user.user_metadata.test_net_contract_id) {
api.idToken.setCustomClaim(`test_net_contract_id`, event.user.user_metadata.test_net_contract_id)
} else if (transaction_input.testNet && !event.user.user_metadata.test_net_contract_id) {
throw new Error('Please log in through your testNet account.')
}
}
if (transaction_input.othentFunction === 'idToken') {
if (event.user.user_metadata.contract_id) {
api.idToken.setCustomClaim(`contract_id`, event.user.user_metadata.contract_id)
}
else {
const contract_input = {
function: 'initializeContract',
data: null
}
api.idToken.setCustomClaim(`contract_input`, contract_input)
api.idToken.setCustomClaim(`email`, '')
api.idToken.setCustomClaim(`email_verified`, '')
api.idToken.setCustomClaim(`family_name`, '')
api.idToken.setCustomClaim(`given_name`, '')
api.idToken.setCustomClaim(`locale`, '')
api.idToken.setCustomClaim(`name`, 'Othent User')
api.idToken.setCustomClaim(`nickname`, '')
api.idToken.setCustomClaim(`picture`, 'https://othent.io/user.png')
}
if (event.user.user_metadata.test_net_contract_id) {
api.idToken.setCustomClaim(`test_net_contract_id`, event.user.user_metadata.test_net_contract_id)
} else if (transaction_input.testNet && !event.user.user_metadata.test_net_contract_id) {
const contract_input = {
function: 'initializeContract',
data: null
}
api.idToken.setCustomClaim(`contract_input`, contract_input)
}
}
if (transaction_input.othentFunction === 'uploadData') {
const file_hash = transaction_input.file_hash
api.idToken.setCustomClaim(`file_hash`, file_hash)
api.idToken.setCustomClaim(`contract_id`, event.user.user_metadata.contract_id)
api.idToken.setCustomClaim(`email`, '')
api.idToken.setCustomClaim(`email_verified`, '')
api.idToken.setCustomClaim(`family_name`, '')
api.idToken.setCustomClaim(`given_name`, '')
api.idToken.setCustomClaim(`locale`, '')
api.idToken.setCustomClaim(`name`, 'Othent User')
api.idToken.setCustomClaim(`nickname`, '')
api.idToken.setCustomClaim(`picture`, 'https://othent.io/user.png')
}
if (transaction_input.othentFunction === 'initializeJWK') {
const contract_input = {
function: transaction_input.warpData.function,
data: transaction_input.warpData.data,
}
api.idToken.setCustomClaim(`contract_input`, contract_input)
api.idToken.setCustomClaim(`contract_id`, event.user.user_metadata.contract_id)
api.idToken.setCustomClaim(`email`, '')
api.idToken.setCustomClaim(`email_verified`, '')
api.idToken.setCustomClaim(`family_name`, '')
api.idToken.setCustomClaim(`given_name`, '')
api.idToken.setCustomClaim(`locale`, '')
api.idToken.setCustomClaim(`name`, 'Othent User')
api.idToken.setCustomClaim(`nickname`, '')
api.idToken.setCustomClaim(`picture`, 'https://othent.io/user.png')
}
if (transaction_input.othentFunction === 'API_ID') {
api.idToken.setCustomClaim(`API_ID`, event.user.user_metadata.API_ID)
api.idToken.setCustomClaim(`contract_id`, event.user.user_metadata.contract_id)
}
if (transaction_input.othentFunction === 'deployWarpContractFromTx') {
const srcTxId = transaction_input.srcTxId
api.idToken.setCustomClaim(`srcTxId`, srcTxId)
api.idToken.setCustomClaim(`contract_id`, event.user.user_metadata.contract_id)
api.idToken.setCustomClaim(`email`, '')
api.idToken.setCustomClaim(`email_verified`, '')
api.idToken.setCustomClaim(`family_name`, '')
api.idToken.setCustomClaim(`given_name`, '')
api.idToken.setCustomClaim(`locale`, '')
api.idToken.setCustomClaim(`name`, 'Othent User')
api.idToken.setCustomClaim(`nickname`, '')
api.idToken.setCustomClaim(`picture`, 'https://othent.io/user.png')
}
}
};
/**
* Handler that will be invoked when this action is resuming after an external redirect. If your
* onExecutePostLogin function does not perform a redirect, this function can be safely ignored.
*
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
*/
// exports.onContinuePostLogin = async (event, api) => {
// };