File: orgs_token_manager.py

package info (click to toggle)
python-twilio 9.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,756 kB
  • sloc: python: 8,281; makefile: 65
file content (41 lines) | stat: -rw-r--r-- 1,157 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from twilio.http.token_manager import TokenManager
from twilio.rest import Client


class OrgTokenManager(TokenManager):
    """
    Orgs Token Manager
    """

    def __init__(
        self,
        grant_type: str,
        client_id: str,
        client_secret: str,
        code: str = None,
        redirect_uri: str = None,
        audience: str = None,
        refreshToken: str = None,
        scope: str = None,
    ):
        self.grant_type = grant_type
        self.client_id = client_id
        self.client_secret = client_secret
        self.code = code
        self.redirect_uri = redirect_uri
        self.audience = audience
        self.refreshToken = refreshToken
        self.scope = scope
        self.client = Client()

    def fetch_access_token(self):
        token_instance = self.client.preview_iam.v1.token.create(
            grant_type=self.grant_type,
            client_id=self.client_id,
            client_secret=self.client_secret,
            code=self.code,
            redirect_uri=self.redirect_uri,
            audience=self.audience,
            scope=self.scope,
        )
        return token_instance.access_token