Coverage for polar/oauth2/userinfo.py: 16%
23 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 16:17 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 16:17 +0000
1import typing 1a
3from authlib.oidc.core import UserInfo 1a
5from polar.auth.scope import Scope, scope_to_list 1a
7from .sub_type import SubTypeValue, is_sub_organization, is_sub_user 1a
10def generate_user_info(sub: SubTypeValue, scope: str) -> UserInfo: 1a
11 _, sub_object = sub
12 claims: dict[str, typing.Any] = {"sub": str(sub_object.id)}
13 scopes = scope_to_list(scope)
15 if is_sub_user(sub):
16 _, user = sub
17 if scopes:
18 if Scope.openid in scopes:
19 pass
20 if Scope.email in scopes:
21 claims.update(
22 {"email": user.email, "email_verified": user.email_verified}
23 )
24 elif is_sub_organization(sub):
25 _, organization = sub
26 if scopes:
27 if Scope.openid in scopes:
28 claims.update({"name": organization.slug})
29 else:
30 raise NotImplementedError()
32 return UserInfo(**claims)
35__all__ = ["generate_user_info", "UserInfo"] 1a