You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-07-29 22:01:14 +03:00
Better frontend assets handling and move the react app to /account/ (#1324)
This makes the Vite assets handling better, namely: - make it possible to include any vite assets in the templates - include the right `<link rel="preload">` tags for assets - include Subresource Integrity hashes - pre-compress assets and remove on-the-fly compression by the Rust server - build the CSS used by templates through Vite It also moves the React app from /app/ to /account/, and remove some of the old SSR account screens.
This commit is contained in:
@ -24,6 +24,7 @@ pub enum PostAuthAction {
|
||||
ContinueCompatSsoLogin { id: Ulid },
|
||||
ChangePassword,
|
||||
LinkUpstream { id: Ulid },
|
||||
ManageAccount,
|
||||
}
|
||||
|
||||
impl PostAuthAction {
|
||||
@ -48,6 +49,7 @@ impl PostAuthAction {
|
||||
Self::ContinueCompatSsoLogin { id } => CompatLoginSsoComplete::new(*id, None).go(),
|
||||
Self::ChangePassword => AccountPassword.go(),
|
||||
Self::LinkUpstream { id } => UpstreamOAuth2Link::new(*id).go(),
|
||||
Self::ManageAccount => Account.go(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -335,7 +337,7 @@ impl From<Option<PostAuthAction>> for Register {
|
||||
}
|
||||
}
|
||||
|
||||
/// `GET|POST /account/emails/verify/:id`
|
||||
/// `GET|POST /verify-email/:id`
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AccountVerifyEmail {
|
||||
id: Ulid,
|
||||
@ -367,19 +369,19 @@ impl AccountVerifyEmail {
|
||||
impl Route for AccountVerifyEmail {
|
||||
type Query = PostAuthAction;
|
||||
fn route() -> &'static str {
|
||||
"/account/emails/verify/:id"
|
||||
}
|
||||
|
||||
fn path(&self) -> std::borrow::Cow<'static, str> {
|
||||
format!("/account/emails/verify/{}", self.id).into()
|
||||
"/verify-email/:id"
|
||||
}
|
||||
|
||||
fn query(&self) -> Option<&Self::Query> {
|
||||
self.post_auth_action.as_ref()
|
||||
}
|
||||
|
||||
fn path(&self) -> std::borrow::Cow<'static, str> {
|
||||
format!("/verify-email/{}", self.id).into()
|
||||
}
|
||||
}
|
||||
|
||||
/// `GET /account/emails/add`
|
||||
/// `GET /add-email`
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct AccountAddEmail {
|
||||
post_auth_action: Option<PostAuthAction>,
|
||||
@ -388,7 +390,7 @@ pub struct AccountAddEmail {
|
||||
impl Route for AccountAddEmail {
|
||||
type Query = PostAuthAction;
|
||||
fn route() -> &'static str {
|
||||
"/account/emails/add"
|
||||
"/add-email"
|
||||
}
|
||||
|
||||
fn query(&self) -> Option<&Self::Query> {
|
||||
@ -404,28 +406,28 @@ impl AccountAddEmail {
|
||||
}
|
||||
}
|
||||
|
||||
/// `GET /account`
|
||||
/// `GET /account/`
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct Account;
|
||||
|
||||
impl SimpleRoute for Account {
|
||||
const PATH: &'static str = "/account";
|
||||
const PATH: &'static str = "/account/";
|
||||
}
|
||||
|
||||
/// `GET|POST /account/password`
|
||||
/// `GET /account/*`
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct AccountWildcard;
|
||||
|
||||
impl SimpleRoute for AccountWildcard {
|
||||
const PATH: &'static str = "/account/*rest";
|
||||
}
|
||||
|
||||
/// `GET|POST /change-password`
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct AccountPassword;
|
||||
|
||||
impl SimpleRoute for AccountPassword {
|
||||
const PATH: &'static str = "/account/password";
|
||||
}
|
||||
|
||||
/// `GET|POST /account/emails`
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct AccountEmails;
|
||||
|
||||
impl SimpleRoute for AccountEmails {
|
||||
const PATH: &'static str = "/account/emails";
|
||||
const PATH: &'static str = "/change-password";
|
||||
}
|
||||
|
||||
/// `GET /authorize/:grant_id`
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
// Copyright 2022, 2023 The Matrix.org Foundation C.I.C.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@ -14,6 +14,8 @@
|
||||
|
||||
//! Utility to build URLs
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
use ulid::Ulid;
|
||||
use url::Url;
|
||||
|
||||
@ -21,7 +23,8 @@ use crate::traits::Route;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct UrlBuilder {
|
||||
base: Url,
|
||||
http_base: Url,
|
||||
assets_base: Cow<'static, str>,
|
||||
issuer: Url,
|
||||
}
|
||||
|
||||
@ -30,21 +33,26 @@ impl UrlBuilder {
|
||||
where
|
||||
U: Route,
|
||||
{
|
||||
destination.absolute_url(&self.base)
|
||||
destination.absolute_url(&self.http_base)
|
||||
}
|
||||
|
||||
pub fn absolute_redirect<U>(&self, destination: &U) -> axum::response::Redirect
|
||||
where
|
||||
U: Route,
|
||||
{
|
||||
destination.go_absolute(&self.base)
|
||||
destination.go_absolute(&self.http_base)
|
||||
}
|
||||
|
||||
/// Create a new [`UrlBuilder`] from a base URL
|
||||
#[must_use]
|
||||
pub fn new(base: Url, issuer: Option<Url>) -> Self {
|
||||
pub fn new(base: Url, issuer: Option<Url>, assets_base: Option<String>) -> Self {
|
||||
let issuer = issuer.unwrap_or_else(|| base.clone());
|
||||
Self { base, issuer }
|
||||
let assets_base = assets_base.map_or(Cow::Borrowed("/assets/"), Cow::Owned);
|
||||
Self {
|
||||
http_base: base,
|
||||
assets_base,
|
||||
issuer,
|
||||
}
|
||||
}
|
||||
|
||||
/// OIDC issuer
|
||||
@ -107,6 +115,12 @@ impl UrlBuilder {
|
||||
self.url_for(&crate::endpoints::StaticAsset::new(path))
|
||||
}
|
||||
|
||||
/// Static asset base
|
||||
#[must_use]
|
||||
pub fn assets_base(&self) -> &str {
|
||||
&self.assets_base
|
||||
}
|
||||
|
||||
/// Upstream redirect URI
|
||||
#[must_use]
|
||||
pub fn upstream_oauth_callback(&self, id: Ulid) -> Url {
|
||||
|
Reference in New Issue
Block a user