├── .circleci └── config.yml ├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE │ ├── Bug Report.yml │ ├── Feature Request.yml │ └── config.yml ├── dependabot.yml ├── stale.yml └── workflows │ └── semgrep.yml ├── 01-Login ├── .dockerignore ├── .env.example ├── .gitignore ├── Dockerfile ├── README.md ├── exec.ps1 ├── exec.sh ├── manage.py ├── requirements.txt └── webappexample │ ├── __init__.py │ ├── settings.py │ ├── templates │ └── index.html │ ├── urls.py │ ├── views.py │ └── wsgi.py ├── LICENSE └── README.md /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | # Common logic 2 | defaults: &defaults 3 | steps: 4 | - attach_workspace: 5 | at: ~/ 6 | - run: 7 | name: Replace Auth0 test credentials 8 | command: | 9 | mv $AUTH0_CFG.example $AUTH0_CFG 10 | sed -i 's/{CLIENT_ID}/'$AUTH0_TEST_CLIENT_ID'/g' $AUTH0_CFG 11 | sed -i 's/{DOMAIN}/'$AUTH0_TEST_DOMAIN'/g' $AUTH0_CFG 12 | sed -i 's/{CLIENT_SECRET}/'$AUTH0_TEST_CLIENT_SECRET'/g' $AUTH0_CFG 13 | - run: 14 | name: Build pull request 15 | command: | 16 | docker build -t $CIRCLE_JOB ./$SAMPLE_PATH 17 | docker run -d -p 3000:3000 --name $CIRCLE_SHA1 --env-file ./$AUTH0_CFG $CIRCLE_JOB 18 | background: true 19 | - run: 20 | name: Wait for app to be available 21 | command: | 22 | sleep 50 23 | docker run --network host --rm appropriate/curl --retry 8 --retry-connrefused -v localhost:3000 24 | - run: 25 | name: Run tests 26 | command: | 27 | docker create --network host --name tester codeceptjs/codeceptjs codeceptjs run-multiple --all --steps 28 | docker cp $(pwd)/lock_login_test.js tester:/tests/lock_login_test.js 29 | docker cp $(pwd)/codecept.conf.js tester:/tests/codecept.conf.js 30 | docker start -i tester 31 | working_directory: scripts 32 | - run: 33 | name: Copy app container logs 34 | command: | 35 | mkdir -p /tmp/out 36 | docker logs $CIRCLE_SHA1 > /tmp/out/app_logs.log 37 | docker cp tester:/tests/out /tmp/ 38 | when: on_fail 39 | - store_artifacts: 40 | path: /tmp/out 41 | 42 | # Jobs and Workflows 43 | version: 2.1 44 | parameters: 45 | machine_image: 46 | type: string 47 | default: ubuntu-2004:202201-02 48 | jobs: 49 | checkout: 50 | machine: 51 | image: << pipeline.parameters.machine_image >> 52 | steps: 53 | - checkout 54 | - run: git clone https://github.com/auth0-samples/spa-quickstarts-tests scripts 55 | - persist_to_workspace: 56 | root: ~/ 57 | paths: 58 | - project 59 | - scripts 60 | login: 61 | machine: 62 | image: << pipeline.parameters.machine_image >> 63 | environment: 64 | - AUTH0_CFG: 01-Login/.env 65 | - SAMPLE_PATH: 01-Login 66 | <<: *defaults 67 | 68 | workflows: 69 | version: 2 70 | quickstarts_login: 71 | jobs: 72 | - checkout: 73 | context: Quickstart Web App Test 74 | - login: 75 | context: Quickstart Web App Test 76 | requires: 77 | - checkout 78 | 79 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @auth0-samples/dx-sdks-engineer 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/Bug Report.yml: -------------------------------------------------------------------------------- 1 | name: 🐞 Report a bug 2 | description: Have you found a bug or issue? Create a bug report for this sample 3 | 4 | body: 5 | - type: markdown 6 | attributes: 7 | value: | 8 | **Please do not report security vulnerabilities here**. The [Responsible Disclosure Program](https://auth0.com/responsible-disclosure-policy) details the procedure for disclosing security issues. 9 | 10 | - type: checkboxes 11 | id: checklist 12 | attributes: 13 | label: Checklist 14 | options: 15 | - label: I have looked into the [Readme](https://github.com/auth0-samples/auth0-django-web-app/tree/master/01-Login#readme) and have not found a suitable solution or answer. 16 | required: true 17 | - label: I have searched the [issues](https://github.com/auth0-samples/auth0-django-web-app/issues) and have not found a suitable solution or answer. 18 | required: true 19 | - label: I have searched the [Auth0 Community](https://community.auth0.com) forums and have not found a suitable solution or answer. 20 | required: true 21 | - label: I agree to the terms within the [Auth0 Code of Conduct](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md). 22 | required: true 23 | 24 | - type: textarea 25 | id: description 26 | attributes: 27 | label: Description 28 | description: Provide a clear and concise description of the issue, including what you expected to happen. 29 | validations: 30 | required: true 31 | 32 | - type: textarea 33 | id: reproduction 34 | attributes: 35 | label: Reproduction 36 | description: Detail the steps taken to reproduce this error, and whether this issue can be reproduced consistently or if it is intermittent. 37 | placeholder: | 38 | 1. Step 1... 39 | 2. Step 2... 40 | 3. ... 41 | validations: 42 | required: true 43 | 44 | - type: textarea 45 | id: additional-context 46 | attributes: 47 | label: Additional context 48 | description: Any other relevant information you think would be useful. 49 | validations: 50 | required: false 51 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/Feature Request.yml: -------------------------------------------------------------------------------- 1 | name: 🧩 Feature request 2 | description: Suggest an idea or a feature for this sample 3 | labels: ["feature request"] 4 | 5 | body: 6 | - type: checkboxes 7 | id: checklist 8 | attributes: 9 | label: Checklist 10 | options: 11 | - label: I have looked into the [Readme](https://github.com/auth0-samples/auth0-django-web-app/tree/master/01-Login#readme) and have not found a suitable solution or answer. 12 | required: true 13 | - label: I have searched the [issues](https://github.com/auth0-samples/auth0-django-web-app/issues) and have not found a suitable solution or answer. 14 | required: true 15 | - label: I have searched the [Auth0 Community](https://community.auth0.com) forums and have not found a suitable solution or answer. 16 | required: true 17 | - label: I agree to the terms within the [Auth0 Code of Conduct](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md). 18 | required: true 19 | 20 | - type: textarea 21 | id: description 22 | attributes: 23 | label: Describe the problem you'd like to have solved 24 | description: A clear and concise description of what the problem is. 25 | validations: 26 | required: true 27 | 28 | - type: textarea 29 | id: ideal-solution 30 | attributes: 31 | label: Describe the ideal solution 32 | description: A clear and concise description of what you want to happen. 33 | validations: 34 | required: true 35 | 36 | - type: textarea 37 | id: alternatives-and-workarounds 38 | attributes: 39 | label: Alternatives and current workarounds 40 | description: A clear and concise description of any alternatives you've considered or any workarounds that are currently in place. 41 | validations: 42 | required: false 43 | 44 | - type: textarea 45 | id: additional-context 46 | attributes: 47 | label: Additional context 48 | description: Add any other context or screenshots about the feature request here. 49 | validations: 50 | required: false 51 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: 🤔 Help & Questions 4 | url: https://community.auth0.com 5 | about: Ask general support or usage questions in the Auth0 Community forums. 6 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | 4 | - package-ecosystem: "pip" 5 | directory: "/01-Login" 6 | schedule: 7 | interval: "daily" 8 | ignore: 9 | - dependency-name: "*" 10 | update-types: ["version-update:semver-major", "version-update:semver-patch"] 11 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Configuration for probot-stale - https://github.com/probot/stale 2 | 3 | # Number of days of inactivity before an Issue or Pull Request becomes stale 4 | daysUntilStale: 90 5 | 6 | # Number of days of inactivity before an Issue or Pull Request with the stale label is closed. 7 | daysUntilClose: 7 8 | 9 | # Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable 10 | exemptLabels: [] 11 | 12 | # Set to true to ignore issues with an assignee (defaults to false) 13 | exemptAssignees: true 14 | 15 | # Label to use when marking as stale 16 | staleLabel: closed:stale 17 | 18 | # Comment to post when marking as stale. Set to `false` to disable 19 | markComment: > 20 | This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you have not received a response for our team (apologies for the delay) and this is still a blocker, please reply with additional information or just a ping. Thank you for your contribution! 🙇♂️ -------------------------------------------------------------------------------- /.github/workflows/semgrep.yml: -------------------------------------------------------------------------------- 1 | name: Semgrep 2 | 3 | on: 4 | pull_request: {} 5 | 6 | push: 7 | branches: ["master", "main"] 8 | 9 | schedule: 10 | - cron: '30 0 1,15 * *' 11 | 12 | jobs: 13 | semgrep: 14 | name: Scan 15 | runs-on: ubuntu-latest 16 | container: 17 | image: returntocorp/semgrep 18 | # Skip any PR created by dependabot to avoid permission issues 19 | if: (github.actor != 'dependabot[bot]') 20 | steps: 21 | - uses: actions/checkout@v3 22 | 23 | - run: semgrep ci 24 | env: 25 | SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }} 26 | -------------------------------------------------------------------------------- /01-Login/.dockerignore: -------------------------------------------------------------------------------- 1 | .env 2 | .env.example 3 | .gitignore 4 | .git 5 | README.md -------------------------------------------------------------------------------- /01-Login/.env.example: -------------------------------------------------------------------------------- 1 | AUTH0_CLIENT_ID={CLIENT_ID} 2 | AUTH0_CLIENT_SECRET={CLIENT_SECRET} 3 | AUTH0_DOMAIN={DOMAIN} 4 | -------------------------------------------------------------------------------- /01-Login/.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | db.sqlite3 3 | *.pyc 4 | -------------------------------------------------------------------------------- /01-Login/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.9 2 | 3 | WORKDIR /home/app 4 | 5 | #If we add the requirements and install dependencies first, docker can use cache if requirements don't change 6 | ADD requirements.txt /home/app 7 | RUN pip install --no-cache-dir -r requirements.txt 8 | 9 | ADD . /home/app 10 | 11 | # Migrate the database 12 | RUN python manage.py migrate 13 | 14 | CMD python manage.py runserver 0.0.0.0:3000 15 | 16 | EXPOSE 3000 17 | -------------------------------------------------------------------------------- /01-Login/README.md: -------------------------------------------------------------------------------- 1 | # Auth0 Python Web App Sample 2 | 3 | This sample demonstrates how to add authentication to a Django web app using Auth0. 4 | 5 | Check the [Django Quickstart](https://auth0.com/docs/quickstart/webapp/django) to better understand this sample. 6 | 7 | # Running the App 8 | 9 | To run the application: 10 | 11 | 1. Make sure you have `python3`, `pip` installed. 12 | 2. Rename `.env.example` to `.env` and populate it with the client ID, domain, secret. 13 | 3. Register `http://localhost:3000/callback` as `Allowed Callback URLs` and `http://localhost:3000` as `Allowed Logout URLs` in your app settings. 14 | 15 | Once you've set those variables: 16 | 17 | 1. Install the needed dependencies with `pip install -r requirements.txt` 18 | 2. Run `python3 manage.py migrate` to migrate the database schema 19 | 3. Run `python3 manage.py runserver 3000` to run the server. 20 | 21 | The app will be served at [http://localhost:3000/](http://localhost:3000/). 22 | 23 | # Running the App with Docker 24 | 25 | To run the sample with `docker`: 26 | 27 | 1. Rename the `.env.example` file to `.env`, change the environment variables, and register the URLs as explained [previously](#running-the-app). 28 | 2. Run `sh exec.sh` to build and run the docker image in Linux or run `.\exec.ps1` to build and run the docker image on Windows. 29 | 30 | The app will be served at [http://localhost:3000/](http://localhost:3000/). 31 | 32 | ## What is Auth0? 33 | 34 | Auth0 helps you to: 35 | 36 | * Add authentication with [multiple authentication sources](https://docs.auth0.com/identityproviders), either social like **Google, Facebook, Microsoft Account, LinkedIn, GitHub, Twitter, Box, Salesforce, among others**, or enterprise identity systems like **Windows Azure AD, Google Apps, Active Directory, ADFS or any SAML Identity Provider**. 37 | * Add authentication through more traditional 38 | **[username/password databases](https://docs.auth0.com/mysql-connection-tutorial)**. 39 | * Add support for **[linking different user accounts](https://docs.auth0.com/link-accounts)** with the same user. 40 | * Support for generating signed [JSON Web Tokens](https://docs.auth0.com/jwt) to call your APIs and 41 | **flow the user identity** securely. 42 | * Analytics of how, when and where users are logging in. 43 | * Pull data from other sources and add it to the user profile, through [JavaScript rules](https://docs.auth0.com/rules). 44 | 45 | ## Create a free account in Auth0 46 | 47 | 1. Go to [Auth0](https://auth0.com) and click Sign Up. 48 | 2. Use Google, GitHub or Microsoft Account to login. 49 | 50 | ## Issue Reporting 51 | 52 | If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The [Responsible Disclosure Program](https://auth0.com/whitehat) details the procedure for disclosing security issues. 53 | 54 | ## Author 55 | 56 | [Auth0](https://auth0.com) 57 | 58 | ## License 59 | 60 | This project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more info. 61 | -------------------------------------------------------------------------------- /01-Login/exec.ps1: -------------------------------------------------------------------------------- 1 | docker build -t auth0-django-01-login . 2 | docker run --env-file .env -p 3000:3000 -it auth0-django-01-login 3 | -------------------------------------------------------------------------------- /01-Login/exec.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | docker build -t auth0-django-01-login . 3 | docker run --env-file .env -p 3000:3000 -it auth0-django-01-login -------------------------------------------------------------------------------- /01-Login/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "webappexample.settings") 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError: 10 | # The above import may fail for some other reason. Ensure that the 11 | # issue is really that Django is missing to avoid masking other 12 | # exceptions on Python 2. 13 | try: 14 | import django 15 | except ImportError: 16 | raise ImportError( 17 | "Couldn't import Django. Are you sure it's installed and " 18 | "available on your PYTHONPATH environment variable? Did you " 19 | "forget to activate a virtual environment?" 20 | ) 21 | raise 22 | execute_from_command_line(sys.argv) 23 | -------------------------------------------------------------------------------- /01-Login/requirements.txt: -------------------------------------------------------------------------------- 1 | authlib ~= 1.2 2 | django ~= 4.2 3 | python-dotenv ~= 1.0 4 | requests ~= 2.31 5 | -------------------------------------------------------------------------------- /01-Login/webappexample/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/auth0-samples/auth0-django-web-app/4e26a9cc737df60c8eb03274c39617a81b7a0bf2/01-Login/webappexample/__init__.py -------------------------------------------------------------------------------- /01-Login/webappexample/settings.py: -------------------------------------------------------------------------------- 1 | import os 2 | from pathlib import Path 3 | from dotenv import load_dotenv, find_dotenv 4 | 5 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 6 | BASE_DIR = Path(__file__).resolve().parent.parent 7 | TEMPLATE_DIR = os.path.join(BASE_DIR, "webappexample", "templates") 8 | 9 | # Quick-start development settings - unsuitable for production 10 | # See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/ 11 | 12 | # SECURITY WARNING: keep the secret key used in production secret! 13 | SECRET_KEY = "auth0-webappexample-k0n4a#6cqu9=co$_bu^^sd@&^8#*%ukg3z4ku!lj&j)%^@cx8%" 14 | 15 | # SECURITY WARNING: don't run with debug turned on in production! 16 | DEBUG = True 17 | 18 | ALLOWED_HOSTS = [] 19 | 20 | # Application definition 21 | 22 | INSTALLED_APPS = [ 23 | "django.contrib.admin", 24 | "django.contrib.auth", 25 | "django.contrib.contenttypes", 26 | "django.contrib.sessions", 27 | "django.contrib.messages", 28 | ] 29 | 30 | MIDDLEWARE = [ 31 | "django.middleware.security.SecurityMiddleware", 32 | "django.contrib.sessions.middleware.SessionMiddleware", 33 | "django.middleware.common.CommonMiddleware", 34 | "django.middleware.csrf.CsrfViewMiddleware", 35 | "django.contrib.auth.middleware.AuthenticationMiddleware", 36 | "django.contrib.messages.middleware.MessageMiddleware", 37 | "django.middleware.clickjacking.XFrameOptionsMiddleware", 38 | ] 39 | 40 | ROOT_URLCONF = "webappexample.urls" 41 | 42 | TEMPLATES = [ 43 | { 44 | "BACKEND": "django.template.backends.django.DjangoTemplates", 45 | "DIRS": [TEMPLATE_DIR], 46 | "APP_DIRS": True, 47 | "OPTIONS": { 48 | "context_processors": [ 49 | "django.template.context_processors.debug", 50 | "django.template.context_processors.request", 51 | "django.contrib.auth.context_processors.auth", 52 | "django.contrib.messages.context_processors.messages", 53 | ], 54 | }, 55 | }, 56 | ] 57 | 58 | WSGI_APPLICATION = "webappexample.wsgi.application" 59 | 60 | 61 | # Database 62 | # https://docs.djangoproject.com/en/4.0/ref/settings/#databases 63 | 64 | DATABASES = { 65 | "default": { 66 | "ENGINE": "django.db.backends.sqlite3", 67 | "NAME": BASE_DIR / "db.sqlite3", 68 | } 69 | } 70 | 71 | 72 | # Password validation 73 | # https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators 74 | 75 | AUTH_PASSWORD_VALIDATORS = [ 76 | { 77 | "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", 78 | }, 79 | { 80 | "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", 81 | }, 82 | { 83 | "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", 84 | }, 85 | { 86 | "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", 87 | }, 88 | ] 89 | 90 | 91 | # Internationalization 92 | # https://docs.djangoproject.com/en/4.0/topics/i18n/ 93 | 94 | LANGUAGE_CODE = "en-us" 95 | TIME_ZONE = "UTC" 96 | USE_I18N = True 97 | USE_TZ = True 98 | DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" 99 | 100 | 101 | # Load environment definition file 102 | 103 | ENV_FILE = find_dotenv() 104 | if ENV_FILE: 105 | load_dotenv(ENV_FILE) 106 | 107 | 108 | # Load Auth0 application settings into memory 109 | 110 | AUTH0_DOMAIN = os.environ.get("AUTH0_DOMAIN") 111 | AUTH0_CLIENT_ID = os.environ.get("AUTH0_CLIENT_ID") 112 | AUTH0_CLIENT_SECRET = os.environ.get("AUTH0_CLIENT_SECRET") 113 | -------------------------------------------------------------------------------- /01-Login/webappexample/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 |{{pretty}}