Skip to content

Commit d87e502

Browse files
committed
feat(config): add forward endpoint type option
1 parent 80d8858 commit d87e502

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

htsget-config/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,12 @@ The authorization server should respond with a rule set that htsget-rs can use t
430430

431431
The following additional options can be configured under the `auth` table to enable this:
432432

433-
| Option | Description | Type | Default |
434-
|---------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------|----------|
435-
| `authorization_url` | The URL which will be called to authorize the user. A GET request will be issued to the url. Alternatively, this can be a file path to authorize users based on static config. | URL | Not set. |
436-
| `forward_headers` | For each header specified, forward any headers from the client to the authorization server. Headers are forwarded with the `Htsget-Context-` as a prefix. | Array of header names | Not set. |
437-
| `passthrough_auth` | Forward the authorization header to the authorization server directly without renaming it to a `Htsget-Context-` custom header. If this is true, then the `Authorization` header is required with the request. | Boolean | `false` |
433+
| Option | Description | Type | Default |
434+
|-------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------|----------|
435+
| `authorization_url` | The URL which will be called to authorize the user. A GET request will be issued to the url. Alternatively, this can be a file path to authorize users based on static config. | URL | Not set. |
436+
| `forward_headers` | For each header specified, forward any headers from the client to the authorization server. Headers are forwarded with the `Htsget-Context-` as a prefix. | Array of header names | Not set. |
437+
| `forward_endpoint_type` | Forwards the type of endpoint that the request used in a header called `Htsget-Context-Endpoint-Type`. The value of this header will either be `reads` or `variants`, depending on whether the user requested the reads or variants endpoint. | Boolean | `false` |
438+
| `passthrough_auth` | Forward the authorization header to the authorization server directly without renaming it to a `Htsget-Context-` custom header. If this is true, then the `Authorization` header is required with the request. | Boolean | `false` |
438439

439440
When using the `authorization_url`, the [authentication](#jwt-authentication) config must also be set as htsget-rs will
440441
forward the JWT token to the authorization server so that it can make decisions about the user's authorization. If the

htsget-config/docs/examples/auth.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ authorization_url = "https://www.example.com/authorize"
2222
passthrough_auth = true
2323
## Any headers to forward
2424
#forward_headers = ["Content-Type"]
25+
## Forward the endpoint type to the auth service.
26+
#forward_endpoint_type = true
2527

2628
## Set client authentication
2729
#http.key = "key.pem"

htsget-config/src/config/advanced/auth/authorization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl<'de> Deserialize<'de> for UrlOrStatic {
3838
}
3939

4040
/// The extensions to pass through to the authorization server from http request extensions.
41-
#[derive(Serialize, Deserialize, Debug, Clone)]
41+
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
4242
#[serde(deny_unknown_fields)]
4343
pub struct ForwardExtensions {
4444
json_path: String,

htsget-config/src/config/advanced/auth/mod.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub struct AuthConfig {
2828
validate_subject: Option<String>,
2929
authorization_url: Option<UrlOrStatic>,
3030
forward_headers: Vec<String>,
31+
forward_endpoint_type: bool,
3132
passthrough_auth: bool,
3233
forward_extensions: Vec<ForwardExtensions>,
3334
http_client: HttpClient,
@@ -95,6 +96,11 @@ impl AuthConfig {
9596
self.forward_headers.as_slice()
9697
}
9798

99+
/// Get whether to forward the endpoint type of the request.
100+
pub fn forward_endpoint_type(&self) -> bool {
101+
self.forward_endpoint_type
102+
}
103+
98104
/// Get whether to pass through the auth header.
99105
pub fn passthrough_auth(&self) -> bool {
100106
self.passthrough_auth
@@ -126,6 +132,7 @@ pub struct AuthConfigBuilder {
126132
validate_subject: Option<String>,
127133
authorization_url: Option<UrlOrStatic>,
128134
forward_headers: Vec<String>,
135+
forward_endpoint_type: bool,
129136
passthrough_auth: bool,
130137
forward_extensions: Vec<ForwardExtensions>,
131138
#[serde(rename = "http", alias = "tls", skip_serializing)]
@@ -193,6 +200,12 @@ impl AuthConfigBuilder {
193200
self
194201
}
195202

203+
/// Set whether to forward the endpoint type.
204+
pub fn forward_endpoint_type(mut self, forward_endpoint_type: bool) -> Self {
205+
self.forward_endpoint_type = forward_endpoint_type;
206+
self
207+
}
208+
196209
/// Set whether to pass through auth.
197210
pub fn passthrough_auth(mut self, passthrough_auth: bool) -> Self {
198211
self.passthrough_auth = passthrough_auth;
@@ -214,6 +227,7 @@ impl AuthConfigBuilder {
214227
validate_subject: self.validate_subject,
215228
authorization_url: self.authorization_url,
216229
forward_headers: self.forward_headers,
230+
forward_endpoint_type: self.forward_endpoint_type,
217231
passthrough_auth: self.passthrough_auth,
218232
forward_extensions: self.forward_extensions,
219233
http_client: self
@@ -239,6 +253,7 @@ impl Default for AuthConfigBuilder {
239253
validate_subject: None,
240254
authorization_url,
241255
forward_headers: vec![],
256+
forward_endpoint_type: false,
242257
passthrough_auth: false,
243258
forward_extensions: vec![],
244259
http_client: None,
@@ -376,6 +391,10 @@ mod tests {
376391
validate_issuer = ["iss1"]
377392
validate_subject = "sub"
378393
authorization_url = "https://www.example.com"
394+
passthrough_auth = true
395+
forward_headers = ["header"]
396+
forward_endpoint_type = true
397+
forward_extensions = [ { json_path = '$.extension', name = 'Extension'} ]
379398
"#,
380399
)
381400
.unwrap();
@@ -396,6 +415,20 @@ mod tests {
396415
config.authorization_url().unwrap(),
397416
&UrlOrStatic::Url("https://www.example.com".parse::<Uri>().unwrap())
398417
);
418+
assert!(
419+
config.passthrough_auth()
420+
);
421+
assert_eq!(
422+
config.forward_headers(),
423+
["header".to_string()]
424+
);
425+
assert!(
426+
config.forward_endpoint_type()
427+
);
428+
assert_eq!(
429+
config.forward_extensions(),
430+
[ForwardExtensions::new("$.extension".to_string(), "Extension".to_string())]
431+
);
399432
}
400433

401434
#[cfg(feature = "experimental")]

0 commit comments

Comments
 (0)