Last active
July 29, 2022 14:14
-
-
Save Tanver-Hasan/140a91c9746cf37f4530fc7afffdc6cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function (user, context, callback) { | |
const BANKID = 'SwedishBankID!NorwegianBankID!SuomiFi'; | |
if (context.protocol === "redirect-callback") { | |
return callback(null, user, context); | |
} | |
if (!BANKID.includes(context.connection) ) { | |
return callback(null, user, context); | |
} | |
let ManagementClient = require('[email protected]').ManagementClient; | |
let management = new ManagementClient({ | |
token: auth0.accessToken, | |
domain: auth0.domain | |
}); | |
let SSN = ''; | |
if (context.connection === 'NorwegianBankID'){ | |
SSN = user.socialno; | |
} | |
var params = { q: 'user_metadata.SSN:"' + SSN + '"' }; | |
management.getUsers(params, function (err, users) { | |
if (err) { return callback(err); } | |
if (Array.isArray(users) && users.length > 0 ){ | |
console.log("Found " + users.length + " users with the provided SSN"); | |
console.log(users[0]); | |
return callback(null, user, context); | |
} | |
console.log("No users found with the provided SSN . Redircting to the onboarding"); | |
const url= `https://${encodeURIComponent(context.request.hostname)}/authorize?client_id=${encodeURIComponent(context.request.query.client_id)}&response_type=${encodeURIComponent(context.request.query.response_type)}&scope=${encodeURIComponent(context.request.query.scope)}&redirect_uri=${encodeURIComponent(context.request.query.redirect_uri)}&state=${encodeURIComponent(context.request.query.state)}&nonce=${encodeURIComponent(context.request.query.nonce)}&connection=Username-Password-Authentication`; | |
context.redirect = { | |
url: url | |
}; | |
callback(null, user, context); | |
}); | |
console.log("Reach End of Rule "); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment