Skip to content

Commit a075681

Browse files
committed
fix(NODE-2026): support SERVICE_REALM authentication mechanism property
1 parent 05035eb commit a075681

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';
@@ -90,14 +91,20 @@ function makeKerberosClient(authContext: AuthContext, callback: Callback<Kerbero
9091
Object.assign(initOptions, { user: username, password: password });
9192
}
9293

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

0 commit comments

Comments
 (0)