Skip to content

Authorization

schwarzlichtbezirk edited this page Nov 5, 2026 · 2 revisions

General remarks

There is supported basic authorization and bearer authorization (with JWT-tokens). Authorization data can be provided by 4 ways: in header Authorization, at query parameters, at cookies, and at post form.

Bearer works with two HS256 JWT tokens - access token and refresh token. Access token should be provided in all cases except refresh call. When access-token expires, it should be replaced to refresh-token for refresh-call.

Basic expects credentials pair email:password encoded in unpadded base64 encoding for URL (see RFC 4648). Optional method, switched off at settings by default.

In /signin call password can be given by two ways:

  1. Explicitly at field secret as is.
  2. By HMAC SHA256 hash and temporary public key (without send opened secret).

In second case it should be string in field sigtime with current time formatted in RFC3339 (can be with nanoseconds). And at field hs256 it should be hexadecimal HMAC formed with algorithm SHA256 with this current time as a key, and password, i.e. sha256.hmac(sigtime, password). Allowed timeout for public key is 2m 30s.

  • Sign-in, and use token from response with any followed calls.
curl -X POST localhost:8080/signin \
  -H "Content-Type: application/json" \
  -d '{"email":"player@example.org","secret":"iVI05M"}'

You can use token

TOKEN="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzbG90b3BvbCIsInN1YiI6IjMiLCJleHAiOjQ5NDg5NTk2MDAsIm5iZiI6MTc5MzE5OTYwMCwic2lkIjoxfQ.SBj9zW4nSzC7mwqx7PrG5n1nf1HwJqnYxq1-80NdZ0Y"

for test purpose, it given for user with UID=3 on 100 years. Tip: you can generate same token by call

go run ./task/jwtgen -s=1 -u=3 -n="2026-10-28 15:00:00" -t=876600h
  • When your access token expires (you can get response with 401 status code), use refresh-call with refresh-token to get new tokens pair.
curl -X POST localhost:8080/token \
  -H "Content-Type: application/json" \
  -d '{"refrsh":"$REFRESH"}'

To test authorization you can use special authorized ping:

curl -i localhost:8080/authping \
  -H "Authorization: Bearer $TOKEN"

Clone this wiki locally