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:
PopupApp
RedirectApp
The PopupApp
is a the default feature: if you want to use the RedirectApp
it is behind the redirect
feature:
msal_browser =
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:
const CLIENT_ID: &str = "CLIENT_ID";
const AUTHORITY: &str = "AUTHORITY";
// Setup App
let auth_options = new.set_authority;
let config = new;
let client_app = new;
// Define some scopes
let scopes = ;
// Login
let auth_res = client_app.login_popup.await.unwrap;
let auth_res = client_app.login_popup_with_scopes.await.unwrap;
// Account Info
let account = client_app.get_account_by_username.unwrap;
let account = client_app.get_account_by_home_id.unwrap;
let accounts = &client_app.get_all_accounts;
// Requests
let auth_request = new.set_login_hint;
let silent_request = new;
let end_session_request = new;
// SSO sign in
let sso_auth_result = client_app.sso_silent.await.unwrap;
// Popup token
let token = client_app.acquire_token_popup.await.unwrap;
// Silent token
let silent_token = client_app
.acquire_token_silent
.await
.unwrap;
// Logout
client_app.logout;
Example
There is an example app that uses the fantastic dominator dom library.
Approx file sizes in kb:
File | Debug | Release | Release + minified |
---|---|---|---|
wasm | 63 | 14 | 14 |
js | 363 | 363 | 113 |
The js file bundles the msal-browser.js
library.