Last updated

Sample Python Web Application

This sample code demonstrates how to obtain an Access token using the SLB Authenticator service for a Confidential client using an Authorization Code Flow (ACF) grant using Python Flask.

NOTE : For demonstration, this sample retrieves the access token when you click on "Get Access Token" button.

Code sample

PythonCCGSample.zip

Pre-requisites

Installation

  1. Unzip the sample code: PythonCCGSample.zip

  2. Open the root directory (containing app.py) of the unzipped sample code, in Visual Studio Code editor. If you are new to running the Python code using Visual Studio Code editor, refer quick start guide.

  3. We recommend that you create a virtual environment to work with the code samples.

    • Refer to Creation of virtual environments in VS Code for more details. This sample is tested for using "Venv" environment type.

    • Make sure above created environment in activated in VS Code. The selected interpreter version will show on the right side of the status bar of Visual Studio Code editor, as shown below (python version might be different depending on your python installation). If not, refer to select and activate an environment for details. status bar

    • Make sure that your pip package installer is up-to-date:

        python -m pip install --upgrade pip
    • Install the requirements.txt file:
        pip install -r requirements.txt
  4. Open app.py file and make the following changes:

    a. On line 8, set CLIENT_ID = "[YOUR CLIENT ID]"

    b. On line 9, set CLIENT_SECRET = "[YOUR CLIENT SECRET]"

    Note:

  5. Save the changes into app.py file.

  6. Run application using the following command in Python terminal of VS Code

        python -m flask run 
  7. In your web browser, go to http://127.0.0.1:{port}. Replace {port} value with actual port value on which Flask application will run. The default port for the Flask application is 5000.

  8. Click on "Get Access Token" button on home page welcome page

  9. Server side python code will use client id and client secret and will show the access token on web page. access token