Closed twllight closed 4 years ago
You should not need a different key to use adal. That exception message says "Expected Start of Certificate to be '-----BEGIN RSA PRIVATE KEY-----'". Was it the case of your key?
By the way, since it sounds like you were just starting your new project ("I'm working to setup a quick python app"), we would suggest you to try ADAL's successor, MSAL Python, first. It contains lots of improvement and supports more features.
Lastly, where did you know ADAL Python from? If it is an online page hosted by us, we would like to add an advertisement there. :-)
my key is a combo pem key which I use for azure cli logins, which is starts with ---BEGIN PRIVATE KEY---. I found ADAL from needing to authenticate via a service principal without the use of a password, rather just a key file which we are using via the azure-cli. I'll look at MSAL to see if this allows me to authenticate.
Hi @twllight , we believe we now have more understanding on that "Expected Start of Certificate to be '-----BEGIN RSA PRIVATE KEY-----'" thing.
TL;DR: Our latest authentication library, MSAL Python, provides a slightly different suggestion for the exception in such case. And we heard from other customer report that it would help. So you might want to give "pip install cryptography" a shot.
Longer answer:
Just in case, if the above suggestion still won't work, then we need to start a debug session. Here is a minimum equivalent snippet of how ADAL/MSAL calls the PyJWT library.
import sys
import jwt # Normally installed by "pip install pyjwt", but (*)
key = open(sys.argv[1]).read()
print(jwt.encode({"foo": "bar"}, key, algorithm="RS256"))
You can try to run it with a single command line parameter of the file name of your cert file, and see how it pan out:
python test_cert.py my_cert.pem
(*) You will likely see exception, please paste them, and/or try to do pip install pyjwt[crypto]
and re-run and see if it helps.
@twllight : where you able to use @rayluo's answer? I'm closing this issue but please re-activate if you believe we can do more. Note: As @rayluo mentions we highly recommend moving to our latest version of the Python Auth library, MSAL Python
Hi @rayluo The page https://docs.microsoft.com/en-us/samples/azure-samples/data-lake-analytics-python-auth-options/authenticating-your-python-application-against-azure-active-directory/ mention the ADAL python code to authenticate. I believe the exact same issue than twilight got me here. So i'm moving to MSAL, thanks ;)
@navyasric ^^
Hello! I'm working to setup a quick python app to pull down some information from azure using a service principal via the python SDK. While I know I can use a password i'm looking to authenticate via service principal certificate. When doing so I receive the following errors:
I use this same key to authenticate via service principal through the azure cli. Do i need a secondary key to use adal authentication?
my code making the call: