Skip to content

Commit 346613a

Browse files
organization_access_token: Add _sandbox to tokens when in sandbox env
Does the same for personal access tokens, but those are deprecated and thus no longer being created (but are potentially still in use by customers).
1 parent eb3b42d commit 346613a

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

server/polar/organization_access_token/service.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
log: Logger = structlog.get_logger()
3333

3434
TOKEN_PREFIX = "polar_oat_"
35+
TOKEN_PREFIX_SANDBOX = "polar_sandbox_oat_"
3536

3637

3738
class OrganizationAccessTokenService:
@@ -105,8 +106,14 @@ async def create(
105106
organization = await get_payload_organization(
106107
session, auth_subject, create_schema
107108
)
109+
110+
if settings.is_sandbox():
111+
token_prefix = TOKEN_PREFIX_SANDBOX
112+
else:
113+
token_prefix = TOKEN_PREFIX
114+
108115
token, token_hash = generate_token_hash_pair(
109-
secret=settings.SECRET, prefix=TOKEN_PREFIX
116+
secret=settings.SECRET, prefix=token_prefix
110117
)
111118
organization_access_token = OrganizationAccessToken(
112119
**create_schema.model_dump(

server/polar/personal_access_token/service.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@
1818

1919
log: Logger = structlog.get_logger()
2020

21-
TOKEN_PREFIX = "polar_pat_"
21+
# We no longer allow the creation of Personal Access Tokens (PATs), so the
22+
# below prefix is now unused in active code. However, customers may still
23+
# actively be using PATs for API authentication and we continue to support
24+
# that.
25+
# The prefix is listed here for later reference.
26+
#
27+
# TOKEN_PREFIX = "polar_pat_"
2228

2329

2430
class PersonalAccessTokenService(ResourceServiceReader[PersonalAccessToken]):

0 commit comments

Comments
 (0)