Skip to content

Commit

Permalink
chore: fix up examples after refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Jan 26, 2024
1 parent 9247002 commit aa7eb5a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 37 deletions.
16 changes: 6 additions & 10 deletions yew-oauth2-example/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,14 @@ pub fn content() -> Html {
#[function_component(Application)]
pub fn app() -> Html {
#[cfg(not(feature = "openid"))]
let config = Config {
client_id: "example".into(),
auth_url: "http://localhost:8081/realms/master/protocol/openid-connect/auth".into(),
token_url: "http://localhost:8081/realms/master/protocol/openid-connect/token".into(),
};
let config = Config::new(
"example",
"http://localhost:8081/realms/master/protocol/openid-connect/auth",
"http://localhost:8081/realms/master/protocol/openid-connect/token",
);

#[cfg(feature = "openid")]
let config = Config {
client_id: "example".into(),
issuer_url: "http://localhost:8081/realms/master".into(),
additional: Default::default(),
};
let config = Config::new("example", "http://localhost:8081/realms/master");

let mode = if cfg!(feature = "openid") {
"OpenID Connect"
Expand Down
45 changes: 18 additions & 27 deletions yew-oauth2-redirect-example/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,12 @@ pub enum AuthenticatedRoute {
pub fn content() -> Html {
let agent = use_auth_agent().expect("Requires OAuth2Context component in parent hierarchy");

let login = {
let agent = agent.clone();
Callback::from(move |_: MouseEvent| {
if let Err(err) = agent.start_login() {
log::warn!("Failed to start login: {err}");
}
})
};
let logout = Callback::from(move |_: MouseEvent| {
let login = use_callback(agent.clone(), |_, agent| {
if let Err(err) = agent.start_login() {
log::warn!("Failed to start login: {err}");
}
});
let logout = use_callback(agent, |_, agent| {
if let Err(err) = agent.logout() {
log::warn!("Failed to logout: {err}");
}
Expand Down Expand Up @@ -119,26 +116,20 @@ pub fn content() -> Html {
#[function_component(Application)]
pub fn app() -> Html {
#[cfg(not(feature = "openid"))]
let config = Config {
client_id: "example".into(),
auth_url: "http://localhost:8081/realms/master/protocol/openid-connect/auth".into(),
token_url: "http://localhost:8081/realms/master/protocol/openid-connect/token".into(),
};
let config = Config::new(
"example",
"http://localhost:8081/realms/master/protocol/openid-connect/auth",
"http://localhost:8081/realms/master/protocol/openid-connect/token",
);

#[cfg(feature = "openid")]
let config = Config {
client_id: "example".into(),
issuer_url: "http://localhost:8081/realms/master".into(),
additional: Additional {
/*
Set the after logout URL to a public URL. Otherwise, the SSO server will redirect
back to the current page, which is detected as a new session, and will try to login
again, if the page requires this.
*/
after_logout_url: Some("/".into()),
..Default::default()
},
};
let config = Config::new("example", "http://localhost:8081/realms/master")
/*
Set the after logout URL to a public URL. Otherwise, the SSO server will redirect
back to the current page, which is detected as a new session, and will try to log in
again, if the page requires this.
*/
.with_after_logout_url(Some("/".into()));

let mode = if cfg!(feature = "openid") {
"OpenID Connect"
Expand Down

0 comments on commit aa7eb5a

Please sign in to comment.