add code examples for login in openapi spec

This commit is contained in:
Rigel Kent 2021-05-14 19:19:10 +02:00
parent 5b1a6d45b5
commit 3cf8874f1a
No known key found for this signature in database
GPG Key ID: 5E53E96A494E452F
1 changed files with 31 additions and 6 deletions

View File

@ -809,6 +809,13 @@ paths:
parameters: parameters:
client_id: '$response.body#/client_id' client_id: '$response.body#/client_id'
client_secret: '$response.body#/client_secret' client_secret: '$response.body#/client_secret'
x-codeSamples:
- lang: Shell
source: |
API="https://peertube2.cpy.re/api/v1"
## AUTH
curl -s "$API/oauth-clients/local"
/users/token: /users/token:
post: post:
summary: Login summary: Login
@ -855,6 +862,24 @@ paths:
type: integer type: integer
minimum: 0 minimum: 0
example: 1209600 example: 1209600
x-codeSamples:
- lang: Shell
source: |
## DEPENDENCIES: jq
API="https://peertube2.cpy.re/api/v1"
USERNAME="<your_username>"
PASSWORD="<your_password>"
## AUTH
client_id=$(curl -s "$API/oauth-clients/local" | jq -r ".client_id")
client_secret=$(curl -s "$API/oauth-clients/local" | jq -r ".client_secret")
curl -s "$API/users/token" \
--data client_id="$client_id" \
--data client_secret="$client_secret" \
--data grant_type=password \
--data username="$USERNAME" \
--data password="$PASSWORD" \
| jq -r ".access_token"
/users/revoke-token: /users/revoke-token:
post: post:
summary: Logout summary: Logout
@ -1714,21 +1739,21 @@ paths:
FILE_PATH="<your_file_path>" FILE_PATH="<your_file_path>"
CHANNEL_ID="<your_channel_id>" CHANNEL_ID="<your_channel_id>"
NAME="<video_name>" NAME="<video_name>"
API="https://peertube2.cpy.re/api/v1"
API_PATH="https://peertube2.cpy.re/api/v1"
## AUTH ## AUTH
client_id=$(curl -s "$API_PATH/oauth-clients/local" | jq -r ".client_id") client_id=$(curl -s "$API/oauth-clients/local" | jq -r ".client_id")
client_secret=$(curl -s "$API_PATH/oauth-clients/local" | jq -r ".client_secret") client_secret=$(curl -s "$API/oauth-clients/local" | jq -r ".client_secret")
token=$(curl -s "$API_PATH/users/token" \ token=$(curl -s "$API/users/token" \
--data client_id="$client_id" \ --data client_id="$client_id" \
--data client_secret="$client_secret" \ --data client_secret="$client_secret" \
--data grant_type=password \ --data grant_type=password \
--data response_type=code \
--data username="$USERNAME" \ --data username="$USERNAME" \
--data password="$PASSWORD" \ --data password="$PASSWORD" \
| jq -r ".access_token") | jq -r ".access_token")
## VIDEO UPLOAD ## VIDEO UPLOAD
curl -s "$API_PATH/videos/upload" \ curl -s "$API/videos/upload" \
-H "Authorization: Bearer $token" \ -H "Authorization: Bearer $token" \
--max-time 600 \ --max-time 600 \
--form videofile=@"$FILE_PATH" \ --form videofile=@"$FILE_PATH" \