Skip to content

Commit 50d8307

Browse files
committed
fix(RFC8414): strip any terminating "/" when pathname is present
1 parent 80bba0c commit 50d8307

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ function prependWellKnown(url: URL, wellKnown: string) {
12061206
if (url.pathname === '/') {
12071207
url.pathname = wellKnown
12081208
} else {
1209-
url.pathname = replaceDoubleSlash(`${wellKnown}/${url.pathname}`)
1209+
url.pathname = replaceDoubleSlash(`${wellKnown}/${url.pathname.replace(/(\/)$/, '')}`)
12101210
}
12111211
return url
12121212
}

test/discovery.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,20 @@ test('discoveryRequest() - oauth2 with a pathname', async (t) => {
9696
t.pass()
9797
})
9898

99+
test('discoveryRequest() - oauth2 with a pathname and issuer terminating "/"', async (t) => {
100+
const data = { issuer: 'https://op.example.com/path/' }
101+
t.context
102+
.intercept({
103+
path: '/.well-known/oauth-authorization-server/path',
104+
method: 'GET',
105+
})
106+
.reply(200, data)
107+
108+
const url = new URL(data.issuer)
109+
await lib.discoveryRequest(url, { algorithm: 'oauth2' })
110+
t.pass()
111+
})
112+
99113
test('processDiscoveryResponse()', async (t) => {
100114
const expected = new URL('https://op.example.com')
101115

0 commit comments

Comments
 (0)