Skip to content

Commit 70dcf13

Browse files
committed
if an email is configured then use that
1 parent 8678ae1 commit 70dcf13

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

internal/handlers/token.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (h *TokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
8888
return
8989
}
9090

91-
idToken, err := generateIDToken(h.issuerURL, clientID)
91+
idToken, err := h.generateIDToken(h.issuerURL, clientID)
9292
if err != nil {
9393
log.Printf("Error generating ID token: %v", err)
9494
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
@@ -139,11 +139,21 @@ func generateRefreshToken(clientID string) string {
139139
}
140140

141141
// Helper function to generate a mock ID token
142-
func generateIDToken(issuerURL, clientID string) (string, error) {
142+
func (h *TokenHandler) generateIDToken(issuerURL, clientID string) (string, error) {
143143
// Generate a subject ID based on client ID
144144
sub := "user-" + clientID
145-
// Generate a default email based on client ID
146-
email := clientID + "@example.com"
147-
145+
146+
// Check if there's a configured email in the token config
147+
var email string
148+
tokenConfig := h.store.GetTokenConfig()
149+
if tokenConfig != nil {
150+
if userInfoConfig, ok := tokenConfig["user_info"].(map[string]interface{}); ok {
151+
if configuredEmail, ok := userInfoConfig["email"].(string); ok {
152+
email = configuredEmail
153+
}
154+
}
155+
}
156+
157+
// If no email is configured, pass empty string (don't default to generated email)
148158
return jwt.GenerateIDToken(issuerURL, clientID, sub, email)
149159
}

internal/jwt/jwt.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ func GenerateIDToken(issuer, clientID, sub, email string) (string, error) {
5252
"exp": now.Add(time.Hour).Unix(),
5353
"iat": now.Unix(),
5454
"nonce": generateNonce(),
55-
"email": email,
55+
}
56+
57+
// Only include email claim if an email is provided
58+
if email != "" {
59+
claims["email"] = email
5660
}
5761

5862
token := jwt.NewWithClaims(jwt.SigningMethodRS256, claims)

0 commit comments

Comments
 (0)