Skip to content

Commit

Permalink
Improve username for smtp connector
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuelegissi committed Jan 11, 2024
1 parent bf2fca9 commit 3b8515d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
27 changes: 15 additions & 12 deletions connector/smtp/smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,18 @@ func (sc *smtpConnector) Login(ctx context.Context, _ connector.Scopes, username
return
}

// Add and check domain
// Check domain

at := "@" + sc.cfg.Domain
if !strings.Contains(username, "@") {
username = username + at
}
if !strings.HasSuffix(username, at) {
// username ends in something other than @$DOMAIN, so we reject it.
valid = false
err = nil
return
name, domain, found := strings.Cut(username, "@")
if found {
if domain != sc.cfg.Domain {
// username ends in something other than @$DOMAIN, so we reject it.
valid = false
err = nil
return
}
} else {
username += "@" + sc.cfg.Domain
}

// Auth and check
Expand All @@ -87,10 +88,12 @@ func (sc *smtpConnector) Login(ctx context.Context, _ connector.Scopes, username
return
}

// Prepare id

id = connector.Identity{
UserID: username,
Username: username,
PreferredUsername: username,
Username: name,
PreferredUsername: name,
Email: username,
EmailVerified: true,
}
Expand Down
23 changes: 23 additions & 0 deletions examples/smtp/config-smtp-vvf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
issuer: http://127.0.0.1:5556/dex
storage:
type: sqlite3
config:
file: examples/dex.db
web:
http: 0.0.0.0:5556

connectors:
- type: smtp
name: Vigilfuoco
id: smtp-vigilfuoco
config:
host: smtp-s.vigilfuoco.it:465
domain: vigilfuoco.it
label: Username (nome.cognome)

staticClients:
- id: example-app
redirectURIs:
- 'http://127.0.0.1:5555/callback'
name: 'Example App'
secret: ZXhhbXBsZS1hcHAtc2VjcmV0

0 comments on commit 3b8515d

Please sign in to comment.