superstreamlabs / memphis-rest-gateway

Produce messages using REST to Memphis.dev station
https://docs.memphis.dev
Other
11 stars 7 forks source link

feat: add support for access token generation and authentication #53

Open mrchocha opened 1 year ago

mrchocha commented 1 year ago

Context

Issue & Relevant PRs

Examples

Generate New Access Token

curl --location 'http://localhost:4444/auth/generateAccessToken' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50X2lkIjoxLCJjb25uZWN0aW9uX3Rva2VuIjoiIiwiZXhwIjoyMDU1MzAxMTkwLCJwYXNzd29yZCI6Im1lbXBoaXMiLCJ1c2VybmFtZSI6InJvb3QifQ.HCJvG-UQG2kDNNlNlOovbLIf8E6VHPYAaV3JYnDo8Gc' \
--header 'Content-Type: application/json' \
--header 'Cookie: memphis-jwt-refresh-token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhbHJlYWR5X2xvZ2dlZF9pbiI6dHJ1ZSwiYXZhdGFyX2lkIjoxLCJjcmVhdGlvbl9kYXRlIjoiMjAyMy0wOS0xOVQxNTozNjo1Mi42NzI1MTErMDU6MzAiLCJleHAiOjE2OTU0NjkyNjcsInRlbmFudF9uYW1lIjoiJG1lbXBoaXMiLCJ1c2VyX2lkIjoxLCJ1c2VyX3R5cGUiOiJyb290IiwidXNlcm5hbWUiOiJyb290In0.dhJXniH4V7Xh3t7w7e6Ow161GfR7e0hR-M6SYj9ELS4' \
--data '{
    "description": "New Access Tokens from gateway"
}
'

Output

{
    "access_key_id": "rAgfLcvAftjqTOu",
    "secret_key": "BsNjQDqBlxaRbjYyaBviLfYPu3iH1d"
}

Use Access Token in other requests instead of JWT

curl --location 'http://localhost:4444/stations/s1/produce/single' \
--header 'Access-Key-Id: rAgfLcvAftjqTOu' \
--header 'Secret-Key: BsNjQDqBlxaRbjYyaBviLfYPu3iH1d' \
--header 'Content-Type: application/json' \
--header 'Cookie: memphis-jwt-refresh-token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhbHJlYWR5X2xvZ2dlZF9pbiI6dHJ1ZSwiYXZhdGFyX2lkIjoxLCJjcmVhdGlvbl9kYXRlIjoiMjAyMy0wOS0xOVQxNTozNjo1Mi42NzI1MTErMDU6MzAiLCJleHAiOjE2OTU0NjkyNjcsInRlbmFudF9uYW1lIjoiJG1lbXBoaXMiLCJ1c2VyX2lkIjoxLCJ1c2VyX3R5cGUiOiJyb290IiwidXNlcm5hbWUiOiJyb290In0.dhJXniH4V7Xh3t7w7e6Ow161GfR7e0hR-M6SYj9ELS4' \
--data '{
    "message":"With Access Token yooohoo, its working!!!"
}'

Output

{
    "error": null,
    "success": true
}