Skip to content

Commit 24dc578

Browse files
committed
test: azure oidc updates
1 parent e13afba commit 24dc578

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

.evergreen/prepare-shell.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export PATH="$MONGODB_BINARIES:$PATH"
3131

3232
if [ ! -d "$DRIVERS_TOOLS" ]; then
3333
# Only clone driver tools if it does not exist
34-
git clone --depth=1 "https://github.com/mongodb-labs/drivers-evergreen-tools.git" "${DRIVERS_TOOLS}"
34+
git clone --depth=1 --branch DRIVERS-2416-5 "https://github.com/blink1073/drivers-evergreen-tools.git" "${DRIVERS_TOOLS}"
3535
fi
3636

3737
echo "installed DRIVERS_EVERGREEN_TOOLS from commit $(git -C $DRIVERS_EVERGREEN_TOOLS rev-parse HEAD)"

.evergreen/run-oidc-tests.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ if [ "$PROVIDER_NAME" = "azure" ]; then
1717
echo "Must specify an AZUREOIDC_CLIENTID"
1818
exit 1
1919
fi
20-
MONGODB_URI="${MONGODB_URI}/?authMechanism=MONGODB-OIDC"
20+
MONGODB_URI="mongodb://${AZUREOIDC_USERNAME}@127.0.0.1:27017/?authMechanism=MONGODB-OIDC"
2121
MONGODB_URI="${MONGODB_URI}&authMechanismProperties=PROVIDER_NAME:azure"
22-
MONGODB_URI="${MONGODB_URI},TOKEN_AUDIENCE:api%3A%2F%2F${AZUREOIDC_CLIENTID}"
23-
export MONGODB_URI="${MONGODB_URI},TOKEN_CLIENT_ID:${AZUREOIDC_TOKENCLIENT}"
22+
export MONGODB_URI="${MONGODB_URI},TOKEN_AUDIENCE:api%3A%2F%2F${AZUREOIDC_CLIENTID}"
2423
npm run check:oidc-azure
2524
else
2625
echo $OIDC_ATLAS_URI_SINGLE

src/cmap/auth/mongodb_oidc/azure_machine_workflow.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { MachineWorkflow } from './machine_workflow';
66

77
/** Base URL for getting Azure tokens. */
88
const AZURE_BASE_URL =
9-
'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01';
9+
'http://169.254.169.254/metadata/identity/oauth2/token?';
1010

1111
/** Azure request headers. */
1212
const AZURE_HEADERS = Object.freeze({ Metadata: 'true', Accept: 'application/json' });
@@ -41,7 +41,7 @@ export class AzureMachineWorkflow extends MachineWorkflow {
4141
*/
4242
async getToken(credentials?: MongoCredentials): Promise<string> {
4343
const tokenAudience = credentials?.mechanismProperties.TOKEN_AUDIENCE;
44-
const tokenClientId = credentials?.mechanismProperties.TOKEN_CLIENT_ID;
44+
const username = credentials?.username;
4545
if (!tokenAudience) {
4646
throw new MongoAzureError(TOKEN_AUDIENCE_MISSING_ERROR);
4747
}
@@ -51,7 +51,7 @@ export class AzureMachineWorkflow extends MachineWorkflow {
5151
token = entry.token;
5252
} else {
5353
this.cache.deleteEntry(tokenAudience);
54-
const response = await getAzureTokenData(tokenAudience, tokenClientId);
54+
const response = await getAzureTokenData(tokenAudience, username);
5555
if (!isEndpointResultValid(response)) {
5656
throw new MongoAzureError(ENDPOINT_RESULT_ERROR);
5757
}
@@ -67,13 +67,15 @@ export class AzureMachineWorkflow extends MachineWorkflow {
6767
*/
6868
async function getAzureTokenData(
6969
tokenAudience: string,
70-
tokenClientId?: string
70+
username?: string
7171
): Promise<AzureAccessToken> {
72-
let url = `${AZURE_BASE_URL}&resource=${tokenAudience}`;
73-
if (tokenClientId) {
74-
url += `&client_id=${tokenClientId}`;
72+
const url = new URL(AZURE_BASE_URL);
73+
url.searchParams.append('api-version', '2018-02-01');
74+
url.searchParams.append('resource', tokenAudience);
75+
if (username) {
76+
url.searchParams.append('object_id', username);
7577
}
76-
const data = await request(url, {
78+
const data = await request(url.toString(), {
7779
json: true,
7880
headers: AZURE_HEADERS
7981
});

0 commit comments

Comments
 (0)