Skip to main content

"Sign in with Google" for Pyramid

Project description

pyramid-googleauth

"Sign in with Google" for Pyramid. Provides a Pyramid security policy and views for Google's OAuth flow.

Usage

To use pyramid-googleauth with your Pyramid app:

1. Create a Google client ID and secret

  1. Register a Google OAuth client:

    1. Create a new Google Cloud Platform project.

      Go to https://console.cloud.google.com/projectcreate and create a new project, or use an existing Google Cloud Platform project.

    2. Configure the project's OAuth consent screen settings:

      1. Go to https://console.cloud.google.com/apis/credentials/consent and make sure the correct project is selected from the projects dropdown menu in the top left.

      2. Under User Type select Internal and then click CREATE.

        Note that Internal means that only users within the Google organization that contains the project will be able to log in. If you want anyone to be able to log in to your app with their Google account you have to select External.

      3. Fill out the app name, user support email and other fields and click SAVE AND CONTINUE.

      4. On the Scopes screen click ADD OR REMOVE SCOPES, select the ..auth/userinfo.email, ..auth/userinfo.profile and openid scopes, and click UPDATE and SAVE AND CONTINUE.

    3. Configure the project's Credentials settings:

      1. Go to https://console.cloud.google.com/apis/credentials and make sure the correct project is selected from the projects dropdown menu in the top left.

      2. Click CREATE CREDENTIALSOAuth client ID.

      3. Under Application type select Web application.

      4. Enter a Name.

      5. Under Authorized redirect URIs click ADD URI and enter https://<YOUR_DOMAIN>/googleauth/login/callback.

      6. Click CREATE.

      7. Note the Client ID and Client Secret that are created for you. You'll need to use these for the pyramid_googleauth.google_client_id and pyramid_googleauth.google_client_secret settings in your app.

2. Add pyramid-googleauth to your Pyramid app

  1. Add pyramid-googleauth to your app's Python requirements.

  2. Add pyramid-googleauth to your app's code:

    Your app needs to set a session factory, a security policy, and a handful of pyramid-googleauth settings, before doing config.include("pyramid-googleauth"). See the example app for a working example to copy from.

Hacking

Installing pyramid-googleauth in a development environment

You will need

  • Git

  • pyenv Follow the instructions in the pyenv README to install it. The Homebrew method works best on macOS. On Ubuntu follow the Basic GitHub Checkout method.

Clone the git repo

git clone https://github.com/hypothesis/pyramid-googleauth.git

This will download the code into a pyramid-googleauth directory in your current working directory. You need to be in the pyramid-googleauth directory for the rest of the installation process:

cd pyramid-googleauth

Run the test app

pyramid-googleauth comes with a demo Pyramid app that you can use to test the extension. To run the test app:

  1. Set the PYRAMID_GOOGLEAUTH_CLIENT_ID, PYRAMID_GOOGLEAUTH_CLIENT_SECRET and PYRAMID_GOOGLEAUTH_SECRET environment variables.

    Hypothesis developers can set these by just running make devdata:

    make devdata
    
    If you get a permissions error

    If you get a permissions error when running make devdata then you'll have to create your own values and set the environment variables yourself. Follow the instructions above to create a Google client ID and secret and use http://localhost:6547/googleauth/login/callback for the authorized redirect URI. Then set the environment variables to the client ID and secret that you created:

    export PYRAMID_GOOGLEAUTH_CLIENT_ID='765...2g6.apps.googleusercontent.com'
    export PYRAMID_GOOGLEAUTH_CLIENT_SECRET='Dfj...Y6i'
    

    You also need to set the PYRAMID_GOOGLEAUTH_SECRET environment variable for creating OAuth 2.0 state params. This can be set to any securely-generated random string:

    export PYRAMID_GOOGLEAUTH_SECRET='abc...123'
    

Run the tests

make test

That's it! You’ve finished setting up your pyramid-googleauth development environment. Run make help to see all the commands that're available for linting, code formatting, packaging, etc.

Updating the Cookiecutter scaffolding

This project was created from the https://github.com/hypothesis/h-cookiecutter-pypackage/ template. If h-cookiecutter-pypackage itself has changed since this project was created, and you want to update this project with the latest changes, you can "replay" the cookiecutter over this project. Run:

make template

This will change the files in your working tree, applying the latest updates from the h-cookiecutter-pypackage template. Inspect and test the changes, do any fixups that are needed, and then commit them to git and send a pull request.

If you want make template to skip certain files, never changing them, add these files to "options.disable_replay" in .cookiecutter.json and commit that to git.

If you want make template to update a file that's listed in disable_replay simply delete that file and then run make template, it'll recreate the file for you.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyramid_googleauth-1.0.0.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyramid_googleauth-1.0.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file pyramid_googleauth-1.0.0.tar.gz.

File metadata

  • Download URL: pyramid_googleauth-1.0.0.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for pyramid_googleauth-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b91d2422df475fa6934770d4d5bd111d77169ab5c3221fe9264c0ed783d08a17
MD5 c597428d01226af94bd42c5f4a6a361c
BLAKE2b-256 6b4ea29b9d222e6b85c874c213707dcb74b54695f4b8048c6a7e07fc1b53483f

See more details on using hashes here.

File details

Details for the file pyramid_googleauth-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pyramid_googleauth-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for pyramid_googleauth-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f96eca0464ddc08a9dafdd8b3b64b0ea29ca49911029e6958cc0bee5a169d517
MD5 e4094054d7b01d8354543168110f6724
BLAKE2b-256 59e64d8733383ee8cefe5e9d398474fe47855f23816e5d2a2fb4e8028ceb3a51

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page