Add basic JWT-based auth #12
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #2
Adds a JWT-based auth and refresh mechanism for protecting API endpoints.
/api/auth/login: the login endpoint. Needs no authentication./api/auth/refresh: the refresh token dispensing endpoint. Needs no authentication.Users are verified in the system by login credentials when logging in, and by the combination of refresh token and username when requesting a refresh token.
The TTL of both refresh and access tokens may be set by the server admin in the
.envfile. By default, access tokens persist for one hour and refresh tokens persist for 7 days. Each time a request is made for a new access token, the access token's TTL is updated to avoid logging users out too frequently.All web endpoints are protected by form-based login, and all API endpoints are protected by JWTs. User permissions (
USER,ADMIN) are encoded either in the user's principle (for the web interface) or the JWT. Users may only access what they own or what is public, administrators will likely be given much more access.