This PR adds some really nice subscriptions refinements.
Take a look at the two examples provided.
subscriptions.js - demonstrates the basic setup needed for subscriptions. In this mode, all subscriptions must be authenticated
subscriptions_advanced.js - demonstrates how we can use new KeycloakSubscriptionHandler({protect: false}) so that onSubscriptionConnect will not automatically throw an error if no auth related connectionParams are provided. This makes it possible to add authentication/authorization on individual subscription resolvers. For example you could have both public and private subscriptions.
In both scenarios, context.kauth in the subscription resolvers will work the exact same as in regular resolvers thanks to the KeycloakSubscriptionContext class. (KeycloakSubscriptionContext and KeycloakContext are now extensions of the KeycloakContextBase which provides the common functionality. This could also be used in future if we needed to support context from something that isn't express).
These improvements in how the context is built means that it is now possible to reuse the existing hasRole and auth resolver middlewares on subscription resolvers. Here's an example:
This PR adds some really nice subscriptions refinements.
Take a look at the two examples provided.
subscriptions.js - demonstrates the basic setup needed for subscriptions. In this mode, all subscriptions must be authenticated
subscriptions_advanced.js - demonstrates how we can use
new KeycloakSubscriptionHandler({protect: false})
so thatonSubscriptionConnect
will not automatically throw an error if no auth related connectionParams are provided. This makes it possible to add authentication/authorization on individual subscription resolvers. For example you could have both public and private subscriptions.In both scenarios,
context.kauth
in the subscription resolvers will work the exact same as in regular resolvers thanks to theKeycloakSubscriptionContext
class. (KeycloakSubscriptionContext
andKeycloakContext
are now extensions of theKeycloakContextBase
which provides the common functionality. This could also be used in future if we needed to support context from something that isn't express).These improvements in how the context is built means that it is now possible to reuse the existing
hasRole
andauth
resolver middlewares on subscription resolvers. Here's an example: