djangooauthoauth-2.0django-oauth

How to implement OAuth when the resource and auth servers are same


I have a Django Rest API with JWT authentication which is the backend for a Angular frontend. There are many clients who use the service with our frontend. Now some enterprise clients wanted to integrate the APIs from their system's backend. I don't want to remove JWT from current APIs. I am planning to create new APIs in the same backend with OAuth token for those users.

I wonder what is the best way to implement OAuth for this scenario.

I am thinking Client Credentials grant type is the best way.

Question1: Am I right that client credentials is the right approach ?

For those enterprise users, it is sufficient they get just access token through the UI interface so that they can access all our APIs. But here the problem is one additional step of getting the Client ID and Client Secret first and using that to get Access Token.

Question 2: What is the use of client ID and client secret ?

Question3: Should my backend hide the process of generating Client ID and Client secret and just give Access token (or) give them Client ID and Client Secret and ask then to generate access token ?

Question 4: If I am giving them Access Token without client id and secret, is that fine to have infinite expiry time? and

TLDR; How to implement OAuth when the resource server and auth servers are same ?


Solution

  • Question1: Am I right that client credentials is the right approach ?

    Yes. Providing the new APIs do not need to be called in the context of an end user.

    Question 2: What is the use of client ID and client secret ?

    It's effectively a username and password in this scenario.

    Question3: Should my backend hide the process of generating Client ID and Client secret and just give Access token (or) give them Client ID and Client Secret and ask then to generate access token ?

    Your Auth server should issue the client credentials to the application once and the application should provide those credentials every time they wish to obtain a token via the client credentials grant type.