Skip to content

Commit c67007a

Browse files
authored
feat: Make OAuth token server configurable (#305)
1 parent ce71aeb commit c67007a

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

crates/catalog/rest/src/catalog.rs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ impl RestCatalogConfig {
7171
}
7272

7373
fn get_token_endpoint(&self) -> String {
74-
[&self.uri, PATH_V1, "oauth", "tokens"].join("/")
74+
if let Some(auth_url) = self.props.get("rest.authorization-url") {
75+
auth_url.to_string()
76+
} else {
77+
[&self.uri, PATH_V1, "oauth", "tokens"].join("/")
78+
}
7579
}
7680

7781
fn namespaces_endpoint(&self) -> String {
@@ -865,8 +869,12 @@ mod tests {
865869
}
866870

867871
async fn create_oauth_mock(server: &mut ServerGuard) -> Mock {
872+
create_oauth_mock_with_path(server, "/v1/oauth/tokens").await
873+
}
874+
875+
async fn create_oauth_mock_with_path(server: &mut ServerGuard, path: &str) -> Mock {
868876
server
869-
.mock("POST", "/v1/oauth/tokens")
877+
.mock("POST", path)
870878
.with_status(200)
871879
.with_body(
872880
r#"{
@@ -955,6 +963,39 @@ mod tests {
955963
);
956964
}
957965

966+
#[tokio::test]
967+
async fn test_oauth_with_auth_url() {
968+
let mut server = Server::new_async().await;
969+
let config_mock = create_config_mock(&mut server).await;
970+
971+
let mut auth_server = Server::new_async().await;
972+
let auth_server_path = "/some/path";
973+
let oauth_mock = create_oauth_mock_with_path(&mut auth_server, auth_server_path).await;
974+
975+
let mut props = HashMap::new();
976+
props.insert("credential".to_string(), "client1:secret1".to_string());
977+
props.insert(
978+
"rest.authorization-url".to_string(),
979+
format!("{}{}", auth_server.url(), auth_server_path).to_string(),
980+
);
981+
982+
let catalog = RestCatalog::new(
983+
RestCatalogConfig::builder()
984+
.uri(server.url())
985+
.props(props)
986+
.build(),
987+
)
988+
.await
989+
.unwrap();
990+
991+
oauth_mock.assert_async().await;
992+
config_mock.assert_async().await;
993+
assert_eq!(
994+
catalog.config.props.get("token"),
995+
Some(&"ey000000000000".to_string())
996+
);
997+
}
998+
958999
#[tokio::test]
9591000
async fn test_config_override_prefix() {
9601001
let mut server = Server::new_async().await;

0 commit comments

Comments
 (0)