#different ways of authentication django microservice without dedicated user models

19 messages · Page 1 of 1 (latest)

maiden pond
#

(Any comments would be helpful) How can I authenticate a user who belongs to another database through my other microservice in django rest framework?, i think there is a way to do token based authentication but not sure how to, any help with the resources would be appreciated.

green dagger
#

Do you have this database listed in your DATABASES setting?

maiden pond
#

@green dagger Thanks for the response, but the microservice does not access to the main database itself

green dagger
#

Do you have the code to determine if a request is authenticated through your microservice?

#

If yes, wrap that in a custom authentication class as described in the link above.

#

You'll need to create a proxy user account to associate with it in your django application.

#

(I think)

maiden pond
#

Thats the problem, i dont have a method to authenticate the requests made to the microservice

green dagger
#

Why not? Sorry if that's an obvious question.

maiden pond
#

Okay maybe I am missing a few strings here, but how do i authenticate a microservice ?

green dagger
#

It depends on the microservice.

maiden pond
#

its a todo app

green dagger
#

From my perspective you're asking, "how do I use X to authenticate my django app?". In the scenario that I understand X is already built and a known quantity. Is that correct?

maiden pond
#

yes

green dagger
#

Who built X / the microservice that you're supposed to be using for authentication?

maiden pond
#

it is like this situation : So far, I have two separate projects with two separate databases,

  1. To authenticate the user using simplejwt authentication. (todo_auth project with todo_auth database)
  2. To show the todo/task information specific to that user. (todo project with todo database)
#

in this case i want to authenticate apis of 2 using users of 1

green dagger
#

Assuming todo_auth is done and is using django-rest-framework-simplejwt, you should be able to authenticate with something like their example: https://django-rest-framework-simplejwt.readthedocs.io/en/latest/getting_started.html#usage

You'll need to use requests or something similar instead of curl though. In your todo project, you'll create a custom authentication class as I linked originally, and make a request to your todo_auth DRF web service. You'll have to check that the token is valid, get the unique user identifer (maybe a separate web service or you'll have to customize the /api/token/ view). Then create a user for that token in todo's database and return that user from your authentication class.

That said, unless you're specifically trying to learn this I would recommend building a monolith.