File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed
Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -829,11 +829,13 @@ type Credential struct {
829829 // Defaults to "MONGODB-CR".
830830 Mechanism string
831831
832- // Certificate defines an x509 certificate for authentication at login.
832+ // Certificate defines an x509 certificate for authentication at login,
833+ // for reference please see, https://docs.mongodb.com/manual/tutorial/configure-x509-client-authentication/
833834 // If providing a certificate:
834835 // The Username field is populated from the cert and should not be set
835836 // The Mechanism field should be MONGODB-X509 or not set.
836837 // The Source field should be $external or not set.
838+ // If not specified, the username will have to be set manually.
837839 Certificate * x509.Certificate
838840}
839841
@@ -858,14 +860,16 @@ func (s *Session) Login(cred *Credential) error {
858860
859861 credCopy := * cred
860862 if cred .Certificate != nil && cred .Username != "" {
861- return errors .New ("failed to login, both certifcate and credentials are given" )
863+ return errors .New ("failed to login, both certificate and credentials are given" )
862864 }
863865
864866 if cred .Certificate != nil {
865867 credCopy .Username , err = getRFC2253NameStringFromCert (cred .Certificate )
866868 if err != nil {
867869 return err
868870 }
871+ credCopy .Mechanism = "MONGODB-X509"
872+ credCopy .Source = "$external"
869873 }
870874
871875 if cred .Source == "" {
You can’t perform that action at this time.
0 commit comments