davisvansant / auth0

MIT License
7 stars 3 forks source link

Rust and Web Assembly on Client #4

Open arn-the-long-beard opened 3 years ago

arn-the-long-beard commented 3 years ago

Hi !

Thank you for your Rust code :yum:

Well I found your project when I was looking for some rust code to get authentication for social medias. I have never used auth0 but I tested the default app in JS today and it seems simple and quick to use :smile: .

I need to handle multiple platform sign in for the App I am developing in Rust -> Web Assembly.

Here are my questions :

My objective is to write full Rust code and make js-free front end :smile: and I would like to not load any js at all.

Best regards,

Arn

davisvansant commented 3 years ago

Hi @arn-the-long-beard ... thanks for stopping by!

Hopefully I can help you get you to where you want to be, and note that this is still somewhat experimental (until we can get more people on board!) and that this currently uses the reqwest crate, which seems to have implemented some initial WASM functionality here - https://github.com/seanmonstar/reqwest/issues/288

With that being said, I just tested a few things locally:

- name: auth0 - wasm
  image: rust:1.47.0
  environment:
    RUST_BACKTRACE: full
  commands:
  - rustup target add wasm32-unknown-unknown
  - rustc --version
  - cargo --version
  - cargo check --workspace --target wasm32-unknown-unknown

Thats fine, we'll see if we can get past this (again, local testing):

fn build_client() -> Client {
        // static USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
        reqwest::Client::builder()
            // .user_agent(USER_AGENT)
            .build()
            .unwrap()
    }
