Skip to content

Commit e1c924b

Browse files
author
Sachin Maheshwari
committed
adding block user for prod tenant
1 parent 30eee19 commit e1c924b

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
function (user, context, callback) {
2+
if (context.clientID === configuration.CLIENT_ACCOUNTS_LOGIN) {
3+
console.log("rule:block-user:enter");
4+
5+
if (context.redirect) {
6+
console.log("rule:block-user:exiting due to context being a redirect");
7+
return callback(null, user, context);
8+
}
9+
10+
const FORBIDDEN_COUNTRIES_CODES = [
11+
"IRN",
12+
"PRK",
13+
"CUB",
14+
"SDN",
15+
"SSD", // (south sudan)
16+
"SYR",
17+
"BLR",
18+
"RUS",
19+
];
20+
21+
const handle = context.idToken[global.AUTH0_CLAIM_NAMESPACE + "handle"];
22+
if (!handle) {
23+
console.log("rule:block-user: exiting due to handle being null.");
24+
return callback(null, user, context);
25+
}
26+
27+
global.AUTH0_CLAIM_NAMESPACE = "https://" + configuration.DOMAIN + "/";
28+
const axios = require("[email protected]");
29+
const options = {
30+
method: "GET",
31+
url: `https://api.${configuration.DOMAIN}/v5/members/${handle}`,
32+
};
33+
34+
// Fetch v5 mmber Api.
35+
axios(options)
36+
.then((result) => {
37+
try {
38+
const data = result.data;
39+
40+
const { homeCountryCode, competitionCountryCode } = data;
41+
console.log(
42+
"rule:block-user: set block user ",
43+
homeCountryCode,
44+
competitionCountryCode
45+
);
46+
const blockIP =
47+
FORBIDDEN_COUNTRIES_CODES.includes(homeCountryCode) ||
48+
FORBIDDEN_COUNTRIES_CODES.includes(competitionCountryCode)
49+
? true
50+
: false;
51+
console.log(
52+
"rule:block-user: blocking user IP ? ..............",
53+
blockIP
54+
);
55+
context.idToken[global.AUTH0_CLAIM_NAMESPACE + "blockIP"] = blockIP;
56+
57+
if (blockIP) {
58+
context.idToken[global.AUTH0_CLAIM_NAMESPACE + "tcsso"] =
59+
"123|block";
60+
}
61+
62+
return callback(null, user, context);
63+
} catch (e) {
64+
console.log(
65+
"rule:block-user:error in member api response handling: ",
66+
e
67+
);
68+
return callback(null, user, context);
69+
}
70+
})
71+
.catch((requestError) => {
72+
console.log(
73+
"rule:block-user:failed to fetch member api, error: ",
74+
requestError.response.status
75+
);
76+
return callback(null, user, context);
77+
});
78+
} else {
79+
return callback(null, user, context);
80+
}
81+
}

0 commit comments

Comments
 (0)