Skip to content

Commit 6d60c55

Browse files
committed
GH-9: Describe claims and add a usage example
1 parent ca1cc3c commit 6d60c55

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ middleware configuration is declared with the `OAuth2Config` and `OAuth2Client`
4242
- `client_secret` - The OAuth2 client secret for the particular provider.
4343
- `redirect_uri` - The OAuth2 redirect URI to redirect to after success. Defaults to the base URL.
4444
- `scope` - The OAuth2 scope for the particular provider. Defaults to `[]`.
45+
- `claims` - Claims mapping for the certain provider.
4546

4647
It is also important to mention that for the configured clients of the auth providers, the authorization URLs are
4748
accessible by the `/oauth2/{provider}/auth` path where the `provider` variable represents the exact value of the auth
4849
provider backend `name` attribute.
4950

5051
```python
52+
from fastapi_oauth2.claims import Claims
5153
from fastapi_oauth2.client import OAuth2Client
5254
from fastapi_oauth2.config import OAuth2Config
5355
from social_core.backends.github import GithubOAuth2
@@ -64,6 +66,10 @@ oauth2_config = OAuth2Config(
6466
client_secret=os.getenv("OAUTH2_CLIENT_SECRET"),
6567
redirect_uri="https://pysnippet.org/",
6668
scope=["user:email"],
69+
claims=Claims(
70+
picture="avatar_url",
71+
identity=lambda user: "%s:%s" % (user.get("provider"), user.get("id")),
72+
),
6773
),
6874
]
6975
)

0 commit comments

Comments
 (0)