Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add basic embedded app #200

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions spylib/oauth/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,27 @@
from spylib.exceptions import FastAPIImportError

try:
from fastapi import APIRouter, Depends, HTTPException, Query # type: ignore
from fastapi import ( # type: ignore
APIRouter,
Depends,
HTTPException,
Query,
Request,
Response,
)
except ImportError as e:
raise FastAPIImportError(
'The oauth router is a fastapi router and fastapi is not installed. '
'Run `pip install spylib[fastapi]` to be able to use the oauth router.'
) from e

from starlette.requests import Request
from starlette.responses import RedirectResponse

from ..utils import store_domain
from .callback import process_callback
from .models import OfflineTokenModel, OnlineTokenModel
from .redirects import app_redirect, oauth_init_url
from .validations import validate_hmac


@dataclass
Expand All @@ -41,6 +48,7 @@ def init_oauth_router(
install_init_path='/shopify/auth',
callback_path='/callback',
path_prefix: str = '',
initial_path: Optional[str] = '/'
) -> APIRouter:
router = APIRouter()

Expand Down Expand Up @@ -120,4 +128,15 @@ async def shopify_callback(request: Request, shop: str, args: Callback = Depends
)
)

if initial_path:
@router.get(initial_path, include_in_schema=False)
async def default_root(
request: Request,
hmac: str,
session: str = None,
):
validate_hmac(request=request, hmac=hmac)
if session:
return Response('App Installed')

return router