replace GitLab, Gitlab, gitlab with atlassian

Signed-off-by: Shousan Liao <samliao980822@gmail.com>
This commit is contained in:
Shousan Liao
2023-11-03 14:00:42 -04:00
parent 8d6824624e
commit 824b2d47d2
14 changed files with 586 additions and 0 deletions
@@ -0,0 +1 @@
module.exports = require('@backstage/cli/config/eslint-factory')(__dirname);
@@ -0,0 +1,131 @@
# @backstage/plugin-auth-backend-module-atlassian-provider
## 0.1.4-next.1
### Patch Changes
- Updated dependencies
- @backstage/backend-common@0.19.9-next.1
- @backstage/plugin-auth-node@0.4.1-next.1
- @backstage/backend-plugin-api@0.6.7-next.1
## 0.1.4-next.0
### Patch Changes
- Updated dependencies
- @backstage/backend-common@0.19.9-next.0
- @backstage/backend-plugin-api@0.6.7-next.0
- @backstage/plugin-auth-node@0.4.1-next.0
## 0.1.3
### Patch Changes
- Updated dependencies
- @backstage/backend-common@0.19.8
- @backstage/plugin-auth-node@0.4.0
- @backstage/backend-plugin-api@0.6.6
## 0.1.3-next.2
### Patch Changes
- Updated dependencies
- @backstage/backend-common@0.19.8-next.2
- @backstage/plugin-auth-node@0.4.0-next.2
- @backstage/backend-plugin-api@0.6.6-next.2
## 0.1.2-next.1
### Patch Changes
- Updated dependencies
- @backstage/backend-common@0.19.7-next.1
- @backstage/backend-plugin-api@0.6.5-next.1
- @backstage/plugin-auth-node@0.3.2-next.1
## 0.1.2-next.0
### Patch Changes
- Updated dependencies
- @backstage/plugin-auth-node@0.3.2-next.0
- @backstage/backend-common@0.19.7-next.0
- @backstage/backend-plugin-api@0.6.5-next.0
## 0.1.0
### Minor Changes
- 080cc7794700: New module for `@backstage/plugin-auth-backend` that adds a Atlassian auth provider.
### Patch Changes
- 71114ac50e02: The export for the new backend system has been moved to be the `default` export.
For example, if you are currently importing the plugin using the following pattern:
```ts
import { examplePlugin } from '@backstage/plugin-example-backend';
backend.add(examplePlugin);
```
It should be migrated to this:
```ts
backend.add(import('@backstage/plugin-example-backend'));
```
- Updated dependencies
- @backstage/backend-common@0.19.5
- @backstage/plugin-auth-node@0.3.0
- @backstage/backend-plugin-api@0.6.3
## 0.1.0-next.2
### Patch Changes
- 71114ac50e02: The export for the new backend system has been moved to be the `default` export.
For example, if you are currently importing the plugin using the following pattern:
```ts
import { examplePlugin } from '@backstage/plugin-example-backend';
backend.add(examplePlugin);
```
It should be migrated to this:
```ts
backend.add(import('@backstage/plugin-example-backend'));
```
- Updated dependencies
- @backstage/backend-plugin-api@0.6.3-next.3
- @backstage/backend-common@0.19.5-next.3
- @backstage/plugin-auth-node@0.3.0-next.3
## 0.1.0-next.1
### Patch Changes
- Updated dependencies
- @backstage/backend-common@0.19.5-next.2
- @backstage/plugin-auth-node@0.3.0-next.2
- @backstage/backend-plugin-api@0.6.3-next.2
## 0.1.0-next.0
### Minor Changes
- 080cc7794700: New module for `@backstage/plugin-auth-backend` that adds a Atlassian auth provider.
### Patch Changes
- Updated dependencies
- @backstage/backend-common@0.19.5-next.1
- @backstage/backend-plugin-api@0.6.3-next.1
- @backstage/plugin-auth-node@0.3.0-next.1
@@ -0,0 +1,8 @@
# Auth Module: Atlassian Provider
This module provides an Atlassian auth provider implementation for `@backstage/plugin-auth-backend`.
## Links
- [Repository](https://atlassian.com/backstage/backstage/tree/master/plugins/auth-backend-module-atlassian-provider)
- [Backstage Project Homepage](https://backstage.io)
@@ -0,0 +1,30 @@
## API Report File for "@backstage/plugin-auth-backend-module-atlassian-provider"
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { BackendFeature } from '@backstage/backend-plugin-api';
import { OAuthAuthenticator } from '@backstage/plugin-auth-node';
import { OAuthAuthenticatorResult } from '@backstage/plugin-auth-node';
import { PassportOAuthAuthenticatorHelper } from '@backstage/plugin-auth-node';
import { PassportProfile } from '@backstage/plugin-auth-node';
import { SignInResolverFactory } from '@backstage/plugin-auth-node';
// @public (undocumented)
const authModuleAtlassianProvider: () => BackendFeature;
export default authModuleAtlassianProvider;
// @public (undocumented)
export const atlassianAuthenticator: OAuthAuthenticator<
PassportOAuthAuthenticatorHelper,
PassportProfile
>;
// @public
export namespace atlassianSignInResolvers {
const usernameMatchingUserEntityName: SignInResolverFactory<
OAuthAuthenticatorResult<PassportProfile>,
unknown
>;
}
```
@@ -0,0 +1,10 @@
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: backstage-plugin-auth-backend-module-atlassian-provider
title: '@backstage/plugin-auth-backend-module-atlassian-provider'
description: The atlassian-provider backend module for the auth plugin.
spec:
lifecycle: experimental
type: backstage-backend-plugin-module
owner: maintainers
@@ -0,0 +1,34 @@
/*
* Copyright 2020 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export interface Config {
auth?: {
providers?: {
/** @visibility frontend */
atlassian?: {
[authEnv: string]: {
clientId: string;
/**
* @visibility secret
*/
clientSecret: string;
audience?: string;
callbackUrl?: string;
};
};
};
};
}
@@ -0,0 +1,24 @@
/*
* Copyright 2023 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { createBackend } from '@backstage/backend-defaults';
const backend = createBackend();
backend.add(import('@backstage/plugin-auth-backend'));
backend.add(import('../src'));
backend.start();
@@ -0,0 +1,45 @@
{
"name": "@backstage/plugin-auth-backend-module-atlassian-provider",
"description": "The atlassian-provider backend module for the auth plugin.",
"version": "0.1.4-next.1",
"main": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"publishConfig": {
"access": "public",
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
},
"backstage": {
"role": "backend-plugin-module"
},
"scripts": {
"start": "backstage-cli package start",
"build": "backstage-cli package build",
"lint": "backstage-cli package lint",
"test": "backstage-cli package test",
"clean": "backstage-cli package clean",
"prepack": "backstage-cli package prepack",
"postpack": "backstage-cli package postpack"
},
"dependencies": {
"@backstage/backend-common": "workspace:^",
"@backstage/backend-plugin-api": "workspace:^",
"@backstage/plugin-auth-node": "workspace:^",
"express": "^4.18.2",
"passport": "^0.6.0",
"passport-atlassian2": "^5.0.0"
},
"devDependencies": {
"@backstage/backend-defaults": "workspace:^",
"@backstage/backend-test-utils": "workspace:^",
"@backstage/cli": "workspace:^",
"@backstage/plugin-auth-backend": "workspace:^",
"supertest": "^6.3.3"
},
"configSchema": "config.d.ts",
"files": [
"dist",
"config.d.ts"
]
}
@@ -0,0 +1,77 @@
/*
* Copyright 2023 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Strategy as AtlassianStrategy } from 'passport-atlassian2';
import {
createOAuthAuthenticator,
PassportOAuthAuthenticatorHelper,
PassportOAuthDoneCallback,
PassportProfile,
} from '@backstage/plugin-auth-node';
/** @public */
export const atlassianAuthenticator = createOAuthAuthenticator({
defaultProfileTransform:
PassportOAuthAuthenticatorHelper.defaultProfileTransform,
initialize({ callbackUrl, config }) {
const clientId = config.getString('clientId');
const clientSecret = config.getString('clientSecret');
const baseUrl =
config.getOptionalString('audience') || 'https://atlassian.com';
return PassportOAuthAuthenticatorHelper.from(
new AtlassianStrategy(
{
clientID: clientId,
clientSecret: clientSecret,
callbackURL: callbackUrl,
baseURL: baseUrl,
authorizationURL: `${baseUrl}/oauth/authorize`,
tokenURL: `${baseUrl}/oauth/token`,
profileURL: `${baseUrl}/api/v4/user`,
},
(
accessToken: string,
refreshToken: string,
params: any,
fullProfile: PassportProfile,
done: PassportOAuthDoneCallback,
) => {
done(
undefined,
{ fullProfile, params, accessToken },
{ refreshToken },
);
},
),
);
},
async start(input, helper) {
return helper.start(input, {
accessType: 'offline',
prompt: 'consent',
});
},
async authenticate(input, helper) {
return helper.authenticate(input);
},
async refresh(input, helper) {
return helper.refresh(input);
},
});
@@ -0,0 +1,25 @@
/*
* Copyright 2023 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* The atlassian-provider backend module for the auth plugin.
*
* @packageDocumentation
*/
export { atlassianAuthenticator } from './authenticator';
export { authModuleAtlassianProvider as default } from './module';
export { atlassianSignInResolvers } from './resolvers';
@@ -0,0 +1,78 @@
/*
* Copyright 2023 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { mockServices, startTestBackend } from '@backstage/backend-test-utils';
import { authModuleAtlassianProvider } from './module';
import request from 'supertest';
import { decodeOAuthState } from '@backstage/plugin-auth-node';
describe('authModuleAtlassianProvider', () => {
it('should start', async () => {
const { server } = await startTestBackend({
features: [
import('@backstage/plugin-auth-backend'),
authModuleAtlassianProvider,
mockServices.rootConfig.factory({
data: {
app: {
baseUrl: 'http://localhost:3000',
},
auth: {
providers: {
atlassian: {
development: {
clientId: 'my-client-id',
clientSecret: 'my-client-secret',
},
},
},
},
},
}),
],
});
const agent = request.agent(server);
const res = await agent.get('/api/auth/atlassian/start?env=development');
expect(res.status).toEqual(302);
const nonceCookie = agent.jar.getCookie('atlassian-nonce', {
domain: 'localhost',
path: '/api/auth/atlassian/handler',
script: false,
secure: false,
});
expect(nonceCookie).toBeDefined();
const startUrl = new URL(res.get('location'));
expect(startUrl.origin).toBe('https://atlassian.com');
expect(startUrl.pathname).toBe('/oauth/authorize');
expect(Object.fromEntries(startUrl.searchParams)).toEqual({
response_type: 'code',
scope: 'read_user',
client_id: 'my-client-id',
redirect_uri: `http://localhost:${server.port()}/api/auth/atlassian/handler/frame`,
state: expect.any(String),
});
expect(decodeOAuthState(startUrl.searchParams.get('state')!)).toEqual({
env: 'development',
nonce: decodeURIComponent(nonceCookie.value),
});
});
});
@@ -0,0 +1,48 @@
/*
* Copyright 2023 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { createBackendModule } from '@backstage/backend-plugin-api';
import {
authProvidersExtensionPoint,
commonSignInResolvers,
createOAuthProviderFactory,
} from '@backstage/plugin-auth-node';
import { atlassianAuthenticator } from './authenticator';
import { atlassianSignInResolvers } from './resolvers';
/** @public */
export const authModuleAtlassianProvider = createBackendModule({
pluginId: 'auth',
moduleId: 'atlassian-provider',
register(reg) {
reg.registerInit({
deps: {
providers: authProvidersExtensionPoint,
},
async init({ providers }) {
providers.registerProvider({
providerId: 'atlassian',
factory: createOAuthProviderFactory({
authenticator: atlassianAuthenticator,
signInResolverFactories: {
...atlassianSignInResolvers,
...commonSignInResolvers,
},
}),
});
},
});
},
});
@@ -0,0 +1,50 @@
/*
* Copyright 2023 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
createSignInResolverFactory,
OAuthAuthenticatorResult,
PassportProfile,
SignInInfo,
} from '@backstage/plugin-auth-node';
/**
* Available sign-in resolvers for the Atlassian auth provider.
*
* @public
*/
export namespace atlassianSignInResolvers {
/**
* Looks up the user by matching their Atlassian username to the entity name.
*/
export const usernameMatchingUserEntityName = createSignInResolverFactory({
create() {
return async (
info: SignInInfo<OAuthAuthenticatorResult<PassportProfile>>,
ctx,
) => {
const { result } = info;
const id = result.fullProfile.username;
if (!id) {
throw new Error(`Atlassian user profile does not contain a username`);
}
return ctx.signInWithCatalogUser({ entityRef: { name: id } });
};
},
});
}
@@ -0,0 +1,25 @@
/*
* Copyright 2020 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
declare module 'passport-atlassian2' {
import { Request } from 'express';
import { StrategyCreated } from 'passport';
export class Strategy {
constructor(options: any, verify: any);
authenticate(this: StrategyCreated<this>, req: Request, options?: any): any;
}
}