Skip to content

Commit

Permalink
fix(NODE-2026): support SERVICE_REALM authentication mechanism property
Browse files Browse the repository at this point in the history
  • Loading branch information
rose-m committed Jun 28, 2021
1 parent 1cdb860 commit 5aa9efd
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/cmap/auth/gssapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { Document } from '../../bson';
type MechanismProperties = {
gssapiCanonicalizeHostName?: boolean;
SERVICE_NAME?: string;
SERVICE_REALM?: string;
};

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

Kerberos.initializeClient(
`${serviceName}${process.platform === 'win32' ? '/' : '@'}${host}`,
initOptions,
(err: string, client: KerberosClient): void => {
if (err) return callback(new MongoDriverError(err));
callback(undefined, client);
let spn: string;
if (process.platform === 'win32') {
spn = `${serviceName}/${host}`;
if ('SERVICE_REALM' in mechanismProperties) {
spn = `${spn}@${mechanismProperties.SERVICE_REALM}`;
}
);
} else {
spn = `${serviceName}@${host}`;
}

Kerberos.initializeClient(spn, initOptions, (err: string, client: KerberosClient): void => {
if (err) return callback(new MongoDriverError(err));
callback(undefined, client);
});
}
);
}
Expand Down

0 comments on commit 5aa9efd

Please sign in to comment.