Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add email validation #622

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/components/services/user-info/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ const ROLES_FROM_USER_ID_CACHE_NAME = 'rolesFromUserId'
const USER_ID_FROM_EMAIL_CACHE_NAME = 'userIdFromEmail'
const THIRTY_MINUTES_IN_MILLISECONDS = 1800000

const validateEmail = email => String(email)
.toLowerCase()
.match(
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
)

class Auth0Service {
boot (options) {
this.logger = options.bootedServices.logger.child('service:userInfo')
Expand Down Expand Up @@ -120,6 +126,8 @@ class Auth0Service {
* @returns {undefined}
*/
async userIdFromEmail (email) {
if (!validateEmail(email)) return

const userId = this.userIdFromEmailCache(email)
if (userId) {
return userId
Expand Down Expand Up @@ -165,7 +173,9 @@ class Auth0Service {
// //////////////////
// internal
userIdFromEmailCache (email) { return this.cacheService.get(USER_ID_FROM_EMAIL_CACHE_NAME, email) }

emailFromUserIdCache (userId) { return this.cacheService.get(EMAIL_FROM_USER_ID_CACHE_NAME, userId) }

rolesFromUserIdCache (userId) { return this.cacheService.get(ROLES_FROM_USER_ID_CACHE_NAME, userId) }

async _addToCache (userId, email, groups = []) {
Expand Down