Skip to content

Commit f1224be

Browse files
committed
chore: combine signer allow api with oauthInitiated track
1 parent f10014c commit f1224be

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

src/helpers/citadelUtils.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import { get, put } from "@toruslabs/http-helpers";
44
import { RetrieveSharesParams } from "../interfaces";
55
import { isNullOrUndefined } from "./common";
66

7+
export enum CitadelAllowParamsSetOrUnsetFlag {
8+
SET = 1,
9+
UNSET = 0,
10+
}
11+
712
export interface CitadelAuthFlowAuditParams {
813
oauthInitiated?: boolean;
914
oauthVerified?: boolean;
@@ -12,14 +17,20 @@ export interface CitadelAuthFlowAuditParams {
1217
oauthFailed?: boolean;
1318
}
1419

15-
export interface CitadelAllowParams extends CitadelAuthFlowAuditParams {
20+
export interface CitadelAllowParams {
1621
buildEnv: BUILD_ENV_TYPE;
1722
verifier: string;
1823
verifierId: string;
1924
network: string;
2025
clientId: string;
2126
recordId: string;
2227
source?: string;
28+
// flags for auditing the auth flow
29+
oauthInitiated?: CitadelAllowParamsSetOrUnsetFlag;
30+
oauthVerified?: CitadelAllowParamsSetOrUnsetFlag;
31+
oauthCompleted?: CitadelAllowParamsSetOrUnsetFlag;
32+
oauthVerificationFailed?: CitadelAllowParamsSetOrUnsetFlag;
33+
oauthFailed?: CitadelAllowParamsSetOrUnsetFlag;
2334
}
2435

2536
export interface CitadelAuditParams extends CitadelAuthFlowAuditParams {

src/helpers/nodeUtils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
import log from "../loglevel";
2828
import { Some } from "../some";
2929
import { TorusUtilsExtraParams } from "../TorusUtilsExtraParams";
30-
import { callAllowApi } from "./citadelUtils";
30+
import { callAllowApi, CitadelAllowParamsSetOrUnsetFlag } from "./citadelUtils";
3131
import {
3232
base64ToBytes,
3333
bigintToHex,
@@ -399,6 +399,8 @@ export async function retrieveOrImportShare(params: {
399399
clientId,
400400
source,
401401
recordId,
402+
oauthInitiated: CitadelAllowParamsSetOrUnsetFlag.SET,
403+
oauthCompleted: CitadelAllowParamsSetOrUnsetFlag.SET,
402404
});
403405

404406
// generate temporary private and public key that is used to secure receive shares

src/torus.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
callAllowApi,
1010
callAuditApi,
1111
CitadelAllowParams,
12+
CitadelAllowParamsSetOrUnsetFlag,
1213
CitadelAuthFlowAuditParams,
1314
Curve,
1415
encodeEd25519Point,
@@ -165,15 +166,13 @@ class Torus {
165166
recordId,
166167
};
167168

168-
let result: TorusKey;
169+
// for auditing the auth flow
170+
const auditParams: CitadelAuthFlowAuditParams = {
171+
// at this point, user has completed the oauth login
172+
oauthCompleted: true,
173+
};
169174

170-
if (!params.recordId) {
171-
// report oauth completed, we won't await this call as it's only for analytics tracking
172-
// if recordId isn't provided in the params, we will also report oauth initiated
173-
this.reportSignerAllow({ ...allowParams, oauthCompleted: true, oauthInitiated: true });
174-
} else {
175-
this.reportUserAuthFlowAudit({ ...params, recordId }, { oauthCompleted: true });
176-
}
175+
let result: TorusKey;
177176

178177
try {
179178
result = await retrieveOrImportShare({
@@ -202,18 +201,20 @@ class Torus {
202201
} catch (error) {
203202
if (params.recordId) {
204203
// report oauth verification failed, we won't await this call as it's only for analytics tracking
205-
this.reportUserAuthFlowAudit({ ...params, recordId }, { oauthVerificationFailed: true });
204+
auditParams.oauthVerificationFailed = true;
205+
this.reportUserAuthFlowAudit({ ...params, recordId }, auditParams);
206206
} else {
207-
this.reportSignerAllow({ ...allowParams, oauthVerificationFailed: true });
207+
this.reportSignerAllow({ ...allowParams, oauthVerificationFailed: CitadelAllowParamsSetOrUnsetFlag.SET });
208208
}
209209
throw error;
210210
}
211211

212212
if (!params.recordId) {
213-
this.reportSignerAllow({ ...allowParams, oauthVerified: true });
213+
this.reportSignerAllow({ ...allowParams, oauthVerified: CitadelAllowParamsSetOrUnsetFlag.SET });
214214
} else {
215215
// report oauth verified, we won't await this call as it's only for analytics tracking
216-
this.reportUserAuthFlowAudit({ ...params, recordId }, { oauthVerified: true });
216+
auditParams.oauthVerified = true;
217+
this.reportUserAuthFlowAudit({ ...params, recordId }, auditParams);
217218
}
218219
return result;
219220
}

0 commit comments

Comments
 (0)