leepeuker / movary

Self hosted web app to track and rate your watched movies
MIT License
388 stars 14 forks source link

Centralize authentication process #598

Open JVT038 opened 6 months ago

JVT038 commented 6 months ago

In this PR I have attempted to centralize the authentication process by creating a new ValueObject called AuthenticationObject.

This object has three properties, namely the token itself, the authentication method and the userEntity of the authenticated user.

Three new methods have been created to create this new authentication object. One method for creating the object with cookie authentication, one method for creating it with the token stored inside the X-Movary-Token header and one 'dynamic' method to create the object with either the header or the cookie. So the dynamic method first checks the cookie for the token and if it doesn't exist, it'll check the HTTP header for the token.

Also, the methods all check both the user_auth_token and the user_api_token table for the token.