Package: jamfAuth
JamfAuthA python script to authenticate with the Jamf Pro API.jamfAuth ExamplesCurrent Version:v0.3.4Starting with version 0.3.4, you now have the option to usejamfAuthwith a development server. By default,jamfAuthwill function as normal. If you want to usejamfAuthwith your development server, you will need to add"dev"inside thestartAuth()function (ie:startAuth("dev")). See the usage and example section for more details.Supported Operating SystemsOperating SystemVersionStatusNotesmacOS MontereymacOS 12.x✅(Supported)NoneWindows Server2022✅(Supported in 0.3.3+)NoneRedHat Enterprise Linux (RHEL)9 (Beta)✅(Supported in 0.3.3+)Requires keychains.alt packageRedHat Enterprise Linux (RHEL)8✅(Supported in 0.3.3+)Requires keychains.alt packageCentOS Stream8⚠️(Needs Testing)NoneOracle Linux8✅(Supported in 0.3.3+)Requires keychains.alt packageUbuntu Server20.04.4 LTS✅(Supported in 0.3.3+)Requires keychains.alt packageOverviewThis python script handles the API Authentication to your Jamf Pro Server. Once you have a valid API Token, you can store it as a variable and use it when performing API calls later in the script.Here is howjamfAuthworks:Checks to see if the JSON Config file exists.✅ JSON Config Found:Attempts to load theapiUserNameandjamfHostNamevariables⚠️ JSON Config Not Found:Creates an empty JSON Config file and prompts you for the following things:Jamf Pro Host Name,API UsernameOnce the above information is entered/loaded, it will check the local keychain for an API Token.✅ API Token Found:Checks to see if the API Token stored is valid✅ Valid Token:Returns the API Token for use⚠️ Invalid Token:Attempts to renew the API Token (usingkeep-alive). If the API Token is unable to be renewed, it will check the local keychain for theAPI Password✅ API Password Keychain Found:Uses theAPI Passwordto get a new API Token then saves it to the local keychain then returns it for use⚠️ API Password Keychain Not Found:Prompts for the API Password, stores it in the local keychain and gets a new API Token then returns it for use⚠️ API Token Not Found:Checks the local keychain for theAPI Password✅API Password Keychain Found:Uses theAPI Passwordto get a new API Token then saves it to the local keychain then returns it for use⚠️ API Password Keychain Not Found:Prompts for the API Password, stores it in the local keychain and gets a new API Token then returns it for useTheAPI PasswordandAPI Tokenwill be stored in the local keychain (using thekeyringpython library) with the following naming convention:VariableKeychain Naming ConventionAPI Passwordservice =JamfProHostName, username =API Username, password =API PasswordAPI Tokenservice =JamfProHostName, username =API Username+API, password =API TokenThejamfAuth.pyJSON Configuration file is located in thesupportdirectory:PRODUCTIONInstall MethodConfiguration File LocationGithub/path/to/jamfAuth/support/.jamfauth.jsonpip/path/to/pip/site-packages/jamfAuth/support/.jamfauth.jsonDEVInstall MethodCommandGithub/path/to/jamfAuth/support/.jamfauth-dev.jsonpip/path/to/pip/site-packages/jamfAuth/support/.jamfauth-dev.jsonjamfAuth OptionsThejamfAuthscript also has two options available for use to help make setup easier, these areresetandsetup. Depending on how you installedjamfAuthwill depend on how these two options can be called.Reset OptionPRODUCTIONInstall MethodCommandGithubpython3 /path/to/jamfAuth.py resetpippython3 -c 'from jamfAuth import *; reset_config()'DEVInstall MethodCommandGithubpython3 /path/to/jamfAuth.py reset-devpippython3 -c 'from jamfAuth import *; reset_config("dev")'Theresetoption allows you to reset the JSON Configuration file thatjamfAuth.pyuses. The following items in the JSON Config file will be reset:apiUserNamejamfHostNamejamfAPIURLAfter theresetoption is ran, you will be prompted to enter theJamf Pro Host NameandAPI Usernameon the next run.Setup OptionPRODUCTIONInstall MethodCommandGithubpython3 /path/to/jamfAuth.py setuppippython3 -c 'from jamfAuth import *; startAuth()'DEVInstall MethodCommandGithubpython3 /path/to/jamfAuth.py setup-devpippython3 -c 'from jamfAuth import *; startAuth("dev")'Thesetupoption allows you to setup the JSON Configuration file thatjamfAuthuses. You can use this option if you would like to avoid being prompted to enter information.Delete KeychainCurrently, deleting the keychain is a manual process. I plan on building this intojamfAuthto make it easier to do, but until then, use the command below to delete the keychain for your API account:python3 -c 'import keyring; keyring.delete_password("https://<JAMF_PRO_INSTANCE>/api/v1/", "<API_USERNAME>")'To-Do ListSave API Token in the keychain and remove it from the JSON config fileAdd usage examplesAdd additional error handling (if a 401 occurs.. etc..)Create pip installAdd option to delete the keychain entry (currently manual delete)Add additional OS support (linux, windows)Add support for a development serverInstallationThere are two ways to installjamfAuth:Githuborpip.pip Method[Recommended]This method will installjamfAuthandall of the required packages. Using this method will allow you to import and usejamfAuthwithout having to copy thejamfAuthdirectory into the project your going to use it with.pip3 install jamfAuthPyPi URLGithub MethodThis method will clone thejamfAuthcode to your system. When using this method, you will need to install the required Python3 packagesmanually.git clone https://github.com/therealmacjeezy/JamfAuth.gitRequirementsJamf ProA Jamf Pro account that has API AccessPythonPython VersionSupported3.8.9✅(Supported)3.9.x⚠️(Not Tested)3.10.x✅(Supported)Required Python Packages:requestspip3 install requestskeyringpip3 install keyringkeyrings.alt(Linux ONLY)pip3 install keyrings.altUsageOnce installed, you'll need to configurejamfAuthby using thesetupoption (seeSetup Optionsection above). This will create the jamfAuth configuration file and the keychain entries. Once it's setup, you're ready to start playing with API Calls!To usejamfAuthwith your script, importjamfAuthand set thestartAuth()function to a variable to store the API Token. See the example below.Note:If you used theGithubmethod to installjamfAuth, you will need to copy thejamfAuthdirectory into the root directory of the script you are going to be using it with. If you used thepipmethod, you can just importjamfAuthas normal.from jamfAuth import *

#### PRODUCTION SERVER EXAMPLE
apiPassword = startAuth()

#### DEVELOPMENT SERVER EXAMPLE
apiPassword = startAuth("dev")

if apiPassword:
    print('You can now use the apiToken variable to authenticate with your Jamf Pro API.')
    print(f'apiToken: \n{apiPassword}')ExamplesI created a few example scripts in bothpythonandbashto show how easy it is to use jamfAuth in your script. Check out theexamples README.mdto see them.