Extract email for active directory users that don't have access to exchange (#3053)

This commit is contained in:
JBodkin-Amphora 2022-03-04 18:18:39 +00:00 committed by GitHub
parent bec4a29f19
commit 8567b56b8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 5 deletions

View file

@ -31,15 +31,17 @@ func (obj apiUser) getEmail() string {
// AD often doesn't have the email address returned, but we can parse it from the UPN
// UPN looks like:
// UPN looks like either:
// cdoxsey_pomerium.com#EXT#@cdoxseypomerium.onmicrosoft.com
// cdoxsey@pomerium.com
email := obj.UserPrincipalName
if idx := strings.Index(email, "#EXT"); idx > 0 {
email = email[:idx]
}
// find the last _ and replace it with @
if idx := strings.LastIndex(email, "_"); idx > 0 {
email = email[:idx] + "@" + email[idx+1:]
// find the last _ and replace it with @
if idx := strings.LastIndex(email, "_"); idx > 0 {
email = email[:idx] + "@" + email[idx+1:]
}
}
return email
}