Skip to content

zemuldo/authentication-methods

Repository files navigation

zemuldo-authentication-methods

To start, clone repo then: Run npm install Run npm start

Basic Auth

Call endpoint with credentials. Example:

curl --request GET \
  --url http://localhost:4000/basic \
  --header 'Authorization: Basic emVtdWxkbzpwYXNzd29yZA=='

Bearer Token

RS256

Run auth request

curl --request POST \
  --url http://localhost:4000/bearer-token/rsa-sha-256/signin \
  --header 'Content-Type: application/json' \
  --data '{
	"username": "zemuldo",
	"password": "password"
}'

Response to this will look like

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2V..."
}

Use the token to call a protected endpoint

curl --request GET \
  --url http://localhost:4000/bearer-token/rsa-sha-256/protected \
  --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1...'

HS256

Login request

curl --request POST \
  --url http://localhost:4000/bearer-token/hmac-sha-256/signin \
  --header 'Content-Type: application/json' \
  --data '{
	"username": "zemuldo",
	"password": "password"
}'

Response to this will look like

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2V..."
}

Use the token to access protected endpoint

curl --request GET \
  --url http://localhost:4000/bearer-token/hmac-sha-256/protected \
  --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2...'