-
-
Notifications
You must be signed in to change notification settings - Fork 48
feat: add apps management page and device authorization flow #146
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
Open
Zingzy
wants to merge
3
commits into
main
Choose a base branch
from
feat/linked-apps
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| # App registry for the spoo.me ecosystem. | ||
| # | ||
| # Loaded at application startup and cached in app.state.app_registry. | ||
| # All apps listed here appear on the dashboard Apps page. | ||
| # Only 'live' + 'device_auth' apps can initiate the consent flow. | ||
|
|
||
| apps: | ||
| spoo-snap: | ||
| name: Spoo Snap | ||
| icon: spoo-snap.svg | ||
| description: Official browser extension for spoo.me | ||
| verified: true | ||
| status: live | ||
| type: device_auth | ||
| redirect_uris: [] | ||
| links: | ||
| chrome: https://chrome.google.com/webstore/detail/spoo-snap | ||
| firefox: https://addons.mozilla.org/en-US/firefox/addon/spoo-snap | ||
| permissions: | ||
| - Access your spoo.me account | ||
| - Create and manage short URLs | ||
| - View your analytics | ||
|
|
||
| spoo-desktop: | ||
| name: Spoo Desktop | ||
| icon: spoo-desktop.svg | ||
| description: Official Windows desktop app | ||
| verified: true | ||
| status: live | ||
| type: device_auth | ||
| redirect_uris: | ||
| - http://localhost:9274/callback | ||
| links: | ||
| windows: https://apps.microsoft.com/detail/9mtwpjxlb0gr | ||
| permissions: | ||
| - Access your spoo.me account | ||
| - Create and manage short URLs | ||
|
|
||
| spoo-discord: | ||
| name: Discord Bot | ||
| icon: discord-bot.svg | ||
| description: Shorten links directly in Discord | ||
| verified: true | ||
| status: live | ||
| type: device_auth | ||
| redirect_uris: | ||
| - https://discord-bot.spoo.me/callback | ||
| links: | ||
| invite: https://spoo.me/discord-bot | ||
| permissions: | ||
| - Access your spoo.me account | ||
| - Create short URLs on your behalf | ||
|
|
||
| spoo-mobile: | ||
| name: Spoo Mobile | ||
| icon: spoo-mobile.svg | ||
| description: Shorten links on the go | ||
| verified: true | ||
| status: coming_soon | ||
| type: device_auth | ||
|
|
||
| spoo-telegram: | ||
| name: Telegram Bot | ||
| icon: telegram-bot.svg | ||
| description: Shorten links in Telegram chats | ||
| verified: true | ||
| status: coming_soon | ||
| type: device_auth | ||
|
|
||
| spoo-slack: | ||
| name: Slack Bot | ||
| icon: slack-bot.svg | ||
| description: Shorten links in Slack with /shorten | ||
| verified: true | ||
| status: coming_soon | ||
| type: device_auth | ||
|
|
||
| spoo-raycast: | ||
| name: Raycast Extension | ||
| icon: raycast.svg | ||
| description: Shorten links from Raycast | ||
| verified: true | ||
| status: coming_soon | ||
| type: device_auth | ||
|
|
||
| spoo-vscode: | ||
| name: VS Code Extension | ||
| icon: vscode.svg | ||
| description: Shorten links from your editor | ||
| verified: true | ||
| status: coming_soon | ||
| type: device_auth | ||
|
|
||
| spoo-mcp: | ||
| name: MCP Server | ||
| icon: mcp.svg | ||
| description: AI tool server for Claude, Cursor, and others | ||
| verified: true | ||
| status: coming_soon | ||
| type: device_auth | ||
|
|
||
| spoo-zapier: | ||
| name: Zapier | ||
| icon: zapier.svg | ||
| description: Shorten links in no-code workflows | ||
| verified: true | ||
| status: coming_soon | ||
| type: device_auth | ||
|
|
||
| spoo-n8n: | ||
| name: n8n | ||
| icon: n8n.svg | ||
| description: Self-hosted automation for link shortening | ||
| verified: true | ||
| status: coming_soon | ||
| type: device_auth | ||
|
|
||
| spoo-cli: | ||
| name: Spoo CLI | ||
| icon: spoo-cli.svg | ||
| description: Shorten links from your terminal | ||
| verified: true | ||
| status: coming_soon | ||
| type: device_auth |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| """ | ||
| Repository for the `app-grants` MongoDB collection. | ||
|
|
||
| Tracks user consent grants for registered apps (device auth flow). | ||
| Supports soft-delete via revoked_at for analytics and reconnect flows. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from datetime import datetime, timezone | ||
|
|
||
| from bson import ObjectId | ||
| from pymongo.asynchronous.collection import AsyncCollection | ||
| from pymongo.errors import PyMongoError | ||
|
|
||
| from schemas.models.app_grant import AppGrantDoc | ||
| from shared.logging import get_logger | ||
|
|
||
| log = get_logger(__name__) | ||
|
|
||
|
|
||
| class AppGrantRepository: | ||
| def __init__(self, collection: AsyncCollection) -> None: | ||
| self._col = collection | ||
|
|
||
| async def find_active_grant( | ||
| self, user_id: ObjectId, app_id: str | ||
| ) -> AppGrantDoc | None: | ||
| """Find an active (non-revoked) grant for a user and app.""" | ||
| try: | ||
| doc = await self._col.find_one( | ||
| {"user_id": user_id, "app_id": app_id, "revoked_at": None} | ||
| ) | ||
| return AppGrantDoc.from_mongo(doc) | ||
| except PyMongoError as exc: | ||
| log.error( | ||
| "app_grant_find_active_failed", | ||
| user_id=str(user_id), | ||
| app_id=app_id, | ||
| error=str(exc), | ||
| error_type=type(exc).__name__, | ||
| ) | ||
| raise | ||
|
|
||
| async def find_active_for_user(self, user_id: ObjectId) -> list[AppGrantDoc]: | ||
| """Find all active grants for a user.""" | ||
| try: | ||
| cursor = self._col.find({"user_id": user_id, "revoked_at": None}) | ||
| return [AppGrantDoc.from_mongo(doc) async for doc in cursor] | ||
| except PyMongoError as exc: | ||
| log.error( | ||
| "app_grant_find_active_for_user_failed", | ||
| user_id=str(user_id), | ||
| error=str(exc), | ||
| error_type=type(exc).__name__, | ||
| ) | ||
| raise | ||
|
|
||
| async def find_all_for_user(self, user_id: ObjectId) -> list[AppGrantDoc]: | ||
| """Find all grants for a user, including revoked.""" | ||
| try: | ||
| cursor = self._col.find({"user_id": user_id}) | ||
| return [AppGrantDoc.from_mongo(doc) async for doc in cursor] | ||
| except PyMongoError as exc: | ||
| log.error( | ||
| "app_grant_find_all_for_user_failed", | ||
| user_id=str(user_id), | ||
| error=str(exc), | ||
| error_type=type(exc).__name__, | ||
| ) | ||
| raise | ||
|
|
||
| async def create_or_reactivate(self, user_id: ObjectId, app_id: str) -> AppGrantDoc: | ||
| """Create a new grant or reactivate a revoked one. | ||
|
|
||
| Uses upsert: if a document exists for (user_id, app_id), clears | ||
| revoked_at and updates granted_at. Otherwise inserts a new document. | ||
| """ | ||
| now = datetime.now(timezone.utc) | ||
| try: | ||
| doc = await self._col.find_one_and_update( | ||
| {"user_id": user_id, "app_id": app_id}, | ||
| { | ||
| "$set": { | ||
| "granted_at": now, | ||
| "revoked_at": None, | ||
| }, | ||
| "$setOnInsert": { | ||
| "user_id": user_id, | ||
| "app_id": app_id, | ||
| "last_used_at": None, | ||
| }, | ||
| }, | ||
| upsert=True, | ||
| return_document=True, | ||
| ) | ||
| return AppGrantDoc.from_mongo(doc) # type: ignore[return-value] | ||
Zingzy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| except PyMongoError as exc: | ||
| log.error( | ||
| "app_grant_create_or_reactivate_failed", | ||
| user_id=str(user_id), | ||
| app_id=app_id, | ||
| error=str(exc), | ||
| error_type=type(exc).__name__, | ||
| ) | ||
| raise | ||
|
|
||
| async def revoke(self, user_id: ObjectId, app_id: str) -> bool: | ||
| """Soft-delete a grant by setting revoked_at. Returns True if a grant was revoked.""" | ||
| try: | ||
| result = await self._col.update_one( | ||
| {"user_id": user_id, "app_id": app_id, "revoked_at": None}, | ||
| {"$set": {"revoked_at": datetime.now(timezone.utc)}}, | ||
| ) | ||
| return result.modified_count > 0 | ||
| except PyMongoError as exc: | ||
| log.error( | ||
| "app_grant_revoke_failed", | ||
| user_id=str(user_id), | ||
| app_id=app_id, | ||
| error=str(exc), | ||
| error_type=type(exc).__name__, | ||
| ) | ||
| raise | ||
|
|
||
| async def touch_last_used(self, user_id: ObjectId, app_id: str) -> None: | ||
| """Update last_used_at on an active grant.""" | ||
| try: | ||
| await self._col.update_one( | ||
| {"user_id": user_id, "app_id": app_id, "revoked_at": None}, | ||
| {"$set": {"last_used_at": datetime.now(timezone.utc)}}, | ||
| ) | ||
| except PyMongoError as exc: | ||
| log.error( | ||
| "app_grant_touch_last_used_failed", | ||
| user_id=str(user_id), | ||
| app_id=app_id, | ||
| error=str(exc), | ||
| error_type=type(exc).__name__, | ||
| ) | ||
| raise | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.