Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Host with multiple transports having different auth types #328

Closed
esso23 opened this issue Dec 9, 2020 · 15 comments
Closed

Host with multiple transports having different auth types #328

esso23 opened this issue Dec 9, 2020 · 15 comments

Comments

@esso23
Copy link

esso23 commented Dec 9, 2020

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

@esso23 esso23 changed the title Host with multiple transports Host with multiple transports having different auth types Dec 9, 2020
@darkl
Copy link
Member

darkl commented Dec 9, 2020

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

@esso23
Copy link
Author

esso23 commented Dec 10, 2020

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?

@darkl
Copy link
Member

darkl commented Dec 10, 2020

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

Thanks
Elad

@esso23
Copy link
Author

esso23 commented Dec 10, 2020

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

Screenshot 2020-12-10 22 58 16

@darkl
Copy link
Member

darkl commented Dec 10, 2020 via email

@esso23
Copy link
Author

esso23 commented Dec 10, 2020

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.

@darkl
Copy link
Member

darkl commented Dec 11, 2020

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.

@darkl
Copy link
Member

darkl commented Jun 6, 2021

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

@esso23
Copy link
Author

esso23 commented Sep 29, 2021

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.

@esso23
Copy link
Author

esso23 commented Oct 25, 2021

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

@darkl
Copy link
Member

darkl commented Oct 25, 2021

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.

@esso23
Copy link
Author

esso23 commented Feb 7, 2022

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

Thanks,
Esso

@darkl
Copy link
Member

darkl commented Feb 7, 2022

Hi Esso,

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

Elad

@esso23
Copy link
Author

esso23 commented Feb 8, 2022

Alright, we'll be patiently waiting then :)

@darkl
Copy link
Member

darkl commented May 3, 2022

Version 22.5.1 is now available on NuGet!

@darkl darkl closed this as completed May 3, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants