Skip to content

Commit

Permalink
Use code blocks for examples
Browse files Browse the repository at this point in the history
  • Loading branch information
frankie567 committed Jul 12, 2024
1 parent 0154b43 commit 9a84e3e
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 14 deletions.
4 changes: 3 additions & 1 deletion httpx_oauth/clients/facebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ async def get_long_lived_access_token(self, token: str) -> OAuth2Token:
the long-lived access token.
Examples:
>>> long_lived_access_token = await client.get_long_lived_access_token("TOKEN")
```py
long_lived_access_token = await client.get_long_lived_access_token("TOKEN")
```
"""
async with self.get_httpx_client() as client:
request, auth = self.build_request(
Expand Down
8 changes: 6 additions & 2 deletions httpx_oauth/clients/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ async def refresh_token(self, refresh_token: str):
RefreshTokenNotSupportedError: The provider does not support token refresh.
Examples:
>>> access_token = await client.refresh_token("REFRESH_TOKEN")
```py
access_token = await client.refresh_token("REFRESH_TOKEN")
```
"""
assert self.refresh_token_endpoint is not None
async with self.get_httpx_client() as client:
Expand Down Expand Up @@ -129,7 +131,9 @@ async def get_id_email(self, token: str) -> Tuple[str, Optional[str]]:
An error occurred while getting the id and email.
Examples:
>>> user_id, user_email = await client.get_id_email("TOKEN")
```py
user_id, user_email = await client.get_id_email("TOKEN")
```
"""
async with httpx.AsyncClient(
headers={**self.request_headers, "Authorization": f"token {token}"}
Expand Down
4 changes: 3 additions & 1 deletion httpx_oauth/clients/linkedin.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ async def refresh_token(self, refresh_token: str) -> OAuth2Token:
RefreshTokenNotSupportedError: The provider does not support token refresh.
Examples:
>>> access_token = await client.refresh_token("REFRESH_TOKEN")
```py
access_token = await client.refresh_token("REFRESH_TOKEN")
```
"""
return await super().refresh_token(refresh_token)

Expand Down
7 changes: 5 additions & 2 deletions httpx_oauth/clients/openid.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ def __init__(
An error occurred while fetching the OpenID configuration.
Examples:
>>> from httpx_oauth.clients.openid import OpenID
>>> client = OpenID("CLIENT_ID", "CLIENT_SECRET", "https://example.fief.dev/.well-known/openid-configuration")
```py
from httpx_oauth.clients.openid import OpenID
client = OpenID("CLIENT_ID", "CLIENT_SECRET", "https://example.fief.dev/.well-known/openid-configuration")
``
"""
with httpx.Client() as client:
try:
Expand Down
5 changes: 3 additions & 2 deletions httpx_oauth/clients/shopify.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ async def get_id_email(self, token: str) -> Tuple[str, Optional[str]]:
An error occurred while getting the id and email.
Examples:
>>> user_id, user_email = await client.get_id_email("TOKEN")
```py
user_id, user_email = await client.get_id_email("TOKEN")
```
"""
async with self.get_httpx_client() as client:
response = await client.get(
Expand Down
38 changes: 32 additions & 6 deletions httpx_oauth/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ class OAuth2Token(Dict[str, Any]):
you can get access token like this:
Examples:
>>> access_token = token["access_token"]
```py
access_token = token["access_token"]
```
"""

def __init__(self, token_dict: Dict[str, Any]):
Expand Down Expand Up @@ -239,9 +241,11 @@ async def get_authorization_url(
The authorization URL.
Examples:
>>> authorization_url = await client.get_authorization_url(
```py
authorization_url = await client.get_authorization_url(
"https://www.tintagel.bt/oauth-callback", scope=["SCOPE1", "SCOPE2", "SCOPE3"],
)
```py
"""
params = {
"response_type": "code",
Expand Down Expand Up @@ -288,7 +292,9 @@ async def get_access_token(
GetAccessTokenError: An error occurred while getting the access token.
Examples:
>>> access_token = await client.get_access_token("CODE", "https://www.tintagel.bt/oauth-callback")
```py
access_token = await client.get_access_token("CODE", "https://www.tintagel.bt/oauth-callback")
```
"""
async with self.get_httpx_client() as client:
data = {
Expand Down Expand Up @@ -328,7 +334,9 @@ async def refresh_token(self, refresh_token: str) -> OAuth2Token:
RefreshTokenNotSupportedError: The provider does not support token refresh.
Examples:
>>> access_token = await client.refresh_token("REFRESH_TOKEN")
```py
access_token = await client.refresh_token("REFRESH_TOKEN")
```
"""
if self.refresh_token_endpoint is None:
raise RefreshTokenNotSupportedError()
Expand Down Expand Up @@ -408,7 +416,9 @@ async def get_id_email(self, token: str) -> Tuple[str, Optional[str]]:
An error occurred while getting the id and email.
Examples:
>>> user_id, user_email = await client.get_id_email("TOKEN")
```py
user_id, user_email = await client.get_id_email("TOKEN")
```
"""
raise NotImplementedError()

Expand Down Expand Up @@ -479,7 +489,23 @@ def get_json(


OAuth2 = BaseOAuth2[Dict[str, Any]]
"""Generic OAuth2 client."""
"""
Generic OAuth2 client.
Examples:
```py
from httpx_oauth.oauth2 import OAuth2
client = OAuth2(
"CLIENT_ID",
"CLIENT_SECRET",
"AUTHORIZE_ENDPOINT",
"ACCESS_TOKEN_ENDPOINT",
refresh_token_endpoint="REFRESH_TOKEN_ENDPOINT",
revoke_token_endpoint="REVOKE_TOKEN_ENDPOINT",
)
```
"""

__all__ = [
"BaseOAuth2",
Expand Down
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ theme:
toggle:
icon: material/brightness-4
name: Switch to light mode
features:
- content.code.copy

extra_css:
- assets/stylesheets/extra.css
Expand Down

0 comments on commit 9a84e3e

Please sign in to comment.