wzarek / Reasn

find your reasn to meet
3 stars 0 forks source link

[RSN-40] Add user authentication #43

Closed raczu closed 4 months ago

raczu commented 4 months ago

Description

The purpose of this PR is to add authentication of users using JWT token and authorization to given resources/routes depending on their roles. A secrey key must be set in appsettings.json in order for JWT to work properly, the easiest way to generate key is to use following command:

openssl rand -base64 32

and manually replace placeholder value or directly with usage of jq:

export SECRET_KEY=$(openssl rand -base64 32); jq '.JwtSettings.Key = env.SECRET_KEY' appsettings.json > tmp.json && mv tmp.json appsettings.json

Additionally, mappers have been added, which extends database models for easier mapping to appropiate DTO, and handlers for easier handling exceptions in service layer or unhandled one. It allowed to standarize the format of problems returned by API to problem+json. When it comes to data validation, a library FluentValidation has been added, and its exceptions are also handled with usage of handlers.

Related issue and/or ticket

RSN-40

raczu commented 4 months ago

@wzarek

raczu commented 4 months ago

Can't we use the same validators as in #32 - RSN-31?

We decided to use fluent validation for creating validators, the @mkoper02 validators have already been rewritten to use this library, see #32

wzarek commented 4 months ago

@raczu resolve conflicts / rebase

raczu commented 4 months ago

@wzarek

wzarek commented 4 months ago

@raczu conflicts again