Skip to content

Commit eca5f62

Browse files
committed
chore: more docs and cleanups
1 parent 4248f11 commit eca5f62

File tree

10 files changed

+57
-16
lines changed

10 files changed

+57
-16
lines changed

src/agent/client/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Client implementations
2+
13
mod oauth2;
24
#[cfg(feature = "openid")]
35
mod openid;

src/agent/client/oauth2.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ pub struct LoginState {
2222
pub pkce_verifier: String,
2323
}
2424

25+
/// An OAuth2 based client implementation
2526
#[derive(Clone, Debug)]
2627
pub struct OAuth2Client {
27-
client: ::oauth2::basic::BasicClient,
28+
client: BasicClient,
2829
}
2930

3031
impl OAuth2Client {

src/agent/client/openid.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub struct OpenIdLoginState {
3333

3434
const DEFAULT_POST_LOGOUT_DIRECT_NAME: &str = "post_logout_redirect_uri";
3535

36+
/// An OpenID Connect based client implementation
3637
#[derive(Clone, Debug)]
3738
pub struct OpenIdClient {
3839
/// The client

src/agent/error.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
use crate::context::OAuth2Context;
22
use core::fmt::{Display, Formatter};
33

4+
/// An error with the OAuth2 agent
45
#[derive(Debug)]
56
pub enum OAuth2Error {
7+
/// Not initialized
68
NotInitialized,
9+
/// Configuration error
710
Configuration(String),
11+
/// Failed to start login
812
StartLogin(String),
13+
/// Failed to handle login result
914
LoginResult(String),
15+
/// Failing storing information
1016
Storage(String),
17+
/// Internal error
1118
Internal(String),
1219
}
1320

src/agent/mod.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! The Yew agent, working in the background to manage the session and refresh tokens.
1+
//! The agent, working in the background to manage the session and refresh tokens.
22
pub mod client;
33

44
mod config;
@@ -42,6 +42,28 @@ use yew::Callback;
4242
/// # let url = Url::parse("https://example.com").unwrap();
4343
/// let opts = LoginOptions::default().with_redirect_url(url);
4444
/// ```
45+
///
46+
/// ## Redirect & Post login redirect
47+
///
48+
/// By default, the login process will ask the issuer to redirect back the page that was active when starting the login
49+
/// process. In some cases, the issuer might require a more strict set of redirect URLs, and so can only redirect back
50+
/// to a single page. This can be enabled set setting a specific URL as `redirect_url`.
51+
///
52+
/// Once the user comes back from the login flow, which might actually be without any user interaction if the session
53+
/// was still valid, the user might find himself on the redirect page. Therefore, it is possible to forward/redirect
54+
/// the back to the original page, but only after the issuer redirected back the `redirect_url`. If, while starting the
55+
/// login process, the currently active URL differs from the `redirect_url`, the agent will store the "current" URL and
56+
/// redirect to it once the login process has completed.
57+
///
58+
/// However, there can be different ways to redirect, and there is no common one. One might think just setting a new
59+
/// location in the browser should work, but that would actually cause a page reload, and would then start the login
60+
/// process again.
61+
///
62+
/// Therefore, it is possible to set a "post login redirect callback", which will be triggered in such cases. Letting
63+
/// the user of the crate implement this logic. Having the `yew-nested-router` feature enabled, it is possible to just
64+
/// call [`LoginOptions::with_nested_router_redirect`] and let the router take care of this.
65+
///
66+
/// **NOTE:** The default is to do nothing. So the user would simply end up on the page defined by `redirect_url`.
4567
#[derive(Debug, Clone, Default)]
4668
#[non_exhaustive]
4769
pub struct LoginOptions {
@@ -135,6 +157,7 @@ impl LogoutOptions {
135157
}
136158
}
137159

160+
#[doc(hidden)]
138161
pub enum Msg<C>
139162
where
140163
C: Client,
@@ -145,6 +168,7 @@ where
145168
Refresh,
146169
}
147170

171+
/// The agent handling the OAuth2/OIDC state
148172
#[derive(Clone, Debug)]
149173
pub struct Agent<C>
150174
where
@@ -170,6 +194,7 @@ where
170194
}
171195
}
172196

