4IT580: Docs
4IT580 WebGitLab

6th Practical Class:
BackEnd finalization!

Auth

Authentication vs Authorization

It is common to see combinations of both, you first need to authenticate in order to be authorized to use the resource.

JWT tokens

Example

Consists of 3 parts:

You can read any JWT token data, but you can't change them! Try out here

Securing our application

Authentication providers

Custom implementations

Example

On signUp/signIn, server creates a JWT token. (We're using library , all examples are included in the code).

Client has to include token for every request, usually in header, in GraphQL we can use :

Server verifies the token with the same secret used for creating the token.

In our case we authenticate the user in the GraphQL context.

Then we simply "authorize" user to use some of the resolvers.

Let's see the code

File upload

Unfortunately, GraphQL is not suitable for uploading files, CSRF vulnerability. You can read more here

Better solutions:

Signed URL uploads

Dedicated file/image service

File upload using GraphQL

Swap to express server

Detailed documentation for swapping to expressMiddleware

Defining and using the scalar.

(Be aware when using TS generators, you also have to adjust the generator to include custom Scalar types)

See the code for an implementation example for signUp mutation

Frontend

apollo-upload-client

Form