Skip to content

Commit 3bfe548

Browse files
authored
Merge pull request #1875 from EnterpriseDB/UPM-2380
docs(UPM-2380): Added docs for using shell script to get API tokens
2 parents 5751c4a + 3773ed2 commit 3bfe548

File tree

1 file changed

+95
-22
lines changed
  • product_docs/docs/edbcloud/beta/reference

1 file changed

+95
-22
lines changed

product_docs/docs/edbcloud/beta/reference/index.mdx

Lines changed: 95 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,21 @@ The API reference documentation is available from the [EDB Cloud portal](https:/
88

99
To access the API, you need a token. The high-level steps to obtain a token are:
1010
1. [Query the authentication endpoint](#query-the-authentication-endpoint).
11-
2. [Request the device code](#request-the-device-code).
11+
2. [Request the device code](#request-the-device-code-using-curl).
1212
3. [Authorize as a user](#authorize-as-a-user).
13-
4. [Request the token](#request-the-token).
13+
4. [Request the token](#request-the-token-using-curl).
1414

1515

16+
EDB provides an optional script to simplify getting your device code and getting and refreshing your tokens. See [Using the `get-token` Script](#using-the-get-token-script) for details.
17+
1618

1719
## Query the Authentication Endpoint
1820

19-
Use the following command to get the information returned by the authentication endpoint that you need later:
21+
This call returns the information that either:
22+
23+
- you need later if you are using `curl` to request the device code and tokens, or
24+
- the `get-token` script uses to generate the tokens for you
25+
2026

2127
```
2228
curl https://portal.edbcloud.com/api/v1/auth/provider
@@ -32,19 +38,21 @@ The response returns the `clientId`, `issuerUri`, `scope`, and `audience`. For e
3238
}
3339
```
3440

35-
EDB recommends you store the output in environment variables to make including them in the following calls easier. For example,
41+
EDB recommends you store the output in environment variables to make including them in the following calls easier. For example:
3642

3743
```
3844
CLIENT_ID=pM8PRguGtW9yVnrsvrvpaPyyeS9fVvFh
3945
ISSUER_URL=https://auth.edbcloud.com
4046
SCOPE="openid profile email offline_access"
4147
AUDIENCE="https://portal.edbcloud.com/api"
4248
```
43-
The following example calls show use these environment variables.
44-
45-
## Request the Device code
49+
The following example calls use these environment variables.
4650

47-
Use the following call to get a device code:
51+
## Request the Device Code Using `curl`
52+
!!!note
53+
The `get-token` script executes this step. You don't need to make this call if you are using the script.
54+
!!!
55+
This call gets a device code:
4856
```
4957
curl --request POST \
5058
--url "$ISSUER_URL/oauth/device/code" \
@@ -56,7 +64,7 @@ curl --request POST \
5664

5765
The response returns:
5866

59-
- `device_code` - the unique code for the device. When you go to the `verification_uri` in your browser-based device, this code is bound to your session. You use this code in your [request for a token](#request-the-token).
67+
- `device_code` - the unique code for the device. When you go to the `verification_uri` in your browser-based device, this code is bound to your session. You use this code in your [request for a token](#request-the-token-using-curl).
6068
- `user_code` - the code you input at the `verification_uri` to authorize the device. You use this code when you [authorize yourself as a user](#authorize-as-a-user).
6169
- `verification_uri` - the URL you use to authorize your device.
6270
- `verification_uri_complete` - the complete URL you use to authorize the device. You can use this URL to embed the user code in your app's URL.
@@ -75,26 +83,31 @@ For example:
7583
}
7684
```
7785

78-
Store the device_code in an environment variable for future use. For example;
86+
Store the device code in an environment variable for future use. For example:
7987

8088
```
8189
DEVICE_CODE=KEOY2_5YjuVsRuIrrR-aq5gs
8290
```
8391

8492
## Authorize as a User
8593

94+
To authorize as a user:
95+
8696
1. Go to the `verification_uri` in your web browser, enter your `user_code`, and select **Continue**.
8797

88-
4. Select **Confirm** on the Device Confirmation dialog.
98+
2. Select **Confirm** on the Device Confirmation dialog.
8999

90-
5. Select **Continue with Microsoft Azure AD** on the EDB Cloud Welcome screen.
100+
3. Select **Continue with Microsoft Azure AD** on the EDB Cloud Welcome screen.
91101

92-
6. Log in with your Azure AD credentials.
102+
4. Log in with your Azure AD credentials.
93103

94104

95-
## Request the Token
105+
## Request the Token Using `curl`
106+
!!!note
107+
The `get-token` script executes this step. You don't need to make this call if you are using the script. See [Request Your Token Using `get-token`](#request-your-token-using-get-token).
108+
!!!
96109

97-
Use the `curl --request POST` command to request a token. For example,
110+
The `curl --request POST` call requests a token. For example:
98111
```
99112
curl --request POST \
100113
--url "$ISSUER_URL/oauth/token" \
@@ -121,17 +134,17 @@ For example:
121134
"token_type": "Bearer"
122135
}
123136
```
124-
Store the access_token and refresh_token in environment variables for future use. For example,
137+
Store the access token and refresh token in environment variables for future use. For example:
125138

126139
```
127140
ACCESS_TOKEN="eyJhbGc.......1Qtkaw2fyho"
128141
REFRESH_TOKEN="v1.MTvuZpu.......sbiionEhtTw"
129142
```
130143

131144
If not successful, you receive one of the following errors:
132-
- `authorization_pending` - continue polling using the suggested interval retrieved when you [requested the device code](#request-the-device-code).
145+
- `authorization_pending` - continue polling using the suggested interval retrieved when you [requested the device code](#request-the-device-code-using-curl).
133146

134-
- `slow_down` - slow down and use the suggested interval retrieved when you [requested the device code](#request-the-device-code). To avoid receiving this error due to network latency, you should start counting each interval after receipt of the last polling request's response.
147+
- `slow_down` - slow down and use the suggested interval retrieved when you [requested the device code](#request-the-device-code-using-curl). To avoid receiving this error due to network latency, you should start counting each interval after receipt of the last polling request's response.
135148
- `expired_token` - you have not authorized the device quickly enough, so the `device_code` has expired. Your application should notify you that it has expired and to restore it.
136149
- `access_denied`
137150

@@ -171,11 +184,16 @@ Example response:
171184
```
172185

173186

174-
## Refreshing your Token
187+
## Refresh your Token
188+
189+
You use the refresh token to get a new access token. Usually you need a new access token only after the previous one expires or when gaining access to a new resource for the first time. You shouldn't call the endpoint to get a new access token every time you call an API. There are rate limits that throttle the amount of requests to the endpoint that can be executed using the same token from the same IP.
175190

176-
You can use the refresh token to get a new access token. Usually you need a new access token only after the previous one expires or when gaining access to a new resource for the first time. You shouldn't call the endpoint to get a new access token every time you call an API. There are rate limits that throttle the amount of requests to the endpoint that can be executed using the same token from the same IP.
191+
### Refresh your Token Using `curl`
192+
!!!note
193+
The `get-token` script has an option to execute this step. See [Refresh the Token Using `get-token`](#refresh-the-token-using-get-token).
194+
!!!
177195

178-
To refresh your token, make a POST request to the `/oauth/token` endpoint in the Authentication API, using `grant_type=refresh_token`. For example:
196+
If you are not using the `get-token` script to refresh your token, make a POST request to the `/oauth/token` endpoint in the Authentication API, using `grant_type=refresh_token`. For example:
179197
```
180198
curl --request POST \
181199
--url "$ISSUER_URL/oauth/token" \
@@ -201,14 +219,69 @@ The response of this API call includes the `access_token`. For example:
201219
```
202220

203221
!!! Note
204-
You need to save the `refresh_token` retrieved from this response for the next refresh call. The `refresh_token` in the response when you originally [requested the token](#request-the-token) is obsoleted once it has been used.
222+
You need to save the refresh token retrieved from this response for the next refresh call. The refresh token in the response when you originally [requested the token](#request-the-token) is obsoleted once it has been used.
205223

206224

207225

226+
## Using the `get-token` Script
208227

209228

229+
To simplify the process of getting tokens, EDB provides the `get-token` script. You can download it [here](https://github.com/EnterpriseDB/cloud-utilities/tree/main/api).
210230

231+
To use the script, install the [jq command-line JSON processor](https://stedolan.github.io/jq/) specific to your OS.
211232

233+
Before running the script, [query the authentication endpoint](#query-the-authentication-endpoint).
212234

235+
### get-token Usage
213236

237+
```
238+
Usage:
239+
./get-token.sh [flags] [options]
240+
241+
flags:
242+
--format (-o) json | plain output format
243+
--refresh <refresh_token> [optional] query for tokens
244+
again using given <refresh_token>
245+
this revokes and rotates the refresh
246+
token. Please remember the newly
247+
returned refresh_token for the next use.
248+
249+
```
250+
251+
### Request Your Token Using `get-token`
252+
To use the `get-token` script to get your tokens, use the script without the `--refresh` option. For example:
253+
254+
```
255+
./get-token.sh -o plain
256+
Please login to
257+
https://edbcloud.us.auth0.com/activate?user_code=ZMNX-VVJT
258+
with your EDB Cloud account
259+
Have you finished the login successfully? (y/N) y
260+
261+
####### Access Token ################
262+
eyxxxxxxxxxxxxxx
263+
264+
####### Refresh Token ###############
265+
xxxxxxxxxx
266+
267+
####### ID Token ###############
268+
xxxxxxxxxxxx
269+
270+
##### Expires In Seconds ##########
271+
86400
272+
```
273+
### Refresh the Token Using `get-token`
274+
To use the `get-token` script to refresh your token, use the script with the `--refresh <refresh_token>` option. For example:
275+
276+
```
277+
./get-token.sh -o json --refresh v1.MVZ9_xxxxxxxx_FRs
278+
{
279+
"access_token": "xxxxxxxxxx",
280+
"refresh_token": "xxxxxxxxxxxx",
281+
"id_token": "xxxxxxxx",
282+
"scope": "openid profile email offline_access",
283+
"expires_in": 86400,
284+
"token_type": "Bearer"
285+
}
286+
```
214287

0 commit comments

Comments
 (0)