Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: update idp default value (#7108)

boojackaac0ebc260a5
diff --git a/backend/api/v1/auth_service.go b/backend/api/v1/auth_service.go
index 528c3e05b9..fec2c0a6b9 100644
--- a/backend/api/v1/auth_service.go
+++ b/backend/api/v1/auth_service.go
@@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"net/mail"
+ "regexp"
"strings"
"golang.org/x/crypto/bcrypt"
@@ -745,8 +746,9 @@ func (s *AuthService) getOrCreateUserWithIDP(ctx context.Context, request *v1pb.
var email string
if fieldMapping.Identifier == fieldMapping.Email {
email = strings.ToLower(userInfo.Email)
- } else {
- email = strings.ToLower(fmt.Sprintf("%s@%s", userInfo.Identifier, idp.Domain))
+ } else if idp.Domain != "" {
+ domain := extractDomain(idp.Domain)
+ email = strings.ToLower(fmt.Sprintf("%s@%s", userInfo.Identifier, domain))
}
if email == "" {
return nil, status.Errorf(codes.NotFound, "unable to identify the user by provider user info")
@@ -839,6 +841,23 @@ func validatePhone(phone string) error {
return nil
}
+func extractDomain(input string) string {
+ pattern := `[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+`
+ regExp, err := regexp.Compile(pattern)
+ if err != nil {
+ // WHen the pattern is invalid, we just return the input.
+ return input
+ }
+
+ match := regExp.FindString(input)
+ domainParts := strings.Split(match, ".")
+ // If the domain has at least 3 parts, we will remove the first part.
+ if len(domainParts) >= 3 {
+ match = strings.Join(domainParts[1:], ".")
+ }
+ return match
+}
+
const (
// issuerName is the name of the issuer of the OTP token.
issuerName = "Bytebase"
diff --git a/backend/api/v1/auth_service_test.go b/backend/api/v1/auth_service_test.go
index cd48565671..a9a0ae6af6 100644
--- a/backend/api/v1/auth_service_test.go
+++ b/backend/api/v1/auth_service_test.go
@@ -25,3 +25,34 @@ func TestValidatePhone(t *testing.T) {
}
}
}
+
+func TestExtractDomain(t *testing.T) {
+ tests := []struct {
+ domain string
+ want string
+ }{
+ {
+ domain: "www.google.com",
+ want: "google.com",
+ },
+ {
+ domain: "code.google.com",
+ want: "google.com",
+ },
+ {
+ domain: "code.google.com.cn",
+ want: "google.com.cn",
+ },
+ {
+ domain: "google.com",
+ want: "google.com",
+ },
+ }
+
+ for _, test := range tests {
+ got := extractDomain(test.domain)
+ if got != test.want {
+ t.Errorf("extractDomain %s, got %s, want %s", test.domain, got, test.want)
+ }
+ }
+}
diff --git a/frontend/src/utils/idp.ts b/frontend/src/utils/idp.ts
index 77b61bf153..a0d1de7f84 100644
--- a/frontend/src/utils/idp.ts
+++ b/frontend/src/utils/idp.ts
@@ -38,8 +38,9 @@ export const identityProviderTemplateList: IdentityProviderTemplate[] = [
tokenUrl: "https://github.com/login/oauth/access_token",
userInfoUrl: "https://api.github.com/user",
scopes: ["user"],
+ skipTlsVerify: false,
fieldMapping: {
- identifier: "login",
+ identifier: "email",
displayName: "name",
email: "email",
},
@@ -57,8 +58,9 @@ export const identityProviderTemplateList: IdentityProviderTemplate[] = [
tokenUrl: "https://gitlab.com/oauth/token",
userInfoUrl: "https://gitlab.com/api/v4/user",
scopes: ["read_user"],
+ skipTlsVerify: false,
fieldMapping: {
- identifier: "username",
+ identifier: "email",
displayName: "name",
email: "email",
},
@@ -79,6 +81,7 @@ export const identityProviderTemplateList: IdentityProviderTemplate[] = [
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/userinfo.profile",
],
+ skipTlsVerify: false,
fieldMapping: {
identifier: "email",
displayName: "name",
@@ -98,6 +101,7 @@ export const identityProviderTemplateList: IdentityProviderTemplate[] = [
tokenUrl: "",
userInfoUrl: "",
scopes: [],
+ skipTlsVerify: false,
fieldMapping: {
identifier: "",
displayName: "",