Skip to content

Commit

Permalink
use a closure for client_id
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Oct 30, 2023
1 parent ecfc31c commit 60535a8
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions .evergreen/auth_oidc/azure/test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pymongo import MongoClient
from functools import partial
import os
import json
from urllib.request import urlopen, Request
Expand All @@ -8,9 +9,8 @@
_AUTH_MAP["MONGODB-OIDC"] = _authenticate_oidc

app_id = os.environ['AZUREOIDC_CLIENTID']
client_id = os.environ['AZUREOIDC_TOKENCLIENT']

def callback(client_info, server_info):
def callback(client_id, client_info, server_info):
url = "http://169.254.169.254/metadata/identity/oauth2/token"
url += "?api-version=2018-02-01"
url += f"&resource=api://{app_id}"
Expand Down Expand Up @@ -41,8 +41,7 @@ def callback(client_info, server_info):
raise ValueError(msg)
return dict(access_token=data['access_token'])


props = dict(request_token_callback=callback)
props = dict(request_token_callback=partial(callback(os.environ['AZUREOIDC_TOKENCLIENT'])))
print('Testing MONGODB-OIDC on azure...')
print('Testing resource 1...')
c = MongoClient('mongodb://localhost:27017/?authMechanism=MONGODB-OIDC', authMechanismProperties=props)
Expand All @@ -51,7 +50,7 @@ def callback(client_info, server_info):
print('Testing resource 1... done.')

print('Testing resource 2...')
client_id = os.environ['AZUREOIDC_TOKENCLIENT2']
props = dict(request_token_callback=partial(callback(os.environ['AZUREOIDC_TOKENCLIENT2'])))
c = MongoClient('mongodb://localhost:27017/?authMechanism=MONGODB-OIDC', authMechanismProperties=props)
c.test.test.find_one({})
c.close()
Expand Down

0 comments on commit 60535a8

Please sign in to comment.