arcade-mcp/arcade/arcade/sdk/auth.py
Nate Barbettini f4fe8c7892
Clean up provider properties (scopes) (#42)
In this PR:
- Rename `scope` to `scopes` so it is more understandable by humans
- DRY up provider structs, it was starting to get silly with so many
providers that just have 1 property called `scopes`

Must go along with this Engine PR:
https://github.com/ArcadeAI/Engine/pull/79
2024-09-17 16:38:51 -07:00

53 lines
1.2 KiB
Python

from abc import ABC, abstractmethod
from typing import Optional
from pydantic import AnyUrl, BaseModel
class ToolAuthorization(BaseModel, ABC):
"""Marks a tool as requiring authorization."""
@abstractmethod
def get_provider(self) -> str:
"""Return the name of the authorization method."""
pass
pass
class BaseOAuth2(ToolAuthorization):
"""Base class for any provider supporting OAuth 2.0-like authorization."""
authority: Optional[AnyUrl] = None
"""The URL of the OAuth 2.0 authorization server."""
scopes: Optional[list[str]] = None
"""The scope(s) needed for the authorized action."""
class OAuth2(BaseOAuth2):
"""Marks a tool as requiring OAuth 2.0 authorization."""
def get_provider(self) -> str:
return "oauth2"
class Google(BaseOAuth2):
"""Marks a tool as requiring Google authorization."""
def get_provider(self) -> str:
return "google"
class SlackUser(BaseOAuth2):
"""Marks a tool as requiring Slack (user token) authorization."""
def get_provider(self) -> str:
return "slack_user"
class GitHubApp(ToolAuthorization):
"""Marks a tool as requiring GitHub App authorization."""
def get_provider(self) -> str:
return "github_app"