Skip to main content

tuwunel_api/oidc/
mod.rs

1pub(super) mod account;
2pub(super) mod auth_issuer;
3pub(super) mod auth_metadata;
4pub(super) mod authorize;
5pub(super) mod complete;
6pub(super) mod jwks;
7pub(super) mod registration;
8pub(super) mod revoke;
9pub(super) mod token;
10pub(super) mod userinfo;
11
12use std::fmt::Write;
13
14use axum::{Json, body::Body, response::IntoResponse};
15use http::{Response, StatusCode};
16use serde_json::json;
17
18pub(super) use self::{
19	account::*, auth_issuer::*, auth_metadata::*, authorize::*, complete::*, jwks::*,
20	registration::*, revoke::*, token::*, userinfo::*,
21};
22
23const OIDC_REQ_ID_LENGTH: usize = 32;
24
25pub(crate) fn url_encode(s: &str) -> String {
26	s.bytes()
27		.fold(String::with_capacity(s.len()), |mut out, b| {
28			if b.is_ascii_alphanumeric() || matches!(b, b'-' | b'_' | b'.' | b'~') {
29				out.push(b.into());
30			} else {
31				write!(&mut out, "%{b:02X}").ok();
32			}
33
34			out
35		})
36}
37
38fn oauth_error(status: StatusCode, error: &str, description: &str) -> Response<Body> {
39	let body = json!({
40		"error": error,
41		"error_description": description,
42	});
43
44	(status, Json(body)).into_response()
45}