Skip to content

Commit 68a7cb3

Browse files
committed
Read credential from pfx
1 parent 03eeb79 commit 68a7cb3

6 files changed

+27
-90
lines changed

msal/application.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ def __init__(
283283
"passphrase": "Passphrase if the private_key is encrypted (Optional. Added in version 1.6.0)",
284284
}
285285
286+
The following command will generate a .pfx file from your .key and .pem file::
287+
288+
openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.pem
289+
286290
:type client_credential: Union[dict, str]
287291
288292
:param dict client_claims:

sample/.env.sample.entra-id

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
# Alternatively, use "https://login.microsoftonline.com/common" for multi-tenant app.
99
AUTHORITY=<authority url>
1010

11-
# The following variables are required for the app to run.
1211
CLIENT_ID=<client id>
1312

14-
# Leave it empty if you are using a public client which has no client secret.
15-
CLIENT_SECRET=<client secret>
13+
# Uncomment the following setting if you are using a confidential client
14+
# which has a client secret. Example value: your password
15+
#CLIENT_SECRET=<client secret>
16+
17+
# Configure this if you are using a confidential client which has a client credential.
18+
# Example value: {"private_key_pfx_path": "/path/to/your.pfx"}
19+
CLIENT_CREDENTIAL_JSON=<client credential json>
1620

1721
# Multiple scopes can be added into the same line, separated by a space.
1822
# Here we use a Microsoft Graph API as an example

sample/.env.sample.external-id

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
# configure AUTHORITY as https://contoso.ciamlogin.com/contoso.onmicrosoft.com
55
AUTHORITY=<authority url>
66

7-
# The following variables are required for the app to run.
87
CLIENT_ID=<client id>
98

10-
# Leave it empty if you are using a public client which has no client secret.
11-
CLIENT_SECRET=<client secret>
9+
# Uncomment the following setting if you are using a confidential client
10+
# which has a client secret. Example value: your password
11+
#CLIENT_SECRET=<client secret>
12+
13+
# Configure this if you are using a confidential client which has a client credential.
14+
# Example value: {"private_key_pfx_path": "/path/to/your.pfx"}
15+
CLIENT_CREDENTIAL_JSON=<client credential json>
1216

1317
# Multiple scopes can be added into the same line, separated by a space.
1418
# Here we use a Microsoft Graph API as an example

sample/.env.sample.external-id-custom-domain

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
# "https://www.contoso.com/TENANT_GUID/v2.0"
66
OIDC_AUTHORITY=<authority url>
77

8-
# The following variables are required for the app to run.
98
CLIENT_ID=<client id>
109

11-
# Leave it empty if you are using a public client which has no client secret.
12-
CLIENT_SECRET=<client secret>
10+
# Uncomment the following setting if you are using a confidential client
11+
# which has a client secret. Example value: your password
12+
#CLIENT_SECRET=<client secret>
13+
14+
# Configure this if you are using a confidential client which has a client credential.
15+
# Example value: {"private_key_pfx_path": "/path/to/your.pfx"}
16+
CLIENT_CREDENTIAL_JSON=<client credential json>
1317

1418
# Multiple scopes can be added into the same line, separated by a space.
1519
# Here we use a Microsoft Graph API as an example

sample/confidential_client_certificate_sample.py

Lines changed: 0 additions & 80 deletions
This file was deleted.

sample/confidential_client_secret_sample.py renamed to sample/confidential_client_sample.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
os.getenv('CLIENT_ID'),
4444
authority=os.getenv('AUTHORITY'), # For Entra ID or External ID
4545
oidc_authority=os.getenv('OIDC_AUTHORITY'), # For External ID with custom domain
46-
client_credential=os.getenv('CLIENT_SECRET'),
46+
client_credential=os.getenv('CLIENT_SECRET') # ENV VAR contains a quotation mark-less string
47+
or json.loads(os.getenv('CLIENT_CREDENTIAL_JSON')), # ENV VAR contains a JSON blob as a string
4748
token_cache=global_token_cache, # Let this app (re)use an existing token cache.
4849
# If absent, ClientApplication will create its own empty token cache
4950
)

0 commit comments

Comments
 (0)