Skip to content

Commit d8cf6a5

Browse files
committed
enable other factors beside dice
1 parent 848e59a commit d8cf6a5

File tree

1 file changed

+22
-52
lines changed

1 file changed

+22
-52
lines changed

web-assets/auth0/dev-tenant/rules/DICE DID.js

Lines changed: 22 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function (user, context, callback) {
1+
function DICE(user, context, callback) {
22
if (context.clientID === configuration.CLIENT_ACCOUNTS_LOGIN) {
33
console.log("rule:DICE DID:enter");
44

@@ -22,27 +22,13 @@ function (user, context, callback) {
2222
console.log("rule:DICE DID:User was redirected to the /continue endpoint");
2323
if (context.request.query.diceVerificationStatus === 'false') {
2424
return callback('Login Error: Credentials verification is failed.<br>Please contact with support <a href="mailto:support@topcoder.com">support@topcoder.com</a>.<br> Back to application ', user, context);
25-
} else if (context.request.query.otp) {
26-
request.post({
27-
url: 'https://api.' + configuration.DOMAIN + '/v3/users/checkOtp',
28-
json: {
29-
"param": {
30-
"userId": user.userId,
31-
"otp": context.request.query.otp
32-
}
33-
}
34-
}, function (error, response, body) {
35-
if (error) return callback(error, user, context);
36-
if (response.statusCode !== 200) {
37-
return callback('Login Error: Whoops! Something went wrong.', user, context);
38-
}
39-
if (body.result.content.verified === true) {
40-
return callback(null, user, context);
41-
} else {
42-
return callback('Login Error: wrong OTP', user, context);
43-
}
44-
});
45-
} else {
25+
} else if (context.request.query.otherMethods || _.isEmpty(user.multifactor)) {
26+
context.multifactor = {
27+
provider: 'any',
28+
allowRememberBrowser: false
29+
};
30+
return callback(null, user, context);
31+
} else if (context.request.query.code) {
4632
const jwt_decode = require('jwt-decode');
4733
request.post({
4834
url: 'https://tc-vcauth-uat.diceid.com/vc/connect/token',
@@ -65,44 +51,24 @@ function (user, context, callback) {
6551
console.log("rule:DICE DID:credentials approved");
6652
return callback(null, user, context);
6753
});
54+
} else {
55+
return callback('Login Error: Whoops! Something went wrong.', user, context);
6856
}
6957
} else {
7058
const maxRetry = 2;
71-
const useOtp = function () {
72-
request.post({
73-
url: 'https://api.' + configuration.DOMAIN + '/v3/users/sendOtp',
74-
json: {
75-
"param": {
76-
"userId": user.userId
77-
}
78-
}
79-
}, function (error, response, body) {
80-
if (error) return callback(error, user, context);
81-
if (response.statusCode !== 200) {
82-
return callback('Login Error: Whoops! Something went wrong.', user, context);
83-
}
84-
console.log("rule:DICE DID: redirecting to OTP page");
85-
const hostName = _.get(context, "request.hostname", null);
86-
const otpCompletetUrl = "https://" + hostName + "/continue";
87-
const retUrl = _.get(context, "request.query.returnUrl", null);
88-
const otpRedirectUrl = configuration.CUSTOM_PAGES_BASE_URL +
89-
"/otp.html?formAction=" + otpCompletetUrl +
90-
"&returnUrl=" + retUrl;
91-
context.redirect = {
92-
url: otpRedirectUrl
93-
};
94-
return callback(null, user, context);
95-
});
96-
};
9759
const checkDiceHealth = function (attempt) {
9860
console.log("rule:DICE DID:checking dice health, attempt:" + attempt);
9961
request.get({
10062
url: 'https://tc-vcauth-uat.diceid.com/.well-known/openid-configuration'
10163
}, function (error, response, body) {
10264
if (error || response.statusCode !== 200) {
10365
if (attempt >= maxRetry) {
104-
console.log("rule:DICE DID:dice services down, using otp flow...");
105-
useOtp();
66+
console.log("rule:DICE DID:dice services down, using other factors...");
67+
context.multifactor = {
68+
provider: 'any',
69+
allowRememberBrowser: false
70+
};
71+
return callback(null, user, context);
10672
} else {
10773
checkDiceHealth(attempt + 1);
10874
}
@@ -116,8 +82,12 @@ function (user, context, callback) {
11682
});
11783
};
11884
if (!global.ENABLE_2FA) {
119-
console.log("rule:DICE DID:dice switch disabled, using otp flow...");
120-
useOtp();
85+
console.log("rule:DICE DID:dice switch disabled, using other factors...");
86+
context.multifactor = {
87+
provider: 'any',
88+
allowRememberBrowser: false
89+
};
90+
return callback(null, user, context);
12191
} else {
12292
checkDiceHealth(1);
12393
}

0 commit comments

Comments
 (0)