Custom Authentication Flow

Is it possible to customize Tyk to implement the following authorization flow? If so, what is the best way?

  1. OAuth module takes some values from headers (some custom claims) and calls internal token web service to get session token from underlying web service.
  2. Token service returns its own session token, which we need to encrypt. That encrypted internal token now becomes the OAuth token that OAuth module returns back (instead of just generating some random session token).
  3. On every request our client sends us this OAuth token, which (besides being checked on revocation/expiration in Tyk internal session store – this is standard Tyk behavior) should be decrypted and passed along with every request to internal API.

The following diagram represents the desired flow:
Authentication:

external — claim -----------> Tyk (stores encryped token) -----claim —> Token service
external <- encrypted token — Tyk <— token — Token service

subsequent requests:

external -------encrypted token --> Tyk ---------------------> decrypted token --> Token service

Here is my undrestanding of the (only?) way to implement this in Tyk:

  1. Tyk custom JS middleware gets the custom claim from the request headers and calls Token Service to get a token using TykMakeHTTPRequest
  2. Token Service returns its own session token. Encrypt the token and store it using TykSetKeyData.
  3. On subsequent requests, the external service sends the (encrypted) token, which should work, since we saved it in the session store.

Is this customization do-able? Is using the JS custom middleware API the best way of accomplishing the task?

Hi Max,

There is a very convoluted way of achieving this in version 2.2 of Tyk. However, version 2.3 is set to come out in a few days (either later this week or some time next week) and in this release, it will be possible to replace the authentication module with custom code that can perform identity caching.

Regards,

Jess @ Tyk

Hello @jess, thanks for your response.

Would the solution I described work for 2.2?
Do you know what language will be used for custom authentication modules in 2.3+? I looked at the 2.3 branch on Github and couldn’t find anything having to do with custom authentication, but may have looked in the wrong place.

Thanks,

Max

Hi Max,

Apologies for the delayed response, are you still unsure of what approach to take with regards to authentication? In November, we released a blog post announcing the new custom plugins that became available in Tyk 2.3. The languages supported are as follows:

  • Javascript (ES5)
  • Python 3
  • LuaJIT
  • gRPC-compatible languages (e.g., Ruby, NodeJS, .NET, Java, Go, &c.)

Further information on how to use the new plugins can be found in our docs but please let us know if you encounter any issues setting this up.

Kind regards,
Jess @ Tyk