@@ -296,7 +296,7 @@ func (u *ConnString) setDefaultAuthParams(dbName string) error {
296296 u .AuthMechanismProperties ["SERVICE_NAME" ] = "mongodb"
297297 }
298298 fallthrough
299- case "mongodb-aws" , "mongodb-x509" , "mongodb-oidc" :
299+ case "mongodb-aws" , "mongodb-x509" :
300300 if u .AuthSource == "" {
301301 u .AuthSource = "$external"
302302 } else if u .AuthSource != "$external" {
@@ -313,6 +313,13 @@ func (u *ConnString) setDefaultAuthParams(dbName string) error {
313313 u .AuthSource = "admin"
314314 }
315315 }
316+ case "mongodb-oidc" :
317+ if u .AuthSource == "" {
318+ u .AuthSource = dbName
319+ if u .AuthSource == "" {
320+ u .AuthSource = "$external"
321+ }
322+ }
316323 case "" :
317324 // Only set auth source if there is a request for authentication via non-empty credentials.
318325 if u .AuthSource == "" && (u .AuthMechanismProperties != nil || u .Username != "" || u .PasswordSet ) {
@@ -902,16 +909,15 @@ func (p *parser) parse(original string) (*ConnString, error) {
902909 uri := original
903910
904911 var err error
905- switch {
906- case strings .HasPrefix (uri , SchemeMongoDBSRV + "://" ):
912+ if strings .HasPrefix (uri , SchemeMongoDBSRV + "://" ) {
907913 connStr .Scheme = SchemeMongoDBSRV
908914 // remove the scheme
909915 uri = uri [len (SchemeMongoDBSRV )+ 3 :]
910- case strings .HasPrefix (uri , SchemeMongoDB + "://" ):
916+ } else if strings .HasPrefix (uri , SchemeMongoDB + "://" ) {
911917 connStr .Scheme = SchemeMongoDB
912918 // remove the scheme
913919 uri = uri [len (SchemeMongoDB )+ 3 :]
914- default :
920+ } else {
915921 return nil , errors .New (`scheme must be "mongodb" or "mongodb+srv"` )
916922 }
917923
@@ -922,9 +928,9 @@ func (p *parser) parse(original string) (*ConnString, error) {
922928 username := userInfo
923929 var password string
924930
925- if u , p , ok := strings .Cut (userInfo , ":" ); ok {
926- username = u
927- password = p
931+ if idx := strings .Index (userInfo , ":" ); idx != - 1 {
932+ username = userInfo [: idx ]
933+ password = userInfo [ idx + 1 :]
928934 connStr .PasswordSet = true
929935 }
930936
0 commit comments