Skip to content

Commit 5aa9efd

Browse files
committed
fix(NODE-2026): support SERVICE_REALM authentication mechanism property
1 parent 1cdb860 commit 5aa9efd

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/cmap/auth/gssapi.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { Document } from '../../bson';
77
type MechanismProperties = {
88
gssapiCanonicalizeHostName?: boolean;
99
SERVICE_NAME?: string;
10+
SERVICE_REALM?: string;
1011
};
1112

1213
import * as dns from 'dns';
@@ -89,14 +90,20 @@ function makeKerberosClient(authContext: AuthContext, callback: Callback<Kerbero
8990
Object.assign(initOptions, { user: username, password: password });
9091
}
9192

92-
Kerberos.initializeClient(
93-
`${serviceName}${process.platform === 'win32' ? '/' : '@'}${host}`,
94-
initOptions,
95-
(err: string, client: KerberosClient): void => {
96-
if (err) return callback(new MongoDriverError(err));
97-
callback(undefined, client);
93+
let spn: string;
94+
if (process.platform === 'win32') {
95+
spn = `${serviceName}/${host}`;
96+
if ('SERVICE_REALM' in mechanismProperties) {
97+
spn = `${spn}@${mechanismProperties.SERVICE_REALM}`;
9898
}
99-
);
99+
} else {
100+
spn = `${serviceName}@${host}`;
101+
}
102+
103+
Kerberos.initializeClient(spn, initOptions, (err: string, client: KerberosClient): void => {
104+
if (err) return callback(new MongoDriverError(err));
105+
callback(undefined, client);
106+
});
100107
}
101108
);
102109
}

0 commit comments

Comments
 (0)