Another provider
It proves a claim. It never logs a user in: after it comes a passkey.
use auth_chad::axum::{External, Hooks};
use auth_chad::oidc::KeySet;
use auth_chad::sqlite::SqliteStore;
fn company() -> External {
External {
id: "company".into(),
issuer: "https://login.company.example".into(),
client_id: "…".into(),
authorization_endpoint: "https://login.company.example/authorize".into(),
token_endpoint: "https://login.company.example/token".into(),
sends_iss: true,
authoritative_for: vec!["company.example".into()],
}
}
struct App;
impl Hooks<SqliteStore> for App {
async fn exchange(&self, provider: &External, form: &[(&'static str, String)]) -> Option<String> {
// POST `form` to `provider.token_endpoint` with your client secret or key. Return `id_token`.
None
}
async fn provider_keys(&self, provider: &External) -> Option<KeySet> {
// GET the provider's `jwks_uri`, and keep it for some minutes.
None
}
}
Then Auth::new(…)?.with_hooks(App).with_external(vec![company()], "/welcome"). Register the redirect URI
<issuer>/auth/external/company/callback at the provider. In the browser:
await external("company", "signup"); // comes back to /welcome?purpose=signup or /welcome?error=…
await signup({ displayName, external: true });
await external("company", "link"); // comes back to /welcome?purpose=link
await linkExternal(); // from a click, with a recent passkey
await external("company", "refresh"); // for a company rule, when login() fails with external_identity_refused
await login();
- Sign up: allow
SignupMode::Externalin the policy. - Company rule: add the issuer to
Policy.external. A login then needs a company login of the last 24 hours. - The answer of the provider must be a redirect with a query. A form post (
response_mode=form_post) does not work: the browser does not send the cookie with it.
Never look up an account by the email address.