Skip to content

Commit 6799a93

Browse files
authored
Merge pull request #6040 from segmentio/DOC-821
obtain OAuth access token [DOC-821]
2 parents d5811ce + fe21973 commit 6799a93

File tree

2 files changed

+87
-8
lines changed

2 files changed

+87
-8
lines changed

src/connections/oauth.md

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,62 @@ Once you've connected your source to OAuth, you can enable it. To enable your so
6767

6868
To disable your source from OAuth, turn the toggle off for **Enable OAuth**.
6969

70-
<!-- ## Request the access token
71-
72-
To request the access token, run:
73-
74-
```
75-
./gentoken.sh -k <private-key.pem> -i <key_id> -a <oauth_app_id> | jq '.access_token'
76-
```
77-
-->
70+
## Obtain the access token
71+
You can obtain an access token once you create an OAuth application and enable a source to OAuth.
72+
73+
Access tokens are only valid within a region. The supported regional authorization servers are:
74+
* Oregon - `https://oauth2.segment.io`
75+
* Dublin - `https://oauth2.eu1.segmentapis.com`
76+
77+
To obtain the access token:
78+
79+
1. Create a JWT token with the header and payload as below:
80+
81+
Header
82+
```
83+
{
84+
"alg":"RS256",
85+
"typ":"JWT",
86+
"kid":"<<KID>>"
87+
}
88+
```
89+
90+
Payload
91+
```
92+
{
93+
"iss":"<<ISS>>",
94+
"sub":"<<SUB>>",
95+
"aud":"<<AUD>>",
96+
"iat":"<<IAT>>",
97+
"exp":"<<EXP>>",
98+
"jti":"<<JTI>>"
99+
}
100+
```
101+
102+
Field | Description
103+
------------ | -------------
104+
KID | The key ID of the public key in the OAuth application.
105+
ISS | The identifier of the JWT issuer.
106+
SUB | The OAuth application ID.
107+
IAT | The epoch time in seconds when the token was issued.
108+
EXP | The expiry time in seconds. This is expected to be valid only for a short duration under a minute.
109+
JTI | The unique identifer for the token.
110+
111+
2. Send a form-url-encoded `POST` request to the regional authorization server with the following parameters:
112+
113+
```
114+
grant_type=client_credentials
115+
client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer
116+
client_assertion=<<JWT>>
117+
scope=<<SCOPE>>
118+
```
119+
120+
Field | Description
121+
----- | ------------
122+
JWT | The signed JWT token string from Step 1.
123+
SCOPE | Scopes for which token is requested. See [supported scopes](#supported-scopes).
124+
125+
To use the access token, see an example of how to use the access token in the [HTTP API source]().
78126
79127
## Edit an OAuth application
80128
To edit an existing OAuth application:

src/connections/sources/catalog/libraries/server/http-api/index.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ Segment has native [sources](/docs/connections/sources/) for most use cases (lik
1111

1212
### Authentication
1313

14+
Choose between [basic authentication](#basic-authentication) and [OAuth](#oauth) to authenticate requests.
15+
16+
#### Basic authentication
17+
1418
Authenticate to the Tracking API by sending your project's **Write Key** along with a request.
1519
Authentication uses HTTP Basic Auth, which involves a `username:password` that is base64 encoded and prepended with the string `Basic`.
1620

@@ -19,6 +23,33 @@ In practice that means taking a Segment source **Write Key**,`'abc123'`, as the
1923
> info ""
2024
> Include a colon before encoding. While encoding the write key without a colon might work due to backward compatibility, this won't always be the case.
2125
26+
#### OAuth
27+
[Obtain the access token](/docs/connections/oauth/) from the Authorization Server specific to the region.
28+
29+
Include the access token in the Authorization header as a Bearer token along with your project's write key in the payload of the request. For example, Authorization with Bearer token looks like:
30+
31+
```
32+
Authorization: Bearer <access token>
33+
```
34+
35+
36+
For example, to use the access token in the HTTP API Source, use `access_token` in the header and `write_key` in the payload. An example cURL request looks like:
37+
38+
```
39+
curl --location 'https://api.segment.io/v1/track' \
40+
--header 'Content-Type: application/json' \
41+
--header 'Authorization: Bearer <access token>' \
42+
--data-raw '{
43+
"event": "happy-path-a3ef8a6f-0482-4694-bc4d-4afba03a0eab",
44+
"email": "[email protected]",
45+
"messageId": "58524f3a-3b76-4eac-aa97-d88bccdf4f77",
46+
"userId": "123",
47+
"writeKey": "DmBXIN4JnwqBnTqXccTF0wBnLXNQmFtk"
48+
}
49+
```
50+
51+
You can reuse the access token until the expiry period specified on the OAuth application.
52+
2253
### Content-Type
2354

2455
To send data to Segment's HTTP API, a content-type header must be set to `'application/json'`.

0 commit comments

Comments
 (0)