Skip to content

Commit 6cc5b61

Browse files
committed
Showcase the usage of claims config
1 parent 86ff69f commit 6cc5b61

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

examples/demonstration/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from dotenv import load_dotenv
44
from social_core.backends.github import GithubOAuth2
55

6+
from fastapi_oauth2.claims import Claims
67
from fastapi_oauth2.client import OAuth2Client
78
from fastapi_oauth2.config import OAuth2Config
89

@@ -20,6 +21,10 @@
2021
client_secret=os.getenv("OAUTH2_CLIENT_SECRET"),
2122
# redirect_uri="http://127.0.0.1:8000/",
2223
scope=["user:email"],
24+
claims=Claims(
25+
picture="avatar_url",
26+
identity=lambda user: "%s:%s" % (user.get("provider"), user.get("id")),
27+
),
2328
),
2429
]
2530
)

examples/demonstration/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async def on_auth(user: User):
2222
# the database and create if not exists
2323
db: Session = next(get_db())
2424
query = db.query(UserModel)
25-
if not query.filter_by(identity=user.identity).first():
25+
if user.identity and not query.filter_by(identity=user.identity).first():
2626
UserModel(**{
2727
"identity": user.get("identity"),
2828
"username": user.get("username"),

0 commit comments

Comments
 (0)