-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(NODE-5464): refactor reauth signature
- Loading branch information
Showing
6 changed files
with
101 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Binary, BSON, type Document } from 'bson'; | ||
|
||
import { type MongoCredentials } from '../mongo_credentials'; | ||
import { AuthMechanism } from '../providers'; | ||
|
||
/** | ||
* Generate the finishing command document for authentication. Will be a | ||
* saslStart or saslContinue depending on the presence of a conversation id. | ||
*/ | ||
export function finishCommandDocument(token: string, conversationId?: number): Document { | ||
if (conversationId != null && typeof conversationId === 'number') { | ||
return { | ||
saslContinue: 1, | ||
conversationId: conversationId, | ||
payload: new Binary(BSON.serialize({ jwt: token })) | ||
}; | ||
} | ||
// saslContinue requires a conversationId in the command to be valid so in this | ||
// case the server allows "step two" to actually be a saslStart with the token | ||
// as the jwt since the use of the cached value has no correlating conversating | ||
// on the particular connection. | ||
return { | ||
saslStart: 1, | ||
mechanism: AuthMechanism.MONGODB_OIDC, | ||
payload: new Binary(BSON.serialize({ jwt: token })) | ||
}; | ||
} | ||
|
||
/** | ||
* Generate the saslStart command document. | ||
*/ | ||
export function startCommandDocument(credentials: MongoCredentials): Document { | ||
const payload: Document = {}; | ||
if (credentials.username) { | ||
payload.n = credentials.username; | ||
} | ||
return { | ||
saslStart: 1, | ||
autoAuthorize: 1, | ||
mechanism: AuthMechanism.MONGODB_OIDC, | ||
payload: new Binary(BSON.serialize(payload)) | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters