Add shared OAuth flows

This commit is contained in:
fawney19
2026-04-28 15:46:21 +08:00
parent 712b484bc8
commit 70f747d406
56 changed files with 5927 additions and 977 deletions

View File

@@ -4,7 +4,87 @@ pub(super) fn classify_oauth_route(
method: &http::Method,
normalized_path: &str,
) -> Option<ClassifiedRoute> {
if method == http::Method::GET && normalized_path == "/api/admin/oauth/supported-types" {
if method == http::Method::GET && normalized_path == "/api/oauth/providers" {
Some(classified(
"public_support",
"oauth",
"list_providers",
"user:oauth",
false,
))
} else if method == http::Method::GET
&& normalized_path.starts_with("/api/oauth/")
&& normalized_path.ends_with("/authorize")
{
Some(classified(
"public_support",
"oauth",
"authorize",
"user:oauth",
false,
))
} else if method == http::Method::GET
&& normalized_path.starts_with("/api/oauth/")
&& normalized_path.ends_with("/callback")
{
Some(classified(
"public_support",
"oauth",
"callback",
"user:oauth",
false,
))
} else if method == http::Method::GET && normalized_path == "/api/user/oauth/bindable-providers"
{
Some(classified(
"public_support",
"oauth",
"bindable_providers",
"user:oauth",
false,
))
} else if method == http::Method::GET && normalized_path == "/api/user/oauth/links" {
Some(classified(
"public_support",
"oauth",
"links",
"user:oauth",
false,
))
} else if method == http::Method::POST
&& normalized_path.starts_with("/api/user/oauth/")
&& normalized_path.ends_with("/bind-token")
{
Some(classified(
"public_support",
"oauth",
"bind_token",
"user:oauth",
false,
))
} else if method == http::Method::GET
&& normalized_path.starts_with("/api/user/oauth/")
&& normalized_path.ends_with("/bind")
{
Some(classified(
"public_support",
"oauth",
"bind",
"user:oauth",
false,
))
} else if method == http::Method::DELETE
&& normalized_path.starts_with("/api/user/oauth/")
&& !normalized_path.contains("/bind")
{
Some(classified(
"public_support",
"oauth",
"unbind",
"user:oauth",
false,
))
} else if method == http::Method::GET && normalized_path == "/api/admin/oauth/supported-types" {
Some(classified(
"admin_proxy",
"oauth_manage",

View File

@@ -659,45 +659,73 @@ fn classifies_auth_routes_as_public_support_route() {
}
#[test]
fn does_not_classify_oauth_public_providers_route() {
fn classifies_oauth_public_providers_route() {
let headers = headers(&[]);
let uri: Uri = "/api/oauth/providers".parse().expect("uri should parse");
let decision = classify_control_route(&http::Method::GET, &uri, &headers);
let decision =
classify_control_route(&http::Method::GET, &uri, &headers).expect("route should classify");
assert!(decision.is_none());
assert_eq!(decision.route_class.as_deref(), Some("public_support"));
assert_eq!(decision.route_family.as_deref(), Some("oauth"));
assert_eq!(decision.route_kind.as_deref(), Some("list_providers"));
assert_eq!(
decision.auth_endpoint_signature.as_deref(),
Some("user:oauth")
);
}
#[test]
fn does_not_classify_oauth_public_authorize_route() {
fn classifies_oauth_public_authorize_route() {
let headers = headers(&[]);
let uri: Uri = "/api/oauth/linuxdo/authorize?client_device_id=device-1"
.parse()
.expect("uri should parse");
let decision = classify_control_route(&http::Method::GET, &uri, &headers);
let decision =
classify_control_route(&http::Method::GET, &uri, &headers).expect("route should classify");
assert!(decision.is_none());
assert_eq!(decision.route_class.as_deref(), Some("public_support"));
assert_eq!(decision.route_family.as_deref(), Some("oauth"));
assert_eq!(decision.route_kind.as_deref(), Some("authorize"));
assert_eq!(
decision.auth_endpoint_signature.as_deref(),
Some("user:oauth")
);
}
#[test]
fn does_not_classify_oauth_user_bindable_providers_route() {
fn classifies_oauth_user_bindable_providers_route() {
let headers = headers(&[]);
let uri: Uri = "/api/user/oauth/bindable-providers"
.parse()
.expect("uri should parse");
let decision = classify_control_route(&http::Method::GET, &uri, &headers);
let decision =
classify_control_route(&http::Method::GET, &uri, &headers).expect("route should classify");
assert!(decision.is_none());
assert_eq!(decision.route_class.as_deref(), Some("public_support"));
assert_eq!(decision.route_family.as_deref(), Some("oauth"));
assert_eq!(decision.route_kind.as_deref(), Some("bindable_providers"));
assert_eq!(
decision.auth_endpoint_signature.as_deref(),
Some("user:oauth")
);
}
#[test]
fn does_not_classify_oauth_user_bind_token_route() {
fn classifies_oauth_user_bind_token_route() {
let headers = headers(&[]);
let uri: Uri = "/api/user/oauth/linuxdo/bind-token"
.parse()
.expect("uri should parse");
let decision = classify_control_route(&http::Method::POST, &uri, &headers);
let decision =
classify_control_route(&http::Method::POST, &uri, &headers).expect("route should classify");
assert!(decision.is_none());
assert_eq!(decision.route_class.as_deref(), Some("public_support"));
assert_eq!(decision.route_family.as_deref(), Some("oauth"));
assert_eq!(decision.route_kind.as_deref(), Some("bind_token"));
assert_eq!(
decision.auth_endpoint_signature.as_deref(),
Some("user:oauth")
);
}
#[test]