# Sample Python Web Application

This sample code demonstrates how to obtain an [Access token](/guides/cloud-apis/create-first-app/concepts#access-token) using the SLB Authenticator service for a  [Confidential client](/guides/cloud-apis/create-first-app/concepts#confidential-client) using an [Authorization Code Flow (ACF)](https://oauth.net/2/grant-types/authorization-code/) grant using Python [Flask](https://flask.palletsprojects.com/en/2.2.x/).

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

## Code sample

[PythonCCGSample.zip](/assets/getting_started_pythonccgsample.fd10c3777c5292f465476ebe7018b77e30aa3557397ad882ae547ad5df83f878.ebe4f9c4.zip)

## Pre-requisites

* Access to [SLB Developer Portal](https://developer.delfi.slb.com/)
* You need to be a member of a team on SLB Developer.
* [Python 3.x](https://www.python.org/) is required.
* [VS Code](https://code.visualstudio.com/) and [Python Extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python) for VS Code.


## 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](https://code.visualstudio.com/docs/python/python-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](https://code.visualstudio.com/docs/python/environments#_using-the-create-environment-command) 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](https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment) for details.
![status bar](/assets/environment-in-status-bar.e22ff963cc8c9e5d44d16912c0196641acb77846a44e1f7c6c8f77cbcc503d58.ab5388e2.jpeg)
  - 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:
  - Refer [creation of client](/guides/cloud-apis/developer-portal/create-clients#create-clients-for-service-accounts) for using as service account for details.
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](/assets/ccg-welcomepage.9111b26aaf020791b6ade768eedd4fa84e2059684da8e3cd0a0c784e93ad62bd.ab5388e2.jpeg)
9. Server side python code will use client id and client secret and will show the access token on web page.
![access token](/assets/ccgtoken.26357194557a133c66c0dbbc28431dd81e15f39a581ad217a8c00c520a5c239b.ab5388e2.jpeg)


## Recommended further Reading

- [User context](/solutions/ccm/tutorial/user-context-service) in SLB Digital platform
- [Secret management](/solutions/sauth/tutorial/secret-management-service) on SLB Digital platform
- [API Maturity](/guides/cloud-apis/references/api-lifecycle) of cloud APIs
- Refer tutorial of various solutions (e.g. [FDPlan](/solutions/fdplan/tutorial/about), [DrillPlan](/solutions/drillplan/docs/tutorials/tutorial), [MPDF](/solutions/core-service/tutorial/osdu-core-services-about) etc.) to learn more about their extensibility and how to integrate with APIs offered by these solutions into your application.