service_account
Nylas Service Account request signing for organization admin APIs.
See https://developer.nylas.com/docs/v3/auth/nylas-service-account/
If you set X-Nylas-* headers manually via RequestOverrides, the HTTP request body must be byte-identical to the canonical JSON string used when computing the signature.
ServiceAccountSigner
Builds the four required Nylas service account headers for a single request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
private_key_pem |
str
|
RSA private key in PEM text form (from the service account JSON). |
required |
private_key_id |
str
|
Value for X-Nylas-Kid ( |
required |
Source code in nylas/handler/service_account.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
build_headers(method, path, body=None, *, timestamp=None, nonce=None)
Produce signing headers and optional canonical JSON body bytes.
For POST/PUT/PATCH, body must be the same dict that will be sent; returned bytes
should be passed to HttpClient as serialized_json_body so the wire body matches
the signed payload.
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
(headers, serialized_json_body) where serialized_json_body is set for |
Optional[bytes]
|
POST/PUT/PATCH when body is not None, else None. |
Source code in nylas/handler/service_account.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
canonical_json(data)
Deterministic JSON with sorted keys at each object level, matching Nylas's reference implementation for service account signing.
Source code in nylas/handler/service_account.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
generate_nonce(length=_NONCE_LENGTH)
Cryptographically secure nonce (alphanumeric), default length 20.
Source code in nylas/handler/service_account.py
81 82 83 | |
load_rsa_private_key_from_pem(pem)
Load an RSA private key from a PEM string (PKCS#1 or PKCS#8).
Source code in nylas/handler/service_account.py
46 47 48 49 50 51 52 | |
sign_bytes(private_key, message)
RSA PKCS#1 v1.5 signature over SHA-256(message), Base64-encoded.
Source code in nylas/handler/service_account.py
75 76 77 78 | |