Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions statgpt/common/auth/authorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class SystemUserAuthorizeConfig(AuthorizeConfig):


class DialUserAuthorizerI(AuthorizerI[DialUserAuthorizerConfig]):
@property
def requires_dial_token(self) -> bool:
return True

async def authorize(self, config: DialUserAuthorizerConfig) -> TokenResponseI:
raise NotImplementedError()

Expand Down Expand Up @@ -80,6 +84,10 @@ class SystemUserViaAuthorizer(DialUserAuthorizerI):
def __init__(self, authorizer: SystemUserAuthorizerI):
self._authorizer = authorizer

@property
def requires_dial_token(self) -> bool:
return False

async def authorize(self, config: DialUserAuthorizerConfig) -> TokenResponseI:
return await self._authorizer.authorize(SystemUserAuthorizeConfig())

Expand Down
4 changes: 2 additions & 2 deletions statgpt/common/data/quanthub/v21/authorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ async def _authorize(self) -> str:
return system_user_token.access_token
else:
dial_token = self._auth_context.dial_access_token
if not dial_token:
if not dial_token and self._dial_user_authorizer.requires_dial_token:
raise AuthorizationError(
'AuthorizationError', 'DIAL access token is required for user authorization'
)

try:
config = DialUserAuthorizerConfig(dial_token=dial_token)
config = DialUserAuthorizerConfig(dial_token=dial_token or "")
token = await self._dial_user_authorizer.authorize(config)
return token.access_token
except AuthorizationError as e:
Expand Down
Loading