diff --git a/src/lib/resource.ts b/src/lib/resource.ts index be3537e..dc07cb0 100644 --- a/src/lib/resource.ts +++ b/src/lib/resource.ts @@ -77,7 +77,12 @@ export class OAuthResource extends Resource { }; } - const pathParts = path.split('/').filter((p) => p); + let pathParts = path.split('/').filter((p) => p); + + // Handle /oauth prefix if present (case-insensitive) + if (pathParts[0]?.toLowerCase() === 'oauth') { + pathParts = pathParts.slice(1); + } return { providerName: pathParts[0] || '', diff --git a/test/lib/OAuthResource.helpers.test.js b/test/lib/OAuthResource.helpers.test.js index c8601ca..4e1ee52 100644 --- a/test/lib/OAuthResource.helpers.test.js +++ b/test/lib/OAuthResource.helpers.test.js @@ -86,6 +86,38 @@ describe('OAuthResource - Helper Methods', () => { assert.equal(route.providerName, 'github'); assert.equal(route.action, 'login'); }); + + it('should handle /oauth prefix', () => { + const target = { id: '/oauth/github/login', pathname: '' }; + const route = OAuthResource.parseRoute(target); + + assert.equal(route.providerName, 'github'); + assert.equal(route.action, 'login'); + }); + + it('should handle /oauth prefix with tenant ID', () => { + const target = { id: '/oauth/oac-abc123/login', pathname: '' }; + const route = OAuthResource.parseRoute(target); + + assert.equal(route.providerName, 'oac-abc123'); + assert.equal(route.action, 'login'); + }); + + it('should handle /oauth prefix only', () => { + const target = { id: '/oauth', pathname: '' }; + const route = OAuthResource.parseRoute(target); + + assert.equal(route.providerName, ''); + assert.equal(route.action, ''); + }); + + it('should handle case-insensitive /Oauth prefix', () => { + const target = { id: '/Oauth/github/login', pathname: '' }; + const route = OAuthResource.parseRoute(target); + + assert.equal(route.providerName, 'github'); + assert.equal(route.action, 'login'); + }); }); describe('isDebugOnlyRoute()', () => {