7 Adding Authorization & Authentication

 

This chapter covers

  • Adding authentication and authorization to our application, including both the GraphQL API and our frontend React application
  • Using JSON Web Tokens (JWTs) to encode user identify and permissions
  • Expressing and enforcing authorization rules in our GraphQL schema using the @auth GraphQL schema directive
  • Using Auth0 as a JWT provider and the Auth0 React SDK to add Auth0 support to our application

Authentication (verifying a user’s identity) and authorization (verifying resources users can access) are needed to secure any application - ensuring users have the permissions that they should, and protecting data and actions of the application, both on the frontend and backend. So far, both our frontend React application and GraphQL API are open for anyone to access all features and functionality, including modifying, creating, and deleting data.

7.1 Authorization In GraphQL - A Naive Approach

7.2 JSON Web Tokens (JWTs)

7.3 The @auth GraphQL Schema Directive

7.3.1 Rules And Operations

7.3.2 The isAuthenticated Authorization Rule

7.3.3 The roles Authorization Rule

7.3.4 The allow Authorization Rule

7.3.5 The where Authorization Rule

7.3.6 The bind Authorization Rule

7.4 Auth0: JWT-as-a-service

7.4.1 Configuring Auth0

7.4.2 Auth0 React

7.5 Exercises

7.6 Summary

sitemap