Skip to content
Open
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
4 changes: 3 additions & 1 deletion apps/auth-service/src/web/admin/tests/sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,9 @@ async fn only_administrators_signed_in_with_a_passkey_are_handed_off() {
csp.contains(&format!("form-action 'self' {DASHBOARD}")),
"{csp}"
);
let page = social.visit(&harness.auth.a, routes::page::LOGIN).await;
let elsewhere = format!("{}?acr=phr", routes::page::LOGIN);
let page = social.visit(&harness.auth.a, &elsewhere).await;
assert_eq!(page.status(), StatusCode::OK);
assert!(!policy(&page).contains(DASHBOARD), "only on its way there");
}

Expand Down
33 changes: 30 additions & 3 deletions apps/auth-service/src/web/auth/login/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
//!
//! Neither is an [`AccountPage`](crate::web::account::AccountPage): they serve browsers
//! that are not signed in. Their `GET` finds the [`Step`] the browser is at, from
//! the query, the provider's sign-in pending in the browser and its session. Their
//! the query, the provider's sign-in pending in the browser and its session; `/login`
//! sends a browser already signed in straight on, when it would only ask it to sign
//! in again ([`Continuation::skipped`]). Their
//! `POST` makes the change its form names, then sends the browser where the
//! [`Continuation`] says, which the server alone decides. A change the service
//! refuses renders the page again, saying why.
Expand Down Expand Up @@ -131,6 +133,24 @@ impl Continuation {
}
}

/// Where a browser at `step` goes at once, without the page: the path, when it is
/// already signed in, as from sourceorigin.dev's Sign in link. `None` for an
/// authorization, which sends a browser here only when its session falls short,
/// and whenever the query asks for a class of authentication, `target_acr`, as the
/// dashboard's handoff does.
fn skipped(&self, step: &Step<'_>, target_acr: Option<Acr>) -> Option<&ReturnTo> {
match (self, step, target_acr) {
(
Self::Path(path),
Step::SignIn {
signed_in: Some(_), ..
},
None,
) => Some(path),
_ => None,
}
}

