Skip to content

Host with multiple transports having different auth types #328

Closed

Description

@esso23

Hello,

I need to create a Host that has multiple transports having different types of authentication.
My case:

  • Transport at port 50000 using secure websocket with OAuth authentication (for public clients) - security
  • Transport at port 50001 using RawSocket transport using ticket authentication (for local clients) - speed

I tried using code from WampAuthenticationHost but I ended up with endless internal dependency chain (I gave up after copying more than dozen classes).

I just need to have 2 different RegisterTransport methods, one which uses CreateAuthenticationBinding (this one uses WampAuthenticationBinaryBinding, WampAuthenticationBinaryBinding and WampAuthenticationBinding which are all internal and have other internal dependencies) and one which does not.

I also tried to use implementation of WampHost and edit that but that's even worse, almost everything is internal.

Is there a simple way to do this? Or is it at least possible to make most of those things public?

Thanks
Esso

Activity

  1. changed the title [-]Host with multiple transports[/-] [+]Host with multiple transports having different auth types[/+] on Dec 9, 2020
  2. darkl commented on Dec 9, 2020

    @darkl
    Member

    It seems to me like the problem is that you have a single IWampSessionAuthenticatorFactory so apparently you can't use two authentication methods?
    But IWampSessionAuthenticatorFactory actually receives as an argument of the type WampPendingClientDetails so in theory we can just add the details about the underlying transport there and then you can choose your authenticator factory based on that?

    Elad

  3. esso23 commented on Dec 10, 2020

    @esso23
    Author

    Oh I didn't know it's sent in the arguments like that. That's very convenient. I actually have two separatate IWampSessionAuthenticatorFactorys so I created one Master factory which has a dictionary to switch the factory based on transport.
    Is there some list where all the transport strings are listed?

  4. darkl commented on Dec 10, 2020

    @darkl
    Member

    Can you attach here your master factory code please?
    For future reference and for understanding what you exactly did.

    Thanks
    Elad

  5. esso23 commented on Dec 10, 2020

    @esso23
    Author

    Well it does not work since the TransportDetails object is null.

    Screenshot 2020-12-10 22 58 16

  6. darkl commented on Dec 10, 2020

    @darkl
    Member
  7. esso23 commented on Dec 10, 2020

    @esso23
    Author

    I was thinking about it and in my opinion it's a hacky solution.
    Ideally we should be able to just attach IWampSessionAuthenticatorFactory to a binding just like it's done in WampAuthenticationHost and that would solve all the issues.
    In that case I would be able to not only have different authentication methods for multiple instances of the same transport, but even specify different authenticators for each binding on the same transport.

  8. darkl commented on Dec 11, 2020

    @darkl
    Member

    We'll have to change some api.

    // Allows to map different bindings to different authentication methods
    public void RegisterTransport(IWampTransport transport, IDictonary<IWampBinding, IWampSessionAuthenticatorFactory> bindingToAuthenticationFactory);

    If we remove the original overload:

    public void RegisterTransport(IWampTransport transport, IEnumerable<IWampBinding> bindings)

    this will break api and also won't allow WampAuthenticationHost to implement IWampHost. Another option is just to add a new class instead of WampAuthenticationHost that has this functionality. I'll have to do some refactoring tricks but this is doable.

    I also checked and authentication for crossbario is also defined per transport so we should probably support this.

  9. darkl commented on Jun 6, 2021

    @darkl
    Member

    Hi Esso,

    I just pushed a commit with this feature. Can you try it out? The version is 21.0.0-develop-33 from GitHub and the new class is called WampMultiAuthenticationHost.

    Usage:

    WampMultiAuthenticationHost host =
        new WampMultiAuthenticationHost();
    
    host.RegisterTransport(new FleckWebSocketTransport("ws://127.0.0.1:8080/ws"),
                           new Dictionary<IWampBinding, IWampSessionAuthenticatorFactory>()
                           {
                               {new JTokenJsonBinding(), new WampCraUserDbAuthenticationFactory(new MyAuthenticationProvider(), new MyUserDb())},
                               {new JTokenMessagePackBinding(), new MyAuthenticatorFactory()}
                           });

    Thanks
    Elad

  10. esso23 commented on Sep 29, 2021

    @esso23
    Author

    Hi Elad,
    sorry for answering so late. I tried this (using 21.0.0-develop-34) and it seems to work without any issues (I will do more testing in the following weeks).

    I propose adding another overload:

    void RegisterTransport(IWampTransport transport, IEnumerable<IWampBinding> bindings, IWampSessionAuthenticatorFactory sessionAuthenticatorFactory);

    Since it's likely going to be the most common use-case to add the same auth factory to all the bindings on the given transport.

  11. esso23 commented on Oct 25, 2021

    @esso23
    Author

    I did some tests in production environment with this and found no issues.

  12. darkl commented on Oct 25, 2021

    @darkl
    Member

    Great! I plan to release a new version of WampSharp at some point containing these changes and also the changes of #330, but it will take me some time unfortunately.

  13. esso23 commented on Feb 7, 2022

    @esso23
    Author

    Hi @darkl,
    any ETA on when we can expect this to be merged to master?

    Thanks,
    Esso

  14. darkl commented on Feb 7, 2022

    @darkl
    Member

    Hi Esso,

    I'm currently very busy. I'll have more time after March 15th.

    Elad

  15. esso23 commented on Feb 8, 2022

    @esso23
    Author

    Alright, we'll be patiently waiting then :)

  16. darkl commented on May 3, 2022

    @darkl
    Member

    Version 22.5.1 is now available on NuGet!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions