Skip to content

auth

AccessType = Literal['online', 'offline'] module-attribute

Literal for the access type of the authentication URL.

Provider = Literal['google', 'imap', 'microsoft', 'virtual-calendar'] module-attribute

Literal for the different authentication providers.

CodeExchangeRequest

Bases: TypedDict

Interface of a Nylas code exchange request

Attributes:

Name Type Description
redirect_uri str

Should match the same redirect URI that was used for getting the code during the initial authorization request.

code str

OAuth 2.0 code fetched from the previous step.

client_id str

Client ID of the application.

client_secret str

Client secret of the application.

code_verifier NotRequired[str]

The original plain text code verifier (code_challenge) used in the initial authorization request (PKCE).

Source code in nylas/models/auth.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class CodeExchangeRequest(TypedDict):
    """
    Interface of a Nylas code exchange request

    Attributes:
        redirect_uri: Should match the same redirect URI that was used for getting the code during the initial authorization request.
        code: OAuth 2.0 code fetched from the previous step.
        client_id: Client ID of the application.
        client_secret: Client secret of the application.
        code_verifier: The original plain text code verifier (code_challenge) used in the initial authorization request (PKCE).
    """

    redirect_uri: str
    code: str
    client_id: str
    client_secret: str
    code_verifier: NotRequired[str]

CodeExchangeResponse dataclass

Class representation of a Nylas code exchange response.

Attributes:

Name Type Description
access_token str

Supports exchanging the Nylas code for an access token, or refreshing an access token.

grant_id str

ID representing the new Grant.

scope str

List of scopes associated with the token.

expires_in int

The remaining lifetime of the access token, in seconds.

refresh_token Optional[str]

Returned only if the code is requested using "access_type=offline".

id_token Optional[str]

A JWT that contains identity information about the user. Digitally signed by Nylas.

token_type Optional[str]

Always "Bearer".

Source code in nylas/models/auth.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
@dataclass_json
@dataclass
class CodeExchangeResponse:
    """
    Class representation of a Nylas code exchange response.

    Attributes:
        access_token: Supports exchanging the Nylas code for an access token, or refreshing an access token.
        grant_id: ID representing the new Grant.
        scope: List of scopes associated with the token.
        expires_in: The remaining lifetime of the access token, in seconds.
        refresh_token: Returned only if the code is requested using "access_type=offline".
        id_token: A JWT that contains identity information about the user. Digitally signed by Nylas.
        token_type: Always "Bearer".
    """

    access_token: str
    grant_id: str
    email: str
    scope: str
    expires_in: int
    refresh_token: Optional[str] = None
    id_token: Optional[str] = None
    token_type: Optional[str] = None

PkceAuthUrl dataclass

Class representing the object containing the OAuth 2.0 URL and the hashed secret.

Attributes:

Name Type Description
secret str

Server-side challenge used in the OAuth 2.0 flow.

secret_hash str

SHA-256 hash of the secret.

url str

The URL for hosted authentication.

Source code in nylas/models/auth.py
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
@dataclass_json
@dataclass
class PkceAuthUrl:
    """
    Class representing the object containing the OAuth 2.0 URL and the hashed secret.

    Attributes:
        secret: Server-side challenge used in the OAuth 2.0 flow.
        secret_hash: SHA-256 hash of the secret.
        url: The URL for hosted authentication.
    """

    secret: str
    secret_hash: str
    url: str

ProviderDetectParams

Bases: TypedDict

Interface representing the object used to set parameters for detecting a provider.

Attributes:

Name Type Description
email str

Email address to detect the provider for.

client_id str

Client ID of the Nylas application.

all_provider_types NotRequired[bool]

Search by all providers regardless of created integrations. If unset, defaults to false.

Source code in nylas/models/auth.py
158
159
160
161
162
163
164
165
166
167
168
169
170
class ProviderDetectParams(TypedDict):
    """
    Interface representing the object used to set parameters for detecting a provider.

    Attributes:
        email: Email address to detect the provider for.
        client_id: Client ID of the Nylas application.
        all_provider_types: Search by all providers regardless of created integrations. If unset, defaults to false.
    """

    email: str
    client_id: str
    all_provider_types: NotRequired[bool]

ProviderDetectResponse dataclass

Interface representing the Nylas provider detect response.

Attributes:

Name Type Description
email_address str

Email provided for autodetection

detected bool

Whether the provider was detected

provider Optional[str]

Detected provider

type Optional[str]

Provider type (if IMAP provider detected displays the IMAP provider)

Source code in nylas/models/auth.py
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
@dataclass_json
@dataclass
class ProviderDetectResponse:
    """
    Interface representing the Nylas provider detect response.

    Attributes:
        email_address: Email provided for autodetection
        detected: Whether the provider was detected
        provider: Detected provider
        type: Provider type (if IMAP provider detected displays the IMAP provider)
    """

    email_address: str
    detected: bool
    provider: Optional[str] = None
    type: Optional[str] = None

TokenExchangeRequest

Bases: TypedDict

Interface of a Nylas token exchange request

Attributes:

Name Type Description
redirect_uri str

Should match the same redirect URI that was used for getting the code during the initial authorization request.

refresh_token str

Token to refresh/request your short-lived access token

client_id str

Client ID of the application.

client_secret str

Client secret of the application.

Source code in nylas/models/auth.py
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
class TokenExchangeRequest(TypedDict):
    """
    Interface of a Nylas token exchange request

    Attributes:
        redirect_uri: Should match the same redirect URI that was used for getting the code during the initial authorization request.
        refresh_token: Token to refresh/request your short-lived access token
        client_id: Client ID of the application.
        client_secret: Client secret of the application.
    """

    redirect_uri: str
    refresh_token: str
    client_id: str
    client_secret: str

TokenInfoResponse dataclass

Class representation of a Nylas token information response.

Attributes:

Name Type Description
iss str

The issuer of the token.

aud str

The token's audience.

iat int

The time that the token was issued.

exp int

The time that the token expires.

sub Optional[str]

The token's subject.

email Optional[str]

The email address of the Grant belonging to the user's token.

Source code in nylas/models/auth.py
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
@dataclass_json
@dataclass
class TokenInfoResponse:
    """
    Class representation of a Nylas token information response.

    Attributes:
        iss: The issuer of the token.
        aud: The token's audience.
        iat: The time that the token was issued.
        exp: The time that the token expires.
        sub: The token's subject.
        email: The email address of the Grant belonging to the user's token.
    """

    iss: str
    aud: str
    iat: int
    exp: int
    sub: Optional[str] = None
    email: Optional[str] = None

URLForAdminConsentConfig

Bases: URLForAuthenticationConfig

Configuration for generating a URL for admin consent authentication for Microsoft.

Attributes:

Name Type Description
credential_id str

The credential ID for the Microsoft account

Source code in nylas/models/auth.py
45
46
47
48
49
50
51
52
53
class URLForAdminConsentConfig(URLForAuthenticationConfig):
    """
    Configuration for generating a URL for admin consent authentication for Microsoft.

    Attributes:
        credential_id: The credential ID for the Microsoft account
    """

    credential_id: str

URLForAuthenticationConfig

Bases: TypedDict

Configuration for generating a URL for OAuth 2.0 authentication.

Attributes:

Name Type Description
client_id str

The client ID of your application.

redirect_uri str

Redirect URI of the integration.

provider NotRequired[Provider]

The integration provider type that you already had set up with Nylas for this application. If not set, the user is directed to the Hosted Login screen and prompted to select a provider.

access_type NotRequired[AccessType]

If the exchange token should return a refresh token too. Not suitable for client side or JavaScript apps.

prompt NotRequired[str]

The prompt parameter is used to force the consent screen to be displayed even if the user has already given consent to your application.

scope NotRequired[List[str]]

A space-delimited list of scopes that identify the resources that your application could access on the user's behalf. If no scope is given, all of the default integration's scopes are used.

include_grant_scopes NotRequired[bool]

If set to true, the scopes granted to the application will be included in the response.

state NotRequired[str]

Optional state to be returned after authentication

login_hint NotRequired[str]

Prefill the login name (usually email) during authorization flow. If a Grant for the provided email already exists, a Grant's re-auth will automatically be initiated.

Source code in nylas/models/auth.py
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
42
class URLForAuthenticationConfig(TypedDict):
    """
    Configuration for generating a URL for OAuth 2.0 authentication.

    Attributes:
        client_id: The client ID of your application.
        redirect_uri: Redirect URI of the integration.
        provider: The integration provider type that you already had set up with Nylas for this application.
            If not set, the user is directed to the Hosted Login screen and prompted to select a provider.
        access_type: If the exchange token should return a refresh token too.
            Not suitable for client side or JavaScript apps.
        prompt: The prompt parameter is used to force the consent screen to be displayed even if the user has already given consent to your application.
        scope: A space-delimited list of scopes that identify the resources that your application could access on the user's behalf.
            If no scope is given, all of the default integration's scopes are used.
        include_grant_scopes: If set to true, the scopes granted to the application will be included in the response.
        state: Optional state to be returned after authentication
        login_hint: Prefill the login name (usually email) during authorization flow.
            If a Grant for the provided email already exists, a Grant's re-auth will automatically be initiated.
    """

    client_id: str
    redirect_uri: str
    provider: NotRequired[Provider]
    access_type: NotRequired[AccessType]
    prompt: NotRequired[str]
    scope: NotRequired[List[str]]
    include_grant_scopes: NotRequired[bool]
    state: NotRequired[str]
    login_hint: NotRequired[str]