Skip to content

Commit 706c500

Browse files
adriangzzMongoDB Bot
authored andcommitted
SERVER-92329 Support issuers with trailing slashes in OIDC (#25217)
GitOrigin-RevId: 8b812e036b4f99f1c0ae17e1452b8b251a1f5e4d
1 parent bd52f29 commit 706c500

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/mongo/db/auth/oauth_discovery_factory.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ OAuthAuthorizationServerMetadata OAuthDiscoveryFactory::acquire(StringData issue
4646
// '.well-known/oauth-authorization-server'. However, that endpoint uses a different URL
4747
// construction scheme which doesn't seem to work with any of the authorization servers we've
4848
// tested.
49+
50+
// Some issuers URL will end with '/', we should remove it since we add it when forming the
51+
// configuration endpoint.
52+
if (issuer.endsWith("/"_sd)) {
53+
issuer = issuer.substr(0, issuer.size() - 1);
54+
}
55+
4956
auto openIDConfiguationEndpoint = "{}/.well-known/openid-configuration"_format(issuer);
5057

5158
DataBuilder results = _client->get(openIDConfiguationEndpoint);

src/mongo/db/auth/oauth_discovery_factory_test.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,20 @@ TEST_F(OAuthDiscoveryFactoryFixture, LookupsMustBeSecure) {
149149
ASSERT_THROWS(factory.acquire("http://idp.example"), DBException);
150150
}
151151

152+
TEST_F(OAuthDiscoveryFactoryFixture, DiscoveryIssuerWithFwdSlash) {
153+
auto defaultMetadata = makeDefaultMetadata();
154+
155+
std::unique_ptr<MockHttpClient> client = std::make_unique<MockHttpClient>();
156+
client->expect(
157+
{HttpClient::HttpMethod::kGET, "https://idp.example/.well-known/openid-configuration"},
158+
{200, {}, defaultMetadata.toBSON().jsonString()});
159+
160+
OAuthDiscoveryFactory factory(std::move(client));
161+
OAuthAuthorizationServerMetadata metadata = factory.acquire("https://idp.example/");
162+
163+
ASSERT_EQ(defaultMetadata, metadata);
164+
}
165+
152166
TEST_F(OAuthDiscoveryFactoryFixture, IssuerAndJWKSUriMustBeSecure) {
153167
auto defaultMetadata = makeDefaultMetadata();
154168

0 commit comments

Comments
 (0)