@devtion/backend 0.0.0-bfc9ee4 → 0.0.0-eb3bb7d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -0
- package/dist/src/functions/index.js +18 -6
- package/dist/src/functions/index.mjs +18 -6
- package/dist/types/functions/user.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/functions/user.ts +22 -7
package/README.md
CHANGED
|
@@ -100,6 +100,32 @@ yarn firebase:init
|
|
|
100
100
|
|
|
101
101
|
### Deployment
|
|
102
102
|
|
|
103
|
+
#### AWS Infrastructure
|
|
104
|
+
|
|
105
|
+
0. Login or create a [new AWS Account](https://portal.aws.amazon.com/billing/signup?nc2=h_ct&src=header_signup&redirect_url=https%3A%2F%2Faws.amazon.com%2Fregistration-confirmation#/start/email).
|
|
106
|
+
- The AWS free tier account will cover a good number of requests for ceremonies but there could be some costs based on your ceremony circuits size.
|
|
107
|
+
1. Create an access key for a user with Admin privileges (__NOT ROOT USER__)
|
|
108
|
+
2. Setup the `awscli` ([docs](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)) and add the keys for this user.
|
|
109
|
+
3. Install `terraform` ([docs](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli))
|
|
110
|
+
4. Decide on an AWS region (by default this is **us-east-1**) - if you want to change you will need to do the following:
|
|
111
|
+
1. update **aws/lambda/index.mjs** ([exact line](https://github.com/privacy-scaling-explorations/p0tion/blob/dev/packages/backend/aws/lambda/index.mjs#L3)) to the new region
|
|
112
|
+
2. update **main.tf** ([exact line](https://github.com/privacy-scaling-explorations/p0tion/blob/dev/packages/backend/aws/main.tf#L2)) to the new region
|
|
113
|
+
5. zip the Lambda folder:
|
|
114
|
+
1. `cd lambda`
|
|
115
|
+
2. `zip -r ../lambda.zip .`
|
|
116
|
+
6. Run terraform:
|
|
117
|
+
1. `terraform init`
|
|
118
|
+
2. `terraform plan`
|
|
119
|
+
3. `terraform apply`
|
|
120
|
+
4. `terraform output secret_key`
|
|
121
|
+
- To print the secret access key for the IAM user
|
|
122
|
+
6. Store the other values (sns_topic_arn etc.)
|
|
123
|
+
- These will be needed for the .env file configuration
|
|
124
|
+
|
|
125
|
+
The IAM user created with the steps above can be used for all p0tion's features.
|
|
126
|
+
|
|
127
|
+
#### Firebase
|
|
128
|
+
|
|
103
129
|
Deploy the current configuration to the `prod` project running
|
|
104
130
|
|
|
105
131
|
```bash
|
|
@@ -544,8 +544,10 @@ const registerAuthUser = functions__namespace
|
|
|
544
544
|
const { uid } = user;
|
|
545
545
|
// Reference to a document using uid.
|
|
546
546
|
const userRef = firestore.collection(actions.commonTerms.collections.users.name).doc(uid);
|
|
547
|
-
// html encode the display name
|
|
548
|
-
const encodedDisplayName = htmlEntities.encode(displayName);
|
|
547
|
+
// html encode the display name (or put the ID if the name is not displayed)
|
|
548
|
+
const encodedDisplayName = user.displayName === "Null" || user.displayName === null ? user.uid : htmlEntities.encode(displayName);
|
|
549
|
+
// store the avatar URL of a contributor
|
|
550
|
+
let avatarUrl = "";
|
|
549
551
|
// we only do reputation check if the user is not a coordinator
|
|
550
552
|
if (!(email?.endsWith(`@${process.env.CUSTOM_CLAIMS_COORDINATOR_EMAIL_ADDRESS_OR_DOMAIN}`) ||
|
|
551
553
|
email === process.env.CUSTOM_CLAIMS_COORDINATOR_EMAIL_ADDRESS_OR_DOMAIN)) {
|
|
@@ -555,14 +557,16 @@ const registerAuthUser = functions__namespace
|
|
|
555
557
|
const vars = getGitHubVariables();
|
|
556
558
|
// this return true or false
|
|
557
559
|
try {
|
|
558
|
-
const
|
|
559
|
-
if (!
|
|
560
|
+
const { reputable, avatarUrl: avatarURL } = await actions.githubReputation(user.providerData[0].uid, vars.minimumFollowing, vars.minimumFollowers, vars.minimumPublicRepos);
|
|
561
|
+
if (!reputable) {
|
|
560
562
|
// Delete user
|
|
561
563
|
await auth.deleteUser(user.uid);
|
|
562
564
|
// Throw error
|
|
563
|
-
logAndThrowError(makeError("permission-denied", "The user is not allowed to sign up because their Github reputation is not high enough.", `The user ${user.displayName} is not allowed to sign up because their Github reputation is not high enough. Please contact the administrator if you think this is a mistake.`));
|
|
565
|
+
logAndThrowError(makeError("permission-denied", "The user is not allowed to sign up because their Github reputation is not high enough.", `The user ${user.displayName === "Null" || user.displayName === null ? user.uid : user.displayName} is not allowed to sign up because their Github reputation is not high enough. Please contact the administrator if you think this is a mistake.`));
|
|
564
566
|
}
|
|
565
|
-
|
|
567
|
+
// store locally
|
|
568
|
+
avatarUrl = avatarURL;
|
|
569
|
+
printLog(`Github reputation check passed for user ${user.displayName === "Null" || user.displayName === null ? user.uid : user.displayName}`, LogLevel.DEBUG);
|
|
566
570
|
}
|
|
567
571
|
catch (error) {
|
|
568
572
|
// Delete user
|
|
@@ -572,6 +576,8 @@ const registerAuthUser = functions__namespace
|
|
|
572
576
|
}
|
|
573
577
|
}
|
|
574
578
|
// Set document (nb. we refer to providerData[0] because we use Github OAuth provider only).
|
|
579
|
+
// In future releases we might want to loop through the providerData array as we support
|
|
580
|
+
// more providers.
|
|
575
581
|
await userRef.set({
|
|
576
582
|
name: encodedDisplayName,
|
|
577
583
|
encodedDisplayName,
|
|
@@ -584,7 +590,13 @@ const registerAuthUser = functions__namespace
|
|
|
584
590
|
photoURL: photoURL || "",
|
|
585
591
|
lastUpdated: getCurrentServerTimestampInMillis()
|
|
586
592
|
});
|
|
593
|
+
// we want to create a new collection for the users to store the avatars
|
|
594
|
+
const avatarRef = firestore.collection(actions.commonTerms.collections.avatars.name).doc(uid);
|
|
595
|
+
await avatarRef.set({
|
|
596
|
+
avatarUrl: avatarUrl || "",
|
|
597
|
+
});
|
|
587
598
|
printLog(`Authenticated user document with identifier ${uid} has been correctly stored`, LogLevel.DEBUG);
|
|
599
|
+
printLog(`Authenticated user avatar with identifier ${uid} has been correctly stored`, LogLevel.DEBUG);
|
|
588
600
|
});
|
|
589
601
|
/**
|
|
590
602
|
* Set custom claims for role-based access control on the newly created user.
|
|
@@ -521,8 +521,10 @@ const registerAuthUser = functions
|
|
|
521
521
|
const { uid } = user;
|
|
522
522
|
// Reference to a document using uid.
|
|
523
523
|
const userRef = firestore.collection(commonTerms.collections.users.name).doc(uid);
|
|
524
|
-
// html encode the display name
|
|
525
|
-
const encodedDisplayName = encode(displayName);
|
|
524
|
+
// html encode the display name (or put the ID if the name is not displayed)
|
|
525
|
+
const encodedDisplayName = user.displayName === "Null" || user.displayName === null ? user.uid : encode(displayName);
|
|
526
|
+
// store the avatar URL of a contributor
|
|
527
|
+
let avatarUrl = "";
|
|
526
528
|
// we only do reputation check if the user is not a coordinator
|
|
527
529
|
if (!(email?.endsWith(`@${process.env.CUSTOM_CLAIMS_COORDINATOR_EMAIL_ADDRESS_OR_DOMAIN}`) ||
|
|
528
530
|
email === process.env.CUSTOM_CLAIMS_COORDINATOR_EMAIL_ADDRESS_OR_DOMAIN)) {
|
|
@@ -532,14 +534,16 @@ const registerAuthUser = functions
|
|
|
532
534
|
const vars = getGitHubVariables();
|
|
533
535
|
// this return true or false
|
|
534
536
|
try {
|
|
535
|
-
const
|
|
536
|
-
if (!
|
|
537
|
+
const { reputable, avatarUrl: avatarURL } = await githubReputation(user.providerData[0].uid, vars.minimumFollowing, vars.minimumFollowers, vars.minimumPublicRepos);
|
|
538
|
+
if (!reputable) {
|
|
537
539
|
// Delete user
|
|
538
540
|
await auth.deleteUser(user.uid);
|
|
539
541
|
// Throw error
|
|
540
|
-
logAndThrowError(makeError("permission-denied", "The user is not allowed to sign up because their Github reputation is not high enough.", `The user ${user.displayName} is not allowed to sign up because their Github reputation is not high enough. Please contact the administrator if you think this is a mistake.`));
|
|
542
|
+
logAndThrowError(makeError("permission-denied", "The user is not allowed to sign up because their Github reputation is not high enough.", `The user ${user.displayName === "Null" || user.displayName === null ? user.uid : user.displayName} is not allowed to sign up because their Github reputation is not high enough. Please contact the administrator if you think this is a mistake.`));
|
|
541
543
|
}
|
|
542
|
-
|
|
544
|
+
// store locally
|
|
545
|
+
avatarUrl = avatarURL;
|
|
546
|
+
printLog(`Github reputation check passed for user ${user.displayName === "Null" || user.displayName === null ? user.uid : user.displayName}`, LogLevel.DEBUG);
|
|
543
547
|
}
|
|
544
548
|
catch (error) {
|
|
545
549
|
// Delete user
|
|
@@ -549,6 +553,8 @@ const registerAuthUser = functions
|
|
|
549
553
|
}
|
|
550
554
|
}
|
|
551
555
|
// Set document (nb. we refer to providerData[0] because we use Github OAuth provider only).
|
|
556
|
+
// In future releases we might want to loop through the providerData array as we support
|
|
557
|
+
// more providers.
|
|
552
558
|
await userRef.set({
|
|
553
559
|
name: encodedDisplayName,
|
|
554
560
|
encodedDisplayName,
|
|
@@ -561,7 +567,13 @@ const registerAuthUser = functions
|
|
|
561
567
|
photoURL: photoURL || "",
|
|
562
568
|
lastUpdated: getCurrentServerTimestampInMillis()
|
|
563
569
|
});
|
|
570
|
+
// we want to create a new collection for the users to store the avatars
|
|
571
|
+
const avatarRef = firestore.collection(commonTerms.collections.avatars.name).doc(uid);
|
|
572
|
+
await avatarRef.set({
|
|
573
|
+
avatarUrl: avatarUrl || "",
|
|
574
|
+
});
|
|
564
575
|
printLog(`Authenticated user document with identifier ${uid} has been correctly stored`, LogLevel.DEBUG);
|
|
576
|
+
printLog(`Authenticated user avatar with identifier ${uid} has been correctly stored`, LogLevel.DEBUG);
|
|
565
577
|
});
|
|
566
578
|
/**
|
|
567
579
|
* Set custom claims for role-based access control on the newly created user.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../../src/functions/user.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,oBAAoB,CAAA;AAW/C;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../../src/functions/user.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,oBAAoB,CAAA;AAW/C;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,mEAsGvB,CAAA;AACN;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,mEA+BpC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devtion/backend",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-eb3bb7d",
|
|
4
4
|
"description": "MPC Phase 2 backend for Firebase services management",
|
|
5
5
|
"repository": "git@github.com:privacy-scaling-explorations/p0tion.git",
|
|
6
6
|
"homepage": "https://github.com/privacy-scaling-explorations/p0tion",
|
|
@@ -85,5 +85,5 @@
|
|
|
85
85
|
"publishConfig": {
|
|
86
86
|
"access": "public"
|
|
87
87
|
},
|
|
88
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "d21d2002b8d020289595aaea83be0202d28486cb"
|
|
89
89
|
}
|
package/src/functions/user.ts
CHANGED
|
@@ -40,8 +40,11 @@ export const registerAuthUser = functions
|
|
|
40
40
|
const { uid } = user
|
|
41
41
|
// Reference to a document using uid.
|
|
42
42
|
const userRef = firestore.collection(commonTerms.collections.users.name).doc(uid)
|
|
43
|
-
// html encode the display name
|
|
44
|
-
const encodedDisplayName = encode(displayName)
|
|
43
|
+
// html encode the display name (or put the ID if the name is not displayed)
|
|
44
|
+
const encodedDisplayName = user.displayName === "Null" || user.displayName === null ? user.uid : encode(displayName)
|
|
45
|
+
|
|
46
|
+
// store the avatar URL of a contributor
|
|
47
|
+
let avatarUrl: string = ""
|
|
45
48
|
// we only do reputation check if the user is not a coordinator
|
|
46
49
|
if (
|
|
47
50
|
!(
|
|
@@ -56,13 +59,13 @@ export const registerAuthUser = functions
|
|
|
56
59
|
|
|
57
60
|
// this return true or false
|
|
58
61
|
try {
|
|
59
|
-
const
|
|
62
|
+
const { reputable, avatarUrl: avatarURL } = await githubReputation(
|
|
60
63
|
user.providerData[0].uid,
|
|
61
64
|
vars.minimumFollowing,
|
|
62
65
|
vars.minimumFollowers,
|
|
63
66
|
vars.minimumPublicRepos
|
|
64
67
|
)
|
|
65
|
-
if (!
|
|
68
|
+
if (!reputable) {
|
|
66
69
|
// Delete user
|
|
67
70
|
await auth.deleteUser(user.uid)
|
|
68
71
|
// Throw error
|
|
@@ -70,11 +73,13 @@ export const registerAuthUser = functions
|
|
|
70
73
|
makeError(
|
|
71
74
|
"permission-denied",
|
|
72
75
|
"The user is not allowed to sign up because their Github reputation is not high enough.",
|
|
73
|
-
`The user ${user.displayName} is not allowed to sign up because their Github reputation is not high enough. Please contact the administrator if you think this is a mistake.`
|
|
76
|
+
`The user ${user.displayName === "Null" || user.displayName === null ? user.uid : user.displayName } is not allowed to sign up because their Github reputation is not high enough. Please contact the administrator if you think this is a mistake.`
|
|
74
77
|
)
|
|
75
78
|
)
|
|
76
|
-
}
|
|
77
|
-
|
|
79
|
+
}
|
|
80
|
+
// store locally
|
|
81
|
+
avatarUrl = avatarURL
|
|
82
|
+
printLog(`Github reputation check passed for user ${user.displayName === "Null" || user.displayName === null ? user.uid : user.displayName }`, LogLevel.DEBUG)
|
|
78
83
|
} catch (error: any) {
|
|
79
84
|
// Delete user
|
|
80
85
|
await auth.deleteUser(user.uid)
|
|
@@ -89,6 +94,8 @@ export const registerAuthUser = functions
|
|
|
89
94
|
}
|
|
90
95
|
}
|
|
91
96
|
// Set document (nb. we refer to providerData[0] because we use Github OAuth provider only).
|
|
97
|
+
// In future releases we might want to loop through the providerData array as we support
|
|
98
|
+
// more providers.
|
|
92
99
|
await userRef.set({
|
|
93
100
|
name: encodedDisplayName,
|
|
94
101
|
encodedDisplayName,
|
|
@@ -101,7 +108,15 @@ export const registerAuthUser = functions
|
|
|
101
108
|
photoURL: photoURL || "",
|
|
102
109
|
lastUpdated: getCurrentServerTimestampInMillis()
|
|
103
110
|
})
|
|
111
|
+
|
|
112
|
+
// we want to create a new collection for the users to store the avatars
|
|
113
|
+
const avatarRef = firestore.collection(commonTerms.collections.avatars.name).doc(uid)
|
|
114
|
+
await avatarRef.set({
|
|
115
|
+
avatarUrl: avatarUrl || "",
|
|
116
|
+
})
|
|
117
|
+
|
|
104
118
|
printLog(`Authenticated user document with identifier ${uid} has been correctly stored`, LogLevel.DEBUG)
|
|
119
|
+
printLog(`Authenticated user avatar with identifier ${uid} has been correctly stored`, LogLevel.DEBUG)
|
|
105
120
|
})
|
|
106
121
|
/**
|
|
107
122
|
* Set custom claims for role-based access control on the newly created user.
|