mirror of
https://github.com/Jackzmc/storage.git
synced 2025-05-05 20:53:21 +00:00
Add sso button on login if enabled
This commit is contained in:
parent
8f69de989b
commit
a839501168
4 changed files with 29 additions and 7 deletions
15
README.md
15
README.md
|
@ -33,7 +33,12 @@ _The current files list when logged in_
|
||||||
git clone https://github.com/jackzmc/storage.git
|
git clone https://github.com/jackzmc/storage.git
|
||||||
cd storage
|
cd storage
|
||||||
|
|
||||||
# Configure your database (create .env file with your PostgreSQL connection)
|
# Copy the sample config
|
||||||
|
cp config.sample.toml config.toml
|
||||||
|
# Edit the config.toml or provide the equivalant settings with env
|
||||||
|
# ex: [auth.oidc] ---> STORAGE_auth.oidc.issuer__url
|
||||||
|
# issuer-url
|
||||||
|
# Configure your database (requires to be set by env for now)
|
||||||
echo "DATABASE_URL=postgres://username:password@localhost" > .env
|
echo "DATABASE_URL=postgres://username:password@localhost" > .env
|
||||||
|
|
||||||
# Build the project
|
# Build the project
|
||||||
|
@ -52,12 +57,18 @@ Rough roadmap in a rough order of priority
|
||||||
|
|
||||||
* [ ] WebDAV Support
|
* [ ] WebDAV Support
|
||||||
* [ ] Email support (for password resets, user invites)
|
* [ ] Email support (for password resets, user invites)
|
||||||
|
* [ ] Email sender utility
|
||||||
|
* [ ] Individual email actions
|
||||||
* [ ] SSO Support (openid)
|
* [ ] SSO Support (openid)
|
||||||
|
* [x] Basic implementation
|
||||||
|
* [ ] User mapping
|
||||||
|
* [ ] User creation
|
||||||
|
* [ ] User logout
|
||||||
|
* [ ] S3 backend support
|
||||||
* [ ] Administration panel
|
* [ ] Administration panel
|
||||||
* [ ] Add storage backends
|
* [ ] Add storage backends
|
||||||
* [ ] Manage users
|
* [ ] Manage users
|
||||||
* [ ] Change app settings
|
* [ ] Change app settings
|
||||||
* [ ] S3 backend support
|
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ use std::collections::HashMap;
|
||||||
use std::env::var;
|
use std::env::var;
|
||||||
use figment::Figment;
|
use figment::Figment;
|
||||||
use figment::providers::{Env, Format, Toml};
|
use figment::providers::{Env, Format, Toml};
|
||||||
use log::error;
|
use log::{debug, error};
|
||||||
use openidconnect::core::{CoreClient, CoreProviderMetadata};
|
use openidconnect::core::{CoreClient, CoreProviderMetadata};
|
||||||
use openidconnect::IssuerUrl;
|
use openidconnect::IssuerUrl;
|
||||||
use openidconnect::url::Url;
|
use openidconnect::url::Url;
|
||||||
|
@ -55,6 +55,12 @@ pub struct AuthConfig {
|
||||||
pub oidc: Option<OidcConfig>,
|
pub oidc: Option<OidcConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AuthConfig {
|
||||||
|
pub fn oidc_enabled(&self) -> bool {
|
||||||
|
self.oidc.as_ref().map(|o| o.enabled).unwrap_or(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
#[serde(rename_all = "kebab-case")]
|
#[serde(rename_all = "kebab-case")]
|
||||||
pub struct OidcConfig {
|
pub struct OidcConfig {
|
||||||
|
|
|
@ -6,6 +6,7 @@ use rocket::http::{Header, Status};
|
||||||
use rocket_dyn_templates::{context, Template};
|
use rocket_dyn_templates::{context, Template};
|
||||||
use rocket_session_store::Session;
|
use rocket_session_store::Session;
|
||||||
use crate::{GlobalMetadata, LoginSessionData, SessionData, DB};
|
use crate::{GlobalMetadata, LoginSessionData, SessionData, DB};
|
||||||
|
use crate::config::AppConfig;
|
||||||
use crate::consts::{APP_METADATA, DISABLE_LOGIN_CHECK};
|
use crate::consts::{APP_METADATA, DISABLE_LOGIN_CHECK};
|
||||||
use crate::models::user::validate_user_form;
|
use crate::models::user::validate_user_form;
|
||||||
use crate::routes::ui::auth::HackyRedirectBecauseRocketBug;
|
use crate::routes::ui::auth::HackyRedirectBecauseRocketBug;
|
||||||
|
@ -16,7 +17,8 @@ pub async fn page(
|
||||||
route: &Route,
|
route: &Route,
|
||||||
session: Session<'_, SessionData>,
|
session: Session<'_, SessionData>,
|
||||||
return_to: Option<String>,
|
return_to: Option<String>,
|
||||||
logged_out: Option<bool>
|
logged_out: Option<bool>,
|
||||||
|
settings: &State<AppConfig>,
|
||||||
) -> Template {
|
) -> Template {
|
||||||
// TODO: redirect if already logged in
|
// TODO: redirect if already logged in
|
||||||
let csrf_token = set_csrf(&session).await;
|
let csrf_token = set_csrf(&session).await;
|
||||||
|
@ -26,7 +28,8 @@ pub async fn page(
|
||||||
form: &Context::default(),
|
form: &Context::default(),
|
||||||
return_to,
|
return_to,
|
||||||
logged_out,
|
logged_out,
|
||||||
meta: APP_METADATA.clone()
|
meta: APP_METADATA.clone(),
|
||||||
|
sso_enabled: settings.auth.oidc_enabled()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +53,7 @@ pub async fn handler(
|
||||||
ip_addr: IpAddr,
|
ip_addr: IpAddr,
|
||||||
session: Session<'_, SessionData>,
|
session: Session<'_, SessionData>,
|
||||||
mut form: Form<Contextual<'_, LoginForm<'_>>>,
|
mut form: Form<Contextual<'_, LoginForm<'_>>>,
|
||||||
|
settings: &State<AppConfig>,
|
||||||
return_to: Option<String>,
|
return_to: Option<String>,
|
||||||
) -> Result<HackyRedirectBecauseRocketBug, Template> {
|
) -> Result<HackyRedirectBecauseRocketBug, Template> {
|
||||||
trace!("handler");
|
trace!("handler");
|
||||||
|
@ -87,7 +91,8 @@ pub async fn handler(
|
||||||
csrf_token: csrf_token,
|
csrf_token: csrf_token,
|
||||||
form: &form.context,
|
form: &form.context,
|
||||||
return_to,
|
return_to,
|
||||||
meta: APP_METADATA.clone()
|
meta: APP_METADATA.clone(),
|
||||||
|
sso_enabled: settings.auth.oidc_enabled()
|
||||||
};
|
};
|
||||||
Err(Template::render("auth/login", &ctx))
|
Err(Template::render("auth/login", &ctx))
|
||||||
}
|
}
|
|
@ -58,7 +58,7 @@
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<button class="button is-link is-fullwidth" type="submit" >Login</button>
|
<button class="button is-link is-fullwidth" type="submit" >Login</button>
|
||||||
{{#if sso_enabled}}
|
{{#if sso_enabled}}
|
||||||
<a href="/login/sso" class="button is-fullwidth">Login with SSO</a>
|
<a href="/auth/sso" class="button is-fullwidth">Login with SSO</a>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue