From 7bdcecfdbccfc948641afde03c439a0feb915d58 Mon Sep 17 00:00:00 2001 From: Zita Szupera Date: Tue, 14 May 2024 15:28:42 +0200 Subject: [PATCH] Update token examples for Bash --- .../docs/api/basics/authentication.mdx | 12 ++++++------ .../docs/api/basics/get_started.mdx | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/docusaurus/video/docusaurus/docs/api/basics/authentication.mdx b/docusaurus/video/docusaurus/docs/api/basics/authentication.mdx index 30eb3d79..b0c66105 100644 --- a/docusaurus/video/docusaurus/docs/api/basics/authentication.mdx +++ b/docusaurus/video/docusaurus/docs/api/basics/authentication.mdx @@ -354,13 +354,13 @@ def create_user_token(request): ```bash -HEADER=$(echo -n '{"alg": "HS256", "typ": "JWT"}' | base64); +HEADER=$(echo -n '{"alg": "HS256", "typ": "JWT"}' | openssl base64 -e -A | tr '+/' '-_' | tr -d '='); USER_ID=''; CURRENT_TIMESTAMP=$(date +%s); HOUR_FROM_NOW=$((CURRENT_TIMESTAMP + 3600)) -PAYLOAD=$(echo -n '{"user_id": "'${USER_ID}'", "iat": '${CURRENT_TIMESTAMP}', "exp": '${HOUR_FROM_NOW}'}' | base64); +PAYLOAD=$(echo -n '{"user_id": "'${USER_ID}'", "iat": '${CURRENT_TIMESTAMP}', "exp": '${HOUR_FROM_NOW}'}' | openssl base64 -e -A | tr '+/' '-_' | tr -d '='); SECRET=''; -SIGNATURE=$(echo -n ${HEADER}.${PAYLOAD} | openssl dgst -sha256 -hmac ${SECRET} -binary | base64 | tr -d '='); +SIGNATURE=$(echo -n ${HEADER}.${PAYLOAD} | openssl dgst -sha256 -hmac ${SECRET} -binary | openssl base64 -e -A | tr '+/' '-_' | tr -d '='); echo "${HEADER}.${PAYLOAD}.${SIGNATURE}" ``` @@ -406,15 +406,15 @@ client.create_call_token(user_id=user_id, expiration=exp, call_cids=call_cids) ```bash -HEADER=$(echo -n '{"alg": "HS256", "typ": "JWT"}' | base64); +HEADER=$(echo -n '{"alg": "HS256", "typ": "JWT"}' | openssl base64 -e -A | tr '+/' '-_' | tr -d '='); USER_ID=''; CURRENT_TIMESTAMP=$(date +%s); HOUR_FROM_NOW=$((CURRENT_TIMESTAMP + 3600)) CALL_CID1='livestream:1'; CALL_CID2='livestream:2'; -PAYLOAD=$(echo -n '{"user_id": "'${USER_ID}'", "call_cids": ["'${CALL_CID1}'", "'${CALL_CID2}'"], "iat": '${CURRENT_TIMESTAMP}', "exp": '${HOUR_FROM_NOW}'}' | base64); +PAYLOAD=$(echo -n '{"user_id": "'${USER_ID}'", "call_cids": ["'${CALL_CID1}'", "'${CALL_CID2}'"], "iat": '${CURRENT_TIMESTAMP}', "exp": '${HOUR_FROM_NOW}'}' | openssl base64 -e -A | tr '+/' '-_' | tr -d '='); SECRET=''; -SIGNATURE=$(echo -n ${HEADER}.${PAYLOAD} | openssl dgst -sha256 -hmac ${SECRET} -binary | base64 | tr -d '='); +SIGNATURE=$(echo -n ${HEADER}.${PAYLOAD} | openssl dgst -sha256 -hmac ${SECRET} -binary | openssl base64 -e -A | tr '+/' '-_' | tr -d '='); echo "${HEADER}.${PAYLOAD}.${SIGNATURE}" ``` diff --git a/docusaurus/video/docusaurus/docs/api/basics/get_started.mdx b/docusaurus/video/docusaurus/docs/api/basics/get_started.mdx index 0c40eba0..bbcc6cab 100644 --- a/docusaurus/video/docusaurus/docs/api/basics/get_started.mdx +++ b/docusaurus/video/docusaurus/docs/api/basics/get_started.mdx @@ -81,6 +81,25 @@ from getstream import Stream client = Stream(api_key="your_api_key", api_secret="your_api_secret", timeout=3.0) ``` + + + +```bash +# Create a server token +HEADER=$(echo -n '{"alg": "HS256", "typ": "JWT"}' | openssl base64 -e -A | tr '+/' '-_' | tr -d '='); +PAYLOAD=$(echo -n '{"server": true}' | openssl base64 -e -A | tr '+/' '-_' | tr -d '='); +SECRET=''; +SIGNATURE=$(echo -n ${HEADER}.${PAYLOAD} | openssl dgst -sha256 -hmac ${SECRET} -binary | openssl base64 -e -A | tr '+/' '-_' | tr -d '='); + +TOKEN="${HEADER}.${PAYLOAD}.${SIGNATURE}"; +API_KEY=''; + +# Provide API key, token and auth header to all requests +curl -X GET "https://video.stream-io-api.com/api/v2/app?api_key=${API_KEY}" \ + -H "Authorization: ${TOKEN}" \ + -H "stream-auth-type: jwt" +``` +