197+
#[doc(hidden)]
173198
pub struct InnerAgent<C>
174199
where
175200
C: Client,
@@ -183,6 +208,7 @@ where
183208
timeout: Option<Timeout>,
184209
}
185210

211+
#[doc(hidden)]
186212
#[derive(Clone, Debug)]
187213
pub struct InnerConfig {
188214
scopes: Vec<String>,

src/agent/ops.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use super::{AgentConfiguration, Client, LoginOptions, LogoutOptions};
22
use std::fmt::{Display, Formatter};
33

4+
/// Operation error
45
#[derive(Clone, Debug)]
56
pub enum Error {
67
/// The agent cannot be reached.

src/components/redirect/location.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use gloo_utils::window;
55
use yew::prelude::*;
66

77
/// A redirector using the browser's location.
8-
pub struct LocationRedirector {}
8+
pub struct LocationRedirector;
99

1010
impl Redirector for LocationRedirector {
11-
type Properties = LocationProps;
11+
type Properties = LocationProperties;
1212

1313
fn new<COMP: Component>(_: &Context<COMP>) -> Self {
1414
Self {}
@@ -21,15 +21,17 @@ impl Redirector for LocationRedirector {
2121
}
2222

2323
#[derive(Clone, Debug, PartialEq, Properties)]
24-
pub struct LocationProps {
24+
pub struct LocationProperties {
25+
/// The content to show when being logged in.
2526
#[prop_or_default]
26-
pub children: Children,
27+
pub children: Html,
2728

29+
/// The logout URL to redirect to
2830
pub logout_href: String,
2931
}
3032

31-
impl RedirectorProperties for LocationProps {
32-
fn children(&self) -> &Children {
33+
impl RedirectorProperties for LocationProperties {
34+
fn children(&self) -> &Html {
3335
&self.children
3436
}
3537
}

src/components/redirect/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub trait Redirector: 'static {
1919
}
2020

2121
pub trait RedirectorProperties: yew::Properties {
22-
fn children(&self) -> &Children;
22+
fn children(&self) -> &Html;
2323
}
2424

2525
#[derive(Debug, Clone)]
@@ -104,7 +104,7 @@ where
104104
fn view(&self, ctx: &Context<Self>) -> Html {
105105
match self.auth {
106106
None => missing_context(),
107-
Some(OAuth2Context::Authenticated(..)) => html!({for ctx.props().children().iter()}),
107+
Some(OAuth2Context::Authenticated(..)) => ctx.props().children().clone(),
108108
_ => html!(),
109109
}
110110
}

src/components/redirect/router.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl<R> Redirector for RouterRedirector<R>
1717
where
1818
R: Target + 'static,
1919
{
20-
type Properties = RouterProps<R>;
20+
type Properties = RouterProperties<R>;
2121

2222
fn new<COMP: Component>(ctx: &Context<COMP>) -> Self {
2323
// while the "route" can change, the "router" itself does not.
@@ -43,21 +43,22 @@ where
4343
}
4444
}
4545

46+
/// Properties for the [`RouterRedirector`] component.
4647
#[derive(Clone, Debug, PartialEq, Properties)]
47-
pub struct RouterProps<R>
48+
pub struct RouterProperties<R>
4849
where
4950
R: Target + 'static,
5051
{
5152
#[prop_or_default]
52-
pub children: Children,
53+
pub children: Html,
5354
pub logout: R,
5455
}
5556

56-
impl<R> RedirectorProperties for RouterProps<R>
57+
impl<R> RedirectorProperties for RouterProperties<R>
5758
where
5859
R: Target + 'static,
5960
{
60-
fn children(&self) -> &Children {
61+
fn children(&self) -> &Html {
6162
&self.children
6263
}
6364
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//!
1111
//! ## Example
1212
//!
13-
//! **NOTE:** Also see the readme for more examples.
13+
//! **NOTE:** Also see the [readme](https://github.com/ctron/yew-oauth2/blob/main/README.md#examples) for more examples.
1414
//!
1515
//! The following is a basic example:
1616
//!

0 commit comments

Comments
 (0)