Quick start
Assuming you've already configured an app in your Salesforce instance to serve as an OAuth provider, the following should get you up and running.
Install
pip install django-salesforce-oauth
Settings
Add the app to your INSTALLED_APPS in your django settings (settings.py):
INSTALLED_APPS = [
# ...
"django_salesforce_oauth",
]
Add the following required variables to your settings.py:
SCOPES = "YOUR SCOPES" # space delimited, e.g., "id api refresh_token"
SFDC_CONSUMER_KEY = "YOUR KEY"
SFDC_CONSUMER_SECRET = "YOUR SECRET"
OAUTH_REDIRECT_URI = "{YOUR DOMAIN}/oauth/callback/"
# Optional, but Django provides a default you likely don't want
LOGIN_REDIRECT_URL = "/"
Urls
Add django-salesforce-oauth's urls to your main urls.py.
from django.urls import path, include
urlpatterns = [
# ...
path("oauth/", include("django_salesforce_oauth.urls")),
]
Then redirect sign-in requests to the oauth namespace.
View example
from django.shortcuts import redirect
def your_view(request):
return redirect("oauth") # or "oauth-sandbox"
Template example
<a href="{% url 'oauth' %}" class="btn btn-primary">Login</a>
Advanced usage
Custom callback
You likely will want to customize what happens after the OAuth flow is complete instead of simply
getting or creating a user. This can be done by specifying the following in your settings.py.
CUSTOM_CALLBACK = "path.to.module.your_callback_function"
your_callback_function must accept the following two arguments:
- the request object (useful in case you want to handle redirection yourself)
- the OAuth object (contains all token and user data)
If you send the user to the oauth view with a query parameter called state, then you must
provide a third, optional argument to your custom callback function.
- the state parameter. Only requered if you redirect to
oauthwith?state=valuein your query params.
An example signature is:
def your_callback_function(request, oauth, state=None):
...
If you do not return a redirect from your_callback_function, it's expected it will return
a user object. In this case the user will then be signed in and redirected to
settings.LOGIN_REDIRECT_URL (which you'll most likely want to set in your settings.py).
Customizing the callback URI
By default the view behind the oauth-callback namespace, specified in the django_salesforce_oauth's app's urls.py, is what needs to match settings.OAUTH_REDIRECT_URI.
But this can be customized by pointing it to some other url and registering the view wherever
you'd like it declared.
# urls.py
from django_salesforce_oauth.views import oauth_callback
urlpatterns = [
# ...
# pass {"domain": "test"} to use a sandbox
path("my/custom/url", oauth_callback, {"domain": "login"}, name="custom-oauth-callback"),
]
Example project
The example project provides a full example of how to use this package, but since it's an integration, there's a few steps to actually running it.
SFDC
Configure a SFDC OAuth app with which you can OAuth against.
.env
Place a .env file inside the project folder that contains the following keys
from the OAuth app you configured above:
SFDC_CONSUMER_KEY=some_key
SFDC_CONSUMER_SECRET=secret_stuff
django
run migrations and start the server!
This project uses poetry for dependency management and packaging.
Metadata
Release files for django-salesforce-oauth 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django-salesforce-oauth-1.0.0.tar.gz | 5.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_salesforce_oauth-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.6 kB
Release files / django-salesforce-oauth-1.0.0.tar.gz
| Download URL | django-salesforce-oauth-1.0.0.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a71fdf7a4049d672a417a59b2595321da8ff18fc9ddef98feabc6d9046f23c4c
|
|
BLAKE2b-256 checksum How to use checksums |
495adc2f18837ceb6d564ee5cc13ce8a1385308465e230d4992dd03dfd92644f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.8.13 Linux/5.4.0-1086-azure
|
Release files / django_salesforce_oauth-1.0.0-py3-none-any.whl
| Download URL | django_salesforce_oauth-1.0.0-py3-none-any.whl |
|---|---|
| Size | 6.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a4ea5dc82bb9f95cdd07059bf0dc5ba1db7984e07caa111049887ec965e56db8
|
|
BLAKE2b-256 checksum How to use checksums |
59306a3c1b4f4a0f60ed788ba99a1e5f94c125652f7bae0e3f5b272f2b345d98
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.8.13 Linux/5.4.0-1086-azure
|
Security for django-salesforce-oauth 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.