mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-12-03 22:01:50 +00:00
feat(oidc): Pass login hint to OIDC provider
This commit is contained in:
4 files changed
+60
-15
No files matched your search
+17
-3
@@ -2579,9 +2579,10 @@
|
||||
|
||||
# Additional scopes Continuwuity should request from the IDP. This may be
|
||||
# necessary to access certain claims. Continuwuity always requests the
|
||||
# `openid` scope, regardless of the contents of this option,
|
||||
# and will also request the `profile` scope by default if this option is
|
||||
# not set.
|
||||
# `openid` scope, regardless of the value of this option.
|
||||
#
|
||||
# Defaults to only the `profile` scope, as recommended by the OIDC
|
||||
# specification.
|
||||
#
|
||||
# env: CONTINUWUITY_OAUTH__OIDC__ADDITIONAL_SCOPES
|
||||
#additional_scopes = ["profile"]
|
||||
@@ -2597,6 +2598,19 @@
|
||||
# env: CONTINUWUITY_OAUTH__OIDC__ADDITIONAL_TRUSTED_AUDIENCES
|
||||
#additional_trusted_audiences = []
|
||||
|
||||
# If `true`, Continuwuity will pass on the Matrix ID of the user trying to
|
||||
# log in to the identity provider where applicable.
|
||||
#
|
||||
# If Continuwuity knows the Matrix ID of the user trying to log in, it
|
||||
# will set the authorization URL's `login_hint` query parameter to the
|
||||
# _localpart_ of that ID (everything between the @ sign and the colon).
|
||||
#
|
||||
# Defaults to `true`. Set this to `false` if supplying the `login_hint`
|
||||
# causes your identity provider to behave undesirably.
|
||||
#
|
||||
# env: CONTINUWUITY_OAUTH__OIDC__SUPPLY_LOGIN_HINT
|
||||
#supply_login_hint = true
|
||||
|
||||
# The name of the identity provider. If this is set, the login page's
|
||||
# button reads "Continue with <name>" instead of just "Continue".
|
||||
#
|
||||
|
||||
+18
-3
@@ -2820,9 +2820,10 @@ pub struct OidcConfig {
|
||||
|
||||
/// Additional scopes Continuwuity should request from the IDP. This may be
|
||||
/// necessary to access certain claims. Continuwuity always requests the
|
||||
/// `openid` scope, regardless of the contents of this option,
|
||||
/// and will also request the `profile` scope by default if this option is
|
||||
/// not set.
|
||||
/// `openid` scope, regardless of the value of this option.
|
||||
///
|
||||
/// Defaults to only the `profile` scope, as recommended by the OIDC
|
||||
/// specification.
|
||||
///
|
||||
/// default: ["profile"]
|
||||
#[serde(default = "default_additional_scopes")]
|
||||
@@ -2840,6 +2841,20 @@ pub struct OidcConfig {
|
||||
#[serde(default)]
|
||||
pub additional_trusted_audiences: BTreeSet<Audience>,
|
||||
|
||||
/// If `true`, Continuwuity will pass on the Matrix ID of the user trying to
|
||||
/// log in to the identity provider where applicable.
|
||||
///
|
||||
/// If Continuwuity knows the Matrix ID of the user trying to log in, it
|
||||
/// will set the authorization URL's `login_hint` query parameter to the
|
||||
/// _localpart_ of that ID (everything between the @ sign and the colon).
|
||||
///
|
||||
/// Defaults to `true`. Set this to `false` if supplying the `login_hint`
|
||||
/// causes your identity provider to behave undesirably.
|
||||
///
|
||||
/// default: true
|
||||
#[serde(default = "true_fn")]
|
||||
pub supply_login_hint: bool,
|
||||
|
||||
/// The name of the identity provider. If this is set, the login page's
|
||||
/// button reads "Continue with <name>" instead of just "Continue".
|
||||
///
|
||||
|
||||
+12
-1
@@ -256,7 +256,11 @@ impl Service {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn begin_session(&self, prompt: Option<CoreAuthPrompt>) -> (PendingSession, Url) {
|
||||
pub async fn begin_session(
|
||||
&self,
|
||||
prompt: Option<CoreAuthPrompt>,
|
||||
login_hint: Option<&UserId>,
|
||||
) -> (PendingSession, Url) {
|
||||
let OidcClient { machine, config, .. } =
|
||||
self.client.as_ref().expect("oidc should be configured");
|
||||
let machine = machine.wait().await.read().clone();
|
||||
@@ -276,6 +280,13 @@ impl Service {
|
||||
auth_url = auth_url.add_prompt(prompt);
|
||||
}
|
||||
|
||||
if let Some(user_id) = login_hint
|
||||
&& config.supply_login_hint
|
||||
{
|
||||
auth_url = auth_url
|
||||
.set_login_hint(openidconnect::LoginHint::new(user_id.localpart().to_owned()));
|
||||
}
|
||||
|
||||
let (auth_url, csrf_token, nonce) = auth_url.url();
|
||||
|
||||
(PendingSession { pkce_verifier, nonce, csrf_token }, auth_url)
|
||||
|
||||
@@ -93,14 +93,19 @@ async fn route_login(
|
||||
}
|
||||
|
||||
let login_type = if services.oidc.enabled() {
|
||||
let (session, redirect_url) = services
|
||||
.oidc
|
||||
.begin_session(match intent {
|
||||
| Some(LoginIntent::SwitchAccounts) => Some(CoreAuthPrompt::SelectAccount),
|
||||
| _ if reauthenticate => Some(CoreAuthPrompt::Consent),
|
||||
| _ => None,
|
||||
})
|
||||
.await;
|
||||
let prompt = match intent {
|
||||
| Some(LoginIntent::SwitchAccounts) => Some(CoreAuthPrompt::SelectAccount),
|
||||
| _ if reauthenticate => Some(CoreAuthPrompt::Consent),
|
||||
| _ => None,
|
||||
};
|
||||
|
||||
let login_hint = if let Some(LoginHint::Mxid(user_id)) = &login_hint {
|
||||
Some(user_id.as_ref())
|
||||
} else {
|
||||
current_user.as_deref()
|
||||
};
|
||||
|
||||
let (session, redirect_url) = services.oidc.begin_session(prompt, login_hint).await;
|
||||
|
||||
session_store
|
||||
.insert(OIDC_SESSION_ID_KEY, OidcSession {
|
||||
|
||||
Reference in new issue
Block a user