- Go to app/authorization/permissions and click on the "Create New Permission" button.
- Enter
call-protected-routeas the name and add a description if you want. - Click "Create New Permission"
- Now head over to /app/authorization/roles and click on the "Create New Role" button.
- Enter a name for the role, for example,
adminand select the permission from the prevous step - Click "Create".
- Go to https://app.unkey.com/apis and click on the "Create New API" button.
- Give it a name.
- Click "Create".
- Click "Create Key" in the top right corner.
- Click "Create"
- Copy the key and save it somewhere safe.
- Go to /app/apis and click on the API you created.
- Click on "Keys" in the tabs.
- Click on the key you created.
- Click on "Permissions" in the tabs.
- Check the role's checkbox to give the key the role and permission.
- Clone the repository
git clone git@github.com:unkeyed/examples.git
cd examples/express-with-middleware-permissions- Install the dependencies
pnpm install- Create a
.envfile and add the following:
UNKEY_ROOT_KEY=your-root-key
UNKEY_API_ID=your-api-id- Start the server
pnpm dev- curl the unprotected route
curl http://localhost:3000/publicIt should return Hello world!
- curl the protected route
curl http://localhost:3000/protected -H "Authorization: Bearer <YOUR_KEY>"It should return Hello protected world!