Rust + WASM + msal-browser

Rust wrapper for msal-browser.js.

Methods names all match the js but with snake case, but unlike the js instead of a single PublicClientApplication type there are two app types:

The PopupApp is a the default feature: if you want to use the RedirectApp it is behind the redirect feature:

rust msal_browser = { version = "0.2.0", features = ["redirect"] }

There are a huge amount of Configuration options so the rust side uses a builder pattern. You can also use a js Object and call Configuration::unchecked_from.

To use:

```rust const CLIENTID: &str = "CLIENTID"; const AUTHORITY: &str = "AUTHORITY";

// Setup App let authoptions = BrowserAuthOptions::new(CLIENTID).setauthority(AUTHORITY); let config = Configuration::new(authoptions); let client_app = PopupApp::new(config);

// Define some scopes let scopes = ["User.Read"];

// Login let authres = clientapp.loginpopup().await.unwrap(); let authres = clientapp.loginpopupwithscopes(&scopes).await.unwrap();

// Account Info let account = clientapp.getaccountbyusername("username").unwrap(); let account = clientapp.getaccountbyhomeid("homeid").unwrap(); let accounts = &clientapp.getall_accounts();

// Requests let authrequest = AuthorizationUrlRequest::new(&scopes[..]).setloginhint(account.username()); let silentrequest = SilentRequest::new(&scopes[..], &account); let endsessionrequest = EndSessionRequest::new();

// SSO sign in let ssoauthresult = clientapp.ssosilent(&auth_request).await.unwrap();

// Popup token let token = clientapp.acquiretokenpopup(&authrequest).await.unwrap();

// Silent token let silenttoken = clientapp .acquiretokensilent(&silent_request) .await .unwrap();

// Logout client_app.logout(None); ```

Example

There is an example app that uses the fantastic dominator dom library.

Tests

Curently there are tests that can be run using ./run_tests.sh or wasm-pack test --safari --headless -- --features "popup redirect

Notes

Needs node installed to build. Currently published to crates.io using --no-verify: this is because the build.rs requires all the node modules installed to run successfully and is modifying files outside of OUT_DIR for buildng the js. Since version 2.12 they switched to using preserveModules = true 3563 which means that the old index.es.js file doesn't exist and instead modules imports are left. So now I am using Rollup to generate the required file to link to in rust with bindgen.