Giter Site home page Giter Site logo

sample-adh-authentication_authorization-python's Introduction

Authorization Code Flow + PKCE Python Sample and Test

Version: 1.0.21

Build Status

This sample uses the OAuth2/OIDC Authorization Code Flow + PKCE to obtain an access token. See the main ADH Authentication samples page README for more information about this flow.

Developed against Python 3.9.1

Python SDS Library

The Python SDS library, ocs_sample_library_preview, implements this flow inside its ADHClient type using the same Python code used in this sample. This sample is preserved separately to demonstrate that code in an isolated environment, and also to allow injection of a Selenium script for automated testing.

To use the Authorization Code Flow + PKCE flow with the library, pass a client ID for an ADH Authorization Code client, without a client secret, to the constructor. The libary will use this OIDC flow if no secret is passed to the constructor.

Requirements

  • Python 3
  • Web Browser with Javascript enabled
    • Google Chrome Web Driver is required for the automated test
  • Register an Authorization Code Client in AVEVA Data Hub and ensure that the registered client in ADH contains http://localhost:5004/callback.html in the list of RedirectUris
  • Configure the sample using the file appsettings.placeholder.json. Before editing, rename this file to appsettings.json. This repository's .gitignore rules should prevent the file from ever being checked in to any fork or branch, to ensure credentials are not compromised.
  • Replace the placeholders in appsettings.json with your Tenant ID and Client ID. The username and password fields are used for testing and can be left as is.

Running the Sample

  1. Open a command prompt in this folder
  2. Install requirements, using pip install -r requirements.txt
  3. Set up the Configuration section of the appsettings.json file, as described above
  4. Run the sample using python ./program.py
  5. Follow prompts in the browser to log in, if you are already logged in this step will be skipped
  6. When prompted by the browser, return to the command prompt and a token will be logged

Running the Automated Test

  1. Open a command prompt in this folder
  2. Install pytest, using pip install pytest
  3. Install selenium, using pip install selenium
  4. Set up the Configuration section of the appsettings.json file, as described above, if you have not already
  5. Set up the Test section of the appsettings.json file with a username and password for the test to use to log in
  6. Run the test, using python -m pytest ./test.py
  7. Chrome should run in the background and log in, and the test will assert that a token is obtained

For the main ADH Authentication samples page ReadMe
For the main ADH samples page ReadMe
For the main AVEVA samples page ReadMe

sample-adh-authentication_authorization-python's People

Contributors

anton-dahlin avatar cbardini avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.