drone exec .drone.yml --include "auth0 - wasm" 
[auth0 - wasm:0] + rustup target add wasm32-unknown-unknown
[auth0 - wasm:1] info: downloading component 'rust-std' for 'wasm32-unknown-unknown'
[auth0 - wasm:2] info: installing component 'rust-std' for 'wasm32-unknown-unknown'
[auth0 - wasm:3] info: Defaulting to 500.0 MiB unpack ram
[auth0 - wasm:4] + rustc --version
[auth0 - wasm:5] rustc 1.47.0 (18bf6b4f0 2020-10-07)
[auth0 - wasm:6] + cargo --version
[auth0 - wasm:7] cargo 1.47.0 (f3c7e066a 2020-08-28)
[auth0 - wasm:8] + cargo check --workspace --target wasm32-unknown-unknown
[auth0 - wasm:9]     Updating crates.io index
[auth0 - wasm:10]  Downloading crates ...
[auth0 - wasm:11]   Downloaded mime v0.3.16
[auth0 - wasm:12]   Downloaded pin-project-internal v0.4.26
[auth0 - wasm:13]   Downloaded proc-macro2 v1.0.24
[auth0 - wasm:14]   Downloaded quote v1.0.7
[auth0 - wasm:15]   Downloaded cc v1.0.60
[auth0 - wasm:16]   Downloaded serde_json v1.0.58
[auth0 - wasm:17]   Downloaded wasm-bindgen-futures v0.4.18
[auth0 - wasm:18]   Downloaded version_check v0.9.2
[auth0 - wasm:19]   Downloaded try-lock v0.2.3
[auth0 - wasm:20]   Downloaded socket2 v0.3.15
[auth0 - wasm:21]   Downloaded tokio-tls v0.3.1
[auth0 - wasm:22]   Downloaded slab v0.4.2
[auth0 - wasm:23]   Downloaded url v2.1.1
[auth0 - wasm:24]   Downloaded futures-task v0.3.6
[auth0 - wasm:25]   Downloaded bitflags v1.2.1
[auth0 - wasm:26]   Downloaded autocfg v1.0.1
[auth0 - wasm:27]   Downloaded hashbrown v0.9.1
[auth0 - wasm:28]   Downloaded futures-util v0.3.6
[auth0 - wasm:29]   Downloaded js-sys v0.3.45
[auth0 - wasm:30]   Downloaded lazy_static v1.4.0
[auth0 - wasm:31]   Downloaded log v0.4.11
[auth0 - wasm:32]   Downloaded openssl-sys v0.9.58
[auth0 - wasm:33]   Downloaded fnv v1.0.7
[auth0 - wasm:34]   Downloaded foreign-types v0.3.2
[auth0 - wasm:35]   Downloaded dtoa v0.4.6
[auth0 - wasm:36]   Downloaded futures-channel v0.3.6
[auth0 - wasm:37]   Downloaded matches v0.1.8
[auth0 - wasm:38]   Downloaded itoa v0.4.6
[auth0 - wasm:39]   Downloaded mime_guess v2.0.3
[auth0 - wasm:40]   Downloaded indexmap v1.6.0
[auth0 - wasm:41]   Downloaded net2 v0.2.35
[auth0 - wasm:42]   Downloaded pin-project v0.4.26
[auth0 - wasm:43]   Downloaded wasm-bindgen-macro v0.2.68
[auth0 - wasm:44]   Downloaded base64 v0.12.3
[auth0 - wasm:45]   Downloaded httpdate v0.3.2
[auth0 - wasm:46]   Downloaded memchr v2.3.3
[auth0 - wasm:47]   Downloaded serde_derive v1.0.116
[auth0 - wasm:48]   Downloaded pkg-config v0.3.18
[auth0 - wasm:49]   Downloaded unicase v2.6.0
[auth0 - wasm:50]   Downloaded ryu v1.0.5
[auth0 - wasm:51]   Downloaded tower-service v0.3.0
[auth0 - wasm:52]   Downloaded http-body v0.3.1
[auth0 - wasm:53]   Downloaded foreign-types-shared v0.1.1
[auth0 - wasm:54]   Downloaded pin-project-lite v0.1.10
[auth0 - wasm:55]   Downloaded cfg-if v0.1.10
[auth0 - wasm:56]   Downloaded bytes v0.5.6
[auth0 - wasm:57]   Downloaded unicode-xid v0.2.1
[auth0 - wasm:58]   Downloaded native-tls v0.2.4
[auth0 - wasm:59]   Downloaded percent-encoding v2.1.0
[auth0 - wasm:60]   Downloaded tinyvec v0.3.4
[auth0 - wasm:61]   Downloaded tracing-core v0.1.17
[auth0 - wasm:62]   Downloaded wasm-bindgen-backend v0.2.68
[auth0 - wasm:63]   Downloaded pin-utils v0.1.0
[auth0 - wasm:64]   Downloaded tokio-macros v0.2.5
[auth0 - wasm:65]   Downloaded want v0.3.0
[auth0 - wasm:66]   Downloaded serde_urlencoded v0.6.1
[auth0 - wasm:67]   Downloaded openssl-probe v0.1.2
[auth0 - wasm:68]   Downloaded tokio-util v0.3.1
[auth0 - wasm:69]   Downloaded ipnet v2.3.0
[auth0 - wasm:70]   Downloaded wasm-bindgen-shared v0.2.68
[auth0 - wasm:71]   Downloaded iovec v0.1.4
[auth0 - wasm:72]   Downloaded hyper-tls v0.4.3
[auth0 - wasm:73]   Downloaded futures-core v0.3.6
[auth0 - wasm:74]   Downloaded futures-sink v0.3.6
[auth0 - wasm:75]   Downloaded unicode-bidi v0.3.4
[auth0 - wasm:76]   Downloaded wasm-bindgen-macro-support v0.2.68
[auth0 - wasm:77]   Downloaded httparse v1.3.4
[auth0 - wasm:78]   Downloaded http v0.2.1
[auth0 - wasm:79]   Downloaded mio v0.6.22
[auth0 - wasm:80]   Downloaded unicode-normalization v0.1.13
[auth0 - wasm:81]   Downloaded reqwest v0.10.8
[auth0 - wasm:82]   Downloaded serde v1.0.116
[auth0 - wasm:83]   Downloaded tracing v0.1.21
[auth0 - wasm:84]   Downloaded bumpalo v3.4.0
[auth0 - wasm:85]   Downloaded hyper v0.13.8
[auth0 - wasm:86]   Downloaded h2 v0.2.6
[auth0 - wasm:87]   Downloaded wasm-bindgen v0.2.68
[auth0 - wasm:88]   Downloaded openssl v0.10.30
[auth0 - wasm:89]   Downloaded idna v0.2.0
[auth0 - wasm:90]   Downloaded syn v1.0.42
[auth0 - wasm:91]   Downloaded tokio v0.2.22
[auth0 - wasm:92]   Downloaded libc v0.2.79
[auth0 - wasm:93]   Downloaded encoding_rs v0.8.24
[auth0 - wasm:94]   Downloaded web-sys v0.3.45
[auth0 - wasm:95]     Checking auth0 v0.3.0 (/drone/src)
[auth0 - wasm:96]     Finished dev [unoptimized + debuginfo] target(s) in 28.37s

It looks like we may be able to get there for you, and it would be an absolutely fantastic test to see if we can get it going in WASM (TBH I didnt think about that in the initial build) with a few options (maybe more?)

Your thoughts and input is much appreciated!

arn-the-long-beard commented 3 years ago

Hello mate !!

Sorry for so long time for answering. I have been so busy with project management :smile:

Thank you so much for your message, your research and explanations!

Got some ideas as well :smiley:

I think we could have a CustomClient with trait as an abstraction so people can actually choose their HttpClient to make request.

The Arangodb Driver that I contributed a bit arangors uses this technique and the feature gate as well with it.

https://github.com/fMeow/arangors/blob/master/src/client/mod.rs

