Skip to content

Commit a34f4ca

Browse files
authored
Adding OAuth information to python documentation
1 parent c473daa commit a34f4ca

File tree

1 file changed

+29
-0
lines changed
  • src/connections/sources/catalog/libraries/server/python

1 file changed

+29
-0
lines changed

src/connections/sources/catalog/libraries/server/python/index.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,35 @@ analytics.track('9742', 'Song Played', context={
560560

561561
Be sure to see the full [reference of supported keys](/docs/connections/spec/common/#context).
562562

563+
### OAuth 2
564+
565+
In order to guarantee authorized communication between your server environment and Segment's Tracking API, you can enable OAuth 2 in your Segment workspace. To support the non-interactive server environment, the OAuth workflow used is a signed client assertion JWT. You will need a public and private key pair where the public key is uploaded to the segment dashboard and the private key is kept in your server environment to be used by this SDK. Your server will verify its identity by signing a token request and will receive a token that is used to to authorize all communication with the Segment Tracking API.
566+
567+
You will also need to provide the OAuth Application ID and the public key's ID, both of which are provided in the Segment dashboard. There are also options available to specify the authorization server, custom scope, maximum number of retries, or a custom HTTP client if your environment has special rules for separate segment endpoints.
568+
569+
You should ensure that you are implementing handling for Analytics SDK errors. Good logging will help distinguish any configuration issues.
570+
571+
For more information, see the [Segment OAuth 2.0 documentation](/docs/connections/oauth/)
572+
573+
```python
574+
import segment.analytics as analytics
575+
with open("private_key.pem") as f:
576+
privatekey = f.read()
577+
578+
analytics.write_key = '<YOUR WRITE KEY HERE>'
579+
580+
analytics.oauth_client_id = 'CLIENT_ID' # OAuth application ID from segment dashboard
581+
analytics.oauth_client_key = privatekey # generated as a public/private key pair in PEM format from OpenSSL
582+
analytics.oauth_key_id = 'KEY_ID' # From segment dashboard after uploading public key
583+
584+
def on_error(error, items):
585+
print("An error occurred: ", error)
586+
analytics.on_error = on_error
587+
588+
analytics.track('AUser', 'track')
589+
analytics.flush()
590+
```
591+
563592
### Versioning
564593

565594
Check that you have the most recent version.

0 commit comments

Comments
 (0)