Authentication¶
This example shows how to connect and authenticate using OAuth and Authentik.
In [4]:
Copied!
from authlib.integrations.requests_client import OAuth2Session
from os import environ as env
from dotenv import load_dotenv
load_dotenv()
from authlib.integrations.requests_client import OAuth2Session
from os import environ as env
from dotenv import load_dotenv
load_dotenv()
Out[4]:
True
In [5]:
Copied!
client = OAuth2Session(
client_id=env["AUTH_CLIENT_ID"],
client_secret=env["AUTH_CLIENT_SECRET"],
scope="openid profile email",
redirect_uri="http://localhost:8000/callback",
)
client = OAuth2Session(
client_id=env["AUTH_CLIENT_ID"],
client_secret=env["AUTH_CLIENT_SECRET"],
scope="openid profile email",
redirect_uri="http://localhost:8000/callback",
)
In [7]:
Copied!
client.create_authorization_url("http://localhost:8000/authorize")
client.create_authorization_url("http://localhost:8000/authorize")
Out[7]:
('http://localhost:8000/authorize?response_type=code&client_id=mHT1TQrrgW2nySGhVRj2mqZC2BYAVJgVY9hhsExq&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fcallback&scope=openid+profile+email&state=vCUYl6kI4RHUdODXybolekX19o0Lkg',
'vCUYl6kI4RHUdODXybolekX19o0Lkg')