/// The pending authorization it continues, if any, as the sign-in page sees it.
async fn authorization(
&self,
Expand Down Expand Up @@ -367,7 +387,7 @@ impl WebApplication {
(see_other(next).into_response(cx)?, cookie)
}
// An explicit link goes back to where it started; an email match offers
// to sign in before going on.
// a signed-out browser to sign in before going on.
LoginChange::CancelLink {} => {
let pending = visit
.pending
Expand Down Expand Up @@ -609,7 +629,8 @@ impl WebApplication {
}

/// Renders the sign-in page `page` at the step the `visit` finds, at `refused`'s
/// status and saying why, if anything was. Its forms may redirect to the
/// status and saying why, if anything was, or sends a browser already signed in
/// on when the page has nothing more to ask of it. Its forms may redirect to the
/// providers, to the application whose authorization the sign-in continues,
/// and through auth's handoff to the admin dashboard; an authorization that is
/// unknown or expired explains itself.
Expand Down Expand Up @@ -697,6 +718,12 @@ impl WebApplication {
.as_ref()
.map(|error| error.public().1)
.or_else(|| query.error.map(CallbackError::message));
// The page stays when it says why something failed.
if alert.is_none()
&& let Some(path) = continuation.skipped(&step, target_acr)
{
return Ok(see_other(path.as_str()).into_response(cx)?);
}
let kept = continuation.on(LoginQuery {
error: None,
linked: None,
Expand Down
27 changes: 22 additions & 5 deletions apps/auth-service/src/web/auth/login/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use axum::http::{StatusCode, header};
use sourceorigin_common::{
AuthenticationMethod, Provider, UserId,
clients::{ClientKind, ClientRegistration},
protocol::claims::Acr,
};
use sourceorigin_crypto::Secret;
use sourceorigin_repository::{Database, PendingFederation};
Expand Down Expand Up @@ -189,7 +190,8 @@ async fn signing_in_offers_passkeys_providers_and_a_handle() {

/// Once the passkey script signed the browser in, its form sends it on to the path
/// on auth it asked for, or to the settings when it asked for none or for another
/// site. A browser already signed in is told to which account, and may sign out
/// site. A browser already signed in goes there at once, unless the page asks for
/// a class of authentication: it is then told to which account, and may sign out
/// first.
#[tokio::test]
#[ignore = "requires TEST_DATABASE_URL"]
Expand All @@ -199,9 +201,6 @@ async fn signing_in_goes_on_to_the_path_asked_for() {
let browser = Browser::new_account(&database).await;
let account = database.users().find_by_id(browser.user_id).await;
let handle = account.expect("account").expect("active").handle;
let page = html(browser.visit(&replicas.a, LOGIN).await).await;
assert!(page.contains(&format!("Signed in as @{handle}.")), "{page}");
assert!(page.contains(">Sign out</button>"), "{page}");
for (return_to, to) in [
(Some(settings::SESSIONS), settings::SESSIONS),
(Some("https://evil.example"), settings::HOME),
Expand All @@ -211,12 +210,30 @@ async fn signing_in_goes_on_to_the_path_asked_for() {
return_to: return_to.map(str::to_owned),
..LoginQuery::default()
};
let here = link(LOGIN, &query);
let opened = browser.visit(&replicas.a, &here).await;
assert_eq!(opened.status(), StatusCode::SEE_OTHER, "{return_to:?}");
assert_eq!(redirect(&opened), to, "{return_to:?}");
let signed_in = browser
.post(&replicas, &link(LOGIN, &query), &LoginChange::SignedIn {})
.post(&replicas, &here, &LoginChange::SignedIn {})
.await;
assert_eq!(signed_in.status(), StatusCode::SEE_OTHER, "{return_to:?}");
assert_eq!(redirect(&signed_in), to, "{return_to:?}");
}
let passkey = LoginQuery {
acr: Some(Acr::PhishingResistant),
..LoginQuery::default()
};
let page = html(browser.visit(&replicas.a, &link(LOGIN, &passkey)).await).await;
assert!(page.contains(&format!("Signed in as @{handle}.")), "{page}");
assert!(page.contains(">Sign out</button>"), "{page}");
// A page saying why something failed stays, as for a provider's sign-in gone.
let gone = waiting(PendingDestination::Link, settings::SESSIONS);
let page = html(browser.visit(&replicas.a, &gone).await).await;
assert!(
page.contains("No provider sign-in is waiting in this browser. Please start again."),
"{page}"
);
}

/// Signing in for an application lets the page's forms redirect on to it, and its
Expand Down
5 changes: 4 additions & 1 deletion docs/dev/rust-conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ browsers, so they are pages of their own rather than `AccountPage`s. Their query
every link to them; it
parses field by field, so a bad value drops only itself, never the `transaction` or
`return_to` it continues. One `Step` comes from the query, the pending social sign-in and the
session: signing in, signing up, or linking a provider. The server decides where a
session: signing in, signing up, or linking a provider. A browser already signed in
that `/login` would only ask to sign in again goes on to its path at once, unless the
page says why something failed, or an authorization or the query's `acr` asks more of
its session. The server decides where a
sign-in continues, an authorization or a path, renders it into each form's action,
and answers the form with it: an authorization continues in-process and goes on
through the onward page when no policy can name its client. A provider's sign-in for
Expand Down
3 changes: 2 additions & 1 deletion docs/user/account/signing-in.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ You need an Origin Account. If you don't have one yet, see
unlock the passkey with your fingerprint, face or PIN.

Origin Auth signs you in and goes on to where you were headed: the app, or your
settings.
settings. If you are already signed in, as when you select **Sign in** on
sourceorigin.dev, it goes there at once.

If your passkey is on a security key or another device, choose that option in
your browser's prompt.
Expand Down
2 changes: 2 additions & 0 deletions tests/browser/layout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ test('the settings and sign-in pages fit every window size', async ({ browser })
}
}
}
// Signed in, /login goes on to the settings: sign out to see it.
await page.context().clearCookies();
await page.goto('/login');
for (const viewport of viewports) {
await page.setViewportSize(viewport);
Expand Down