Do you think we could do the same here ?

The other requirement is that I cannot use Reqwest, because we have a smaller HttpClient in Seed in order to reduce the size of the generated package.

I will look when I can actually make a PR for it, if you think it can be a good idea.

davisvansant commented 3 years ago

Hi @arn-the-long-beard! I havent forgotten about you, and I appreciate your patience here!

If I am understanding correctly, it sounds like we are looking to adjust the

 fn build_client() -> Client {
        static USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
        reqwest::Client::builder()
            .user_agent(USER_AGENT)
            .build()
            .unwrap()
    }
}

area of this library (found here)

specifically to potentially consume other libraries like surf and/or adjust for wasm functionality within reqwest? (and to be clear, I'm all for this)

Your ideas and input is much appreciated, and more than welcomed! If we do go down this route, I'd recommend we start with the working implementation using reqwest, get that solid, then move on to others, opening new issues and PRs as needed. I only mention that because much of this library is hardcoded and built to consume reqwest exclusively, as I wanted to focus more on the "ease of use" vs worrying about which libraries and method(s) to use with specific requests (which may need to be adjusted as we move forward - wasm wasnt even on my mind initially here).

Also, as I review this, I also see that reqwest is a hard stop for you due to library size (so the above may not pan out, and we might need to focus on getting something like surf going first)? I'm also reading up on seed, as its something I'm unfamiliar with.

If its ok, I also wanted to bring others in who have initially expressed some interest here - they may be able to provide some valuable insight as well!

@uwueviee @mcountryman

Thank you!

arn-the-long-beard commented 3 years ago

Hello @davisvansant

Thank you for your message !

I'd recommend we start with the working implementation using reqwest, get that solid, then move on to others, opening new issues and PRs as needed. I only mention that because much of this library is hardcoded and built to consume reqwest exclusively, as I wanted to focus more on the "ease of use" vs worrying about which libraries and method(s) to use with specific requests (which may need to be adjusted as we move forward -

You are right to prioritize on ease of use and make it work first :+1:

It seems we have a plan !

1 - Make it work with Request 2 - Identify Traits and Implementation we could extract/abstract to build a CustomClient trait to implement for other libraries 3 - Make feature gate and add new custom clients

to potentially consume other libraries like surf and/or adjust for wasm functionality within reqwest? (and to be clear, I'm all for this)

Yes this is exactly what I am looking for :smile: It is good to know :+1:

wasm wasnt even on my mind initially here

I understand completely. I think Wasm is pushing Rust into many new places and is challenging the language and its existing ecosystem from more traditional usages of it to new ones. Also Wasm is very specific and fresh, so I fully understand that the library was not planned for this at first thought :wink: . I know it since June as well and it did challenge my conception of the Web.

Thank you for inviting new persons to the discussion !

davisvansant commented 3 years ago

So for some more ramblings...

I spent some time last night digging a bit more into wasm, seed, surf, reqwest, etc - from my understanding (please feel free to correct me if I'm wrong and/or missing anything), if we are specifically targeting wasm, they all consume and use the same exact underlying libraries and implementations, namely (not exhaustive)

If I am looking at seed correctly, it has its own implementation (fetch), surf has multiple feature flags (my preference towards hyper while not targeting wasm), with reqwest defaulting to hyper while targeting wasm enabling wasm specific dependencies (transparently).

The bottom line for me (from my understanding)

Sorry if this is all a bit long winded, I'm just trying to avoid any unnecessary implementations and flags/etc that really point us back to the exact same place

There however may be some things I'm missing here and/or not fully realizing as we move this forward and come to a mutual understanding, and as always, really appreciate your input and feedback here!

Thank you so much!

arn-the-long-beard commented 3 years ago

Hello !

Thank you for your message !

I come very late because I have been more busy than expected :smile:

if we are specifically targeting wasm, they all consume and use the same exact underlying libraries and implementations

Yes, it is actually using https://github.com/rustwasm/wasm-bindgen

Sorry if this is all a bit long winded, I'm just trying to avoid any unnecessary implementations and flags/etc that really point us back to the exact same place

There however may be some things I'm missing here and/or not fully realizing as we move this forward and come to a mutual understanding, and as always, really appreciate your input and feedback here!

Do not be sorry, we need to do what we need to do :wink:

I need to look more at your library to be able to give you more feedback :smile:

It might be a solution to have a specific library for wasm as you mention since, the constraints regarding the code are different than on back_end ( different clients, size matters a lot .. etc ...)

nirvdrum commented 1 year ago

I've just tried to make use of this crate in a Yew application and ran into the issue where user_agent can't be called when building the reqwest client. Is this the only limitation? I don't mind using reqwest as the HTTP client. It looks like that got mixed in with the discussion about supporting WASM.