Debian Codegraph @

src/globus_sdk/token_storage/token_data.py

raw
1 from __future__ import annotations
2
3 import typing as t
4
5 from globus_sdk._internal.guards import validators
6 from globus_sdk._internal.serializable import Serializable
7
8
9 class TokenStorageData(Serializable):
10 """
11 Data class for tokens and token metadata issued by a globus auth token grant.
12 For storage and retrieval of these objects, see :class:`TokenStorage`.
13
14 Tokens are scoped to a specific user/client (`identity_id`) performing
15 specific operations (`scope`) with a specific service (`resource_server`).
16
17 :ivar str resource_server: The resource server for which this token data was
18 granted.
19
20 :ivar str identity_id: The primary identity id of the user or client which
21 requested this token. This will be None if an identity id was not extractable
22 from the token grant response.
23
24 :ivar str scope: A space separated list of scopes that this token data provides
25 access to.
26
27 :ivar str access_token: A Globus Auth-issued OAuth2 access token. Used for
28 authentication when interacting with service APIs.
29
30 :ivar str | None refresh_token: A Globus Auth-issued OAuth2 refresh token. Used to
31 obtain new access tokens when the current one expires. This value will be None
32 if the original token grant did not request refresh tokens.
33
34 :ivar int expires_at_seconds: An epoch seconds timestamp for when the associated
35 access_token expires.
36
37 :ivar str | None token_type: The token type of access_token, currently this will
38 always be "Bearer" if present.
39
40 :param extra: An optional dictionary of additional fields to include. Included for
41 forward/backward compatibility.
42 """
43
44 def __init__(
45 self,
46 resource_server: str,
47 identity_id: str | None,
48 scope: str,
49 access_token: str,
50 refresh_token: str | None,
51 expires_at_seconds: int,
52 token_type: str | None,
53 extra: dict[str, t.Any] | None = None,
54 ) -> None:
55 self.resource_server = validators.str_("resource_server", resource_server)
56 self.identity_id = validators.opt_str("identity_id", identity_id)
57 self.scope = validators.str_("scope", scope)
58 self.access_token = validators.str_("access_token", access_token)
59 self.refresh_token = validators.opt_str("refresh_token", refresh_token)
60 self.expires_at_seconds = validators.int_(
61 "expires_at_seconds", expires_at_seconds
62 )
63 self.token_type = validators.opt_str("token_type", token_type)
64 self.extra = extra or {}