Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add default LoginOptions to OAuth2 #19

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/agent/config.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use crate::agent::Client;
use std::time::Duration;

use super::LoginOptions;

#[derive(Clone, Debug)]
pub struct AgentConfiguration<C: Client> {
pub config: C::Configuration,
pub scopes: Vec<String>,
pub grace_period: Duration,
pub audience: Option<String>,
pub options: Option<LoginOptions>,
}

impl<C: Client> PartialEq for AgentConfiguration<C> {
Expand Down
7 changes: 7 additions & 0 deletions src/agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub struct InnerConfig {
scopes: Vec<String>,
grace_period: Duration,
audience: Option<String>,
options: Option<LoginOptions>,
}

impl<C> InnerAgent<C>
Expand Down Expand Up @@ -230,6 +231,7 @@ where
scopes: config.scopes,
grace_period: config.grace_period,
audience: config.audience,
options: config.options,
};

Ok((client, inner))
Expand Down Expand Up @@ -418,6 +420,11 @@ where
let mut login_url = login_context.url;

login_url.query_pairs_mut().extend_pairs(options.query);
if let Some(options) = &config.options {
login_url
.query_pairs_mut()
.extend_pairs(options.query.clone());
}

// the next call will most likely navigate away from this page

Expand Down
6 changes: 6 additions & 0 deletions src/components/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod agent;
pub use agent::*;

use crate::context::LatestAccessToken;
use crate::prelude::LoginOptions;
use crate::{
agent::{AgentConfiguration, Client, OAuth2Operations},
context::OAuth2Context,
Expand Down Expand Up @@ -36,6 +37,10 @@ pub struct Props<C: Client> {
/// Children which will have access to the [`OAuth2Context`].
#[prop_or_default]
pub children: Children,

/// Default [`LoginOptions`] that will be used for every request
#[prop_or_default]
pub options: Option<LoginOptions>,
}

impl<C: Client> PartialEq for Props<C> {
Expand Down Expand Up @@ -130,6 +135,7 @@ impl<C: Client> OAuth2<C> {
scopes: props.scopes.clone(),
grace_period: props.grace_period,
audience: props.audience.clone(),
options: props.options.clone(),
}
}
}
Expand Down