Add openidconnect authentication demo (#1500)
* Add openidconnect authentication demo * use_atom_ref usage to have a read/write handle on the atom * Use default * Code rewrite to better reflect the authentication flow * Use the env macro instead of the build.rs to load env variables * Add env variables * Remove unnecessary dependency * Add env variables to the root workspace * Update readme * Bump openidconnect version * Use props to pass the client to the child components * Code clean up --------- Co-authored-by: Truong Tan Dat <truongt@igbmc.fr>
This commit is contained in:
1 parent
1cf8f71368
commit
b836851d02
21 files changed
+736
No files matched your search
@@ -0,0 +1,38 @@
|
||||
use fermi::UseAtomRef;
|
||||
use gloo_storage::{LocalStorage, Storage};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
constants::{DIOXUS_FRONT_AUTH_REQUEST, DIOXUS_FRONT_AUTH_TOKEN},
|
||||
oidc::{AuthRequestState, AuthTokenState},
|
||||
};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
pub struct StorageEntry<T> {
|
||||
pub key: String,
|
||||
pub value: T,
|
||||
}
|
||||
|
||||
pub trait PersistentWrite<T: Serialize + Clone> {
|
||||
fn persistent_set(atom_ref: &UseAtomRef<Option<T>>, entry: Option<T>);
|
||||
}
|
||||
|
||||
impl PersistentWrite<AuthTokenState> for AuthTokenState {
|
||||
fn persistent_set(
|
||||
atom_ref: &UseAtomRef<Option<AuthTokenState>>,
|
||||
entry: Option<AuthTokenState>,
|
||||
) {
|
||||
*atom_ref.write() = entry.clone();
|
||||
LocalStorage::set(DIOXUS_FRONT_AUTH_TOKEN, entry).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
impl PersistentWrite<AuthRequestState> for AuthRequestState {
|
||||
fn persistent_set(
|
||||
atom_ref: &UseAtomRef<Option<AuthRequestState>>,
|
||||
entry: Option<AuthRequestState>,
|
||||
) {
|
||||
*atom_ref.write() = entry.clone();
|
||||
LocalStorage::set(DIOXUS_FRONT_AUTH_REQUEST, entry).unwrap();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user