This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
feat: subscriptions refinements and comments #15
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: