From dc29ab24111afc06aa443d703ac807e2fccef25e Mon Sep 17 00:00:00 2001 From: Severin Wischmann Date: Mon, 26 Feb 2024 16:47:44 +0100 Subject: [PATCH 1/4] Fix for atlassian OAuth flow Signed-off-by: Severin Wischmann --- .../src/authenticator.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/auth-backend-module-atlassian-provider/src/authenticator.ts b/plugins/auth-backend-module-atlassian-provider/src/authenticator.ts index 3e5ed50246..6f3309a4ab 100644 --- a/plugins/auth-backend-module-atlassian-provider/src/authenticator.ts +++ b/plugins/auth-backend-module-atlassian-provider/src/authenticator.ts @@ -14,13 +14,13 @@ * limitations under the License. */ -import { Strategy as AtlassianStrategy } from 'passport-atlassian-oauth2'; import { createOAuthAuthenticator, PassportOAuthAuthenticatorHelper, PassportOAuthDoneCallback, PassportProfile, } from '@backstage/plugin-auth-node'; +import { Strategy as AtlassianStrategy } from 'passport-atlassian-oauth2'; /** @public */ export const atlassianAuthenticator = createOAuthAuthenticator({ @@ -30,7 +30,7 @@ export const atlassianAuthenticator = createOAuthAuthenticator({ const clientId = config.getString('clientId'); const clientSecret = config.getString('clientSecret'); const baseUrl = - config.getOptionalString('audience') || 'https://atlassian.com'; + config.getOptionalString('audience') || 'https://api.atlassian.com'; return PassportOAuthAuthenticatorHelper.from( new AtlassianStrategy( @@ -39,7 +39,7 @@ export const atlassianAuthenticator = createOAuthAuthenticator({ clientSecret: clientSecret, callbackURL: callbackUrl, baseURL: baseUrl, - authorizationURL: `${baseUrl}/oauth/authorize`, + authorizationURL: `${baseUrl}/authorize`, tokenURL: `${baseUrl}/oauth/token`, profileURL: `${baseUrl}/api/v4/user`, }, From c51118640dcba4d52ab17e65b3fb74836ccd282b Mon Sep 17 00:00:00 2001 From: Severin Wischmann Date: Mon, 26 Feb 2024 19:11:41 +0100 Subject: [PATCH 2/4] Added changeset Signed-off-by: Severin Wischmann --- .changeset/stale-bags-hug.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/stale-bags-hug.md diff --git a/.changeset/stale-bags-hug.md b/.changeset/stale-bags-hug.md new file mode 100644 index 0000000000..6929180596 --- /dev/null +++ b/.changeset/stale-bags-hug.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-auth-backend-module-atlassian-provider': patch +--- + +Addressed OAuth flow issue in Atlassian auth module From b3f53fa1c78ccfb0dafb922a549f173d2c168c63 Mon Sep 17 00:00:00 2001 From: Severin Wischmann Date: Mon, 26 Feb 2024 21:13:05 +0100 Subject: [PATCH 3/4] Updated module tests Signed-off-by: Severin Wischmann --- .../src/module.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/auth-backend-module-atlassian-provider/src/module.test.ts b/plugins/auth-backend-module-atlassian-provider/src/module.test.ts index 8d02b0b7a5..0b50dc1371 100644 --- a/plugins/auth-backend-module-atlassian-provider/src/module.test.ts +++ b/plugins/auth-backend-module-atlassian-provider/src/module.test.ts @@ -15,9 +15,9 @@ */ import { mockServices, startTestBackend } from '@backstage/backend-test-utils'; -import { authModuleAtlassianProvider } from './module'; -import request from 'supertest'; import { decodeOAuthState } from '@backstage/plugin-auth-node'; +import request from 'supertest'; +import { authModuleAtlassianProvider } from './module'; describe('authModuleAtlassianProvider', () => { it('should start', async () => { @@ -60,8 +60,8 @@ describe('authModuleAtlassianProvider', () => { expect(nonceCookie).toBeDefined(); const startUrl = new URL(res.get('location')); - expect(startUrl.origin).toBe('https://atlassian.com'); - expect(startUrl.pathname).toBe('/oauth/authorize'); + expect(startUrl.origin).toBe('https://api.atlassian.com'); + expect(startUrl.pathname).toBe('/authorize'); expect(Object.fromEntries(startUrl.searchParams)).toEqual({ response_type: 'code', client_id: 'my-client-id', From 10268db7254b5769e669de0ce883d765c9d39ab8 Mon Sep 17 00:00:00 2001 From: Severin Wischmann Date: Fri, 1 Mar 2024 10:44:42 +0100 Subject: [PATCH 4/4] Removed unused config value The config value `audience` was used to set the baseUrl which has a static value. The audience parameter is static in the used library. Therefore, the reading of the config value was removed. Signed-off-by: Severin Wischmann --- .../src/authenticator.ts | 3 +-- .../src/module.test.ts | 2 +- plugins/auth-backend/src/providers/atlassian/provider.ts | 8 ++++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/plugins/auth-backend-module-atlassian-provider/src/authenticator.ts b/plugins/auth-backend-module-atlassian-provider/src/authenticator.ts index 6f3309a4ab..340c61052c 100644 --- a/plugins/auth-backend-module-atlassian-provider/src/authenticator.ts +++ b/plugins/auth-backend-module-atlassian-provider/src/authenticator.ts @@ -29,8 +29,7 @@ export const atlassianAuthenticator = createOAuthAuthenticator({ initialize({ callbackUrl, config }) { const clientId = config.getString('clientId'); const clientSecret = config.getString('clientSecret'); - const baseUrl = - config.getOptionalString('audience') || 'https://api.atlassian.com'; + const baseUrl = 'https://auth.atlassian.com'; return PassportOAuthAuthenticatorHelper.from( new AtlassianStrategy( diff --git a/plugins/auth-backend-module-atlassian-provider/src/module.test.ts b/plugins/auth-backend-module-atlassian-provider/src/module.test.ts index 0b50dc1371..024a45d43d 100644 --- a/plugins/auth-backend-module-atlassian-provider/src/module.test.ts +++ b/plugins/auth-backend-module-atlassian-provider/src/module.test.ts @@ -60,7 +60,7 @@ describe('authModuleAtlassianProvider', () => { expect(nonceCookie).toBeDefined(); const startUrl = new URL(res.get('location')); - expect(startUrl.origin).toBe('https://api.atlassian.com'); + expect(startUrl.origin).toBe('https://auth.atlassian.com'); expect(startUrl.pathname).toBe('/authorize'); expect(Object.fromEntries(startUrl.searchParams)).toEqual({ response_type: 'code', diff --git a/plugins/auth-backend/src/providers/atlassian/provider.ts b/plugins/auth-backend/src/providers/atlassian/provider.ts index 0cd95e19d7..22db26fd85 100644 --- a/plugins/auth-backend/src/providers/atlassian/provider.ts +++ b/plugins/auth-backend/src/providers/atlassian/provider.ts @@ -14,9 +14,7 @@ * limitations under the License. */ -import { AuthHandler } from '../types'; -import { OAuthResult } from '../../lib/oauth'; -import { createAuthProviderIntegration } from '../createAuthProviderIntegration'; +import { atlassianAuthenticator } from '@backstage/plugin-auth-backend-module-atlassian-provider'; import { SignInResolver, createOAuthProviderFactory, @@ -25,7 +23,9 @@ import { adaptLegacyOAuthHandler, adaptLegacyOAuthSignInResolver, } from '../../lib/legacy'; -import { atlassianAuthenticator } from '@backstage/plugin-auth-backend-module-atlassian-provider'; +import { OAuthResult } from '../../lib/oauth'; +import { createAuthProviderIntegration } from '../createAuthProviderIntegration'; +import { AuthHandler } from '../types'; /** * Auth provider integration for Atlassian auth