update readme

This commit is contained in:
Ray Lyon
2023-08-05 15:03:00 +00:00
parent 75b0fedbd5
commit 62ffe0d491
2 changed files with 47 additions and 34 deletions

View File

@@ -1,49 +1,62 @@
# SuccessFactors + Python # SuccessFactors Auth
Authenticate with and use the SAP SuccessFactors API with Python. Authenticate with the SAP SuccessFactors API with OAuth2 and Python.
## Authentcation ## How to use
### How to use
1. Create an OAuth application in SuccessFactors. 1. Create an OAuth application in SuccessFactors.
2. Download the private key and copy the Client ID. 2. Download the private key and copy the Client ID.
3. Clone this repo and copy `sf_auth.py` and `sf_saml_template.xml` into your Python project directory. 3. Install the Python module:
4. Import `sf_auth` into your project. ``` shell
5. Install all the requirements listed in `requirements.txt` in this repo. pip install successfactors_auth
6. Call the `sf_auth.auth()` function in your Python project. You'll need to pass the following parameters: ```
4. Import `successfactors_auth` into your Python >=3.9 project.
5. Call the `successfactors_auth.auth()` function in your Python project. You'll need to pass the following parameters:
- `sf_url`: Base API url of your SuccessFactors instance, e.g. "https://api55.sapsf.eu". - `sf_url`: Base API url of your SuccessFactors instance, e.g. "https://api55.sapsf.eu".
- `sf_company_id`: SuccessFactors company ID. - `sf_company_id`: SuccessFactors company ID.
- `sf_oauth_client_id`: The Client ID for the OAuth application you created earlier. - `sf_oauth_client_id`: The Client ID for the OAuth application you created earlier.
- `sf_admin_user`: An admin user in SuccessFactors that has access to the OAuth application. - `sf_admin_user`: An admin user in SuccessFactors that has access to the OAuth application.
- `sf_saml_private_key`: Path to the private key file you downloaded when you created the OAuth application. - `sf_saml_private_key`: Path to the private key file you downloaded when you created the OAuth application.
- `template_file`: Path to the template file from this repo.
Example: ### Example
``` python
#!/usr/bin/env python
import requests ``` python
import sf_auth #!/usr/bin/env python
sf_url = 'https://your.base.url.com' import requests
sf_company_id = 'your-company-id' import successfactors_auth
sf_oauth_client_id = 'OAUTH-CLIENT-ID'
sf_admin_user = 'your_admin_user'
sf_saml_private_key = 'your_app_private_key.pem'
template_file = 'sf_saml_template.xml'
token = sf_auth.auth(sf_url, sf_company_id, sf_oauth_client_id, sf_admin_user, sf_saml_private_key, sf_saml_template) sf_url = 'https://your.base.url.com'
sf_company_id = 'your-company-id'
sf_oauth_client_id = 'your_app_client_id'
sf_admin_user = 'your_admin_user'
sf_saml_private_key = 'your_app_private_key.pem'
headers = { token = successfactors_auth.auth(
"Accept: application/json", sf_url,
f"Authorization: {token}" sf_company_id,
} sf_oauth_client_id,
sf_admin_user,
sf_saml_private_key,
sf_saml_template
)
request = requests.get(f"{sf_url}/User", headers=headers) headers = {
"Accept: application/json",
f"Authorization: {token}"
}
print(request.json()) request = requests.get(f"{sf_url}/User", headers=headers)
``` user = request.json()
### Using as an AWS Lambda function w/ API Gateway print(user)
```
Coming soon... ## Background
I wrote this module because I was forced to deal with the *horrific* SAP SuccessFactors API at my job, and I wanted to make sure other devs/sysadmins wouldn't have to feel the pain that I felt.
Once you get authenticated, getting the information you want is a whole new level of suffering. I hope to publish some more examples in the form of a blog post or docs in this repo.
## Contributing
All contributions welcome! Feel free to file an [issue](https://github.com/skoobasteeve/successfactors_auth/issues) or open a [pull request](https://github.com/skoobasteeve/successfactors_auth/pulls).

View File

@@ -4,13 +4,13 @@ build-backend = "hatchling.build"
[project] [project]
name = "successfactors_auth" name = "successfactors_auth"
version = "0.0.3" version = "0.0.4"
authors = [ authors = [
{ name="Ray Lyon", email="ray@raylyon.net" }, { name="Ray Lyon", email="ray@raylyon.net" },
] ]
description = "Authenticate to the SuccessFactors API." description = "Authenticate to the SuccessFactors API."
readme = "README.md" readme = "README.md"
requires-python = ">=3.8" requires-python = ">=3.9"
classifiers = [ classifiers = [
"Programming Language :: Python :: 3", "Programming Language :: Python :: 3",
"License :: OSI Approved :: Apache Software License", "License :: OSI Approved :: Apache Software License",