Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

External authentification provider #98

Open
s18alg opened this issue Apr 20, 2020 · 6 comments
Open

External authentification provider #98

s18alg opened this issue Apr 20, 2020 · 6 comments
Labels

Comments

@s18alg
Copy link

s18alg commented Apr 20, 2020

Hi everyone

I am trying to use an external api as the authentification provider to allow or deny websocket connection to my system.

I want to pass some of the websocket creation request from the client to the api, and my current code looks like:

    let auth_middleware_callback = |req: &Request, res: Response| {
        let task = client.on_connect(req.headers().get("Authorization");); // This is an async method wrapping around the hyper http client
        Ok(res)
    };
    let ws_stream = tokio_tungstenite::accept_hdr_async(raw_stream, auth_middleware_callback)

My issue is that I don't get how I can make the auth_middleware_callback an async closure (I get a compiler error saying they are not supported yet) and the lib give my some big type missmatch error if I try to feed it an async function.

I feel like I am missing something here, as the accept_hdr_async feels quite tailored for local authentification, but I don't see how to adapt it to my use case.

Thank you and have a nice day

@daniel-abramov
Copy link
Member

Do you have a SSCCE? I may be wrong, but it might be related to #29

let task = client.on_connect(req.headers().get("Authorization");); // This is an async method wrapping around the hyper http client

But if it's an async method, then you would probably have to block at that point, waiting for it to complete (that may or may not be the desirable effect).

@s18alg
Copy link
Author

s18alg commented May 2, 2020

On second read, it is indeed related to #29.
I also think it's the same need that inspired #51 (Which I almost implemented but don't like how verbose this solution is)

I ended up using a blocking http request to make my prototype run, but as the other issue pointed out, I kinda think tokio-tungstenite could use some future based authentification process that would suite me better.

I took a look at the code and I think I'll have time to contribute some code next week.

@daniel-abramov
Copy link
Member

I kinda think tokio-tungstenite could use some future based authentification process that would suite me better.

That indeed would be very useful as it would allow to "inject" some middleware at this stage.

@s18alg
Copy link
Author

s18alg commented Jun 17, 2020

So I finally found some time to dig this issue, and there is indeed some work needed on tungstenite itself to make it process an async callback.

@sammoh94
Copy link

Also running into this issue. Has there been any progress on this?

@s18alg
Copy link
Author

s18alg commented Mar 23, 2021

From what I have been reading on other issue, no
From my investigation at the time, this is an issue related to tungstenite as the core lib reject async function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants