Skip to content

Instantly share code, notes, and snippets.

@omidraha
Forked from andineck/README.md
Last active November 19, 2022 21:27
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save omidraha/f47858de4c773959a6f0376a5d0c64d4 to your computer and use it in GitHub Desktop.
Save omidraha/f47858de4c773959a6f0376a5d0c64d4 to your computer and use it in GitHub Desktop.
Authentication and Authorization Concepts for MicroServices

auth with microservices

Authorization and Authentication are hard. when you only have to implement them once (as you do within a monolith) instead of over and over again, it makes the developer happy :-), and maybe leads to less implementation failures.

When you have a bunch of microservices, this is something that has to be considered.

Implement it once or in every microservice, or something in between?

approach 1

do authentication and authorization globally

pros

  • makes developer happy :)
  • less implementation errors
  • less risk of forgetting to handle at all
  • centrally defined and handled
  • smaller micro services
  • less repetition in the code in the micro services

cons

  • service can not have fine grained object permissions
  • all or nothing authorization
  • global auth bottleneck

approach 2

do authentication globally, and authorization in every microservice

pros

  • global authentication is easier to manage/control
  • fine grained object permissions are possible

cons

  • slightly more code in the micro services
  • needs some effort to have an overview what you can do with which permission

approach 3

do authentication in every microservice, and authorization globally

is listed only for completeness. it does not make sense -> worst of both worlds.

no fine grained object permissions and error prone and tedious repetitive authentication

approach 4

do authentication and authorization in every microservice

pros

  • fine grained object permissions are possible
  • different user authentication mechanisms are possible for different microservices

cons

  • error prone
  • many repetitions
  • bigger micro services
  • needs some effort to have an overview what you can do with which permission
  • no happy developer :-(

links

@iambudi
Copy link

iambudi commented Sep 23, 2020

Nice summary. Which one do you choose and how do you handle the cons?

@omidraha
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment