Skip to content

Commit 2b98eb8

Browse files
authored
Updated admin model to register auth provider type (#568)
* Updated admin model to register auth provider type * fix: sync npm-shrinkwrap file with package.json
1 parent fa49de7 commit 2b98eb8

File tree

6 files changed

+103
-41
lines changed

6 files changed

+103
-41
lines changed

README.md

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,43 @@ Main features:
4242
2. Add .env-cmdrc file into the project directory (use '.env-cmdrc-template')
4343
3. Replace values such as secret keys and URLs
4444

45+
### Auth Providers
46+
47+
Switcher API supports multiple auth providers such as email/password-based authentication or GitHub, Bitbucket OAuth.
48+
49+
Follow the steps below to set up your OAuth App in GitHub and Bitbucket.
50+
51+
#### GitHub OAuth App setup
52+
53+
1. Open your GitHub account or organization settings
54+
2. Go to Developer settings > OAuth Apps
55+
3. Click on "New OAuth App"
56+
4. Fill in the application details:
57+
- Application name: Switcher API
58+
- Homepage URL: https://switcher-management-url (or your deployed URL)
59+
- Authorization callback URL: https://switcher-management-url/login?platform=github
60+
5. Click on "Register application"
61+
6. Copy the Client ID and Client Secret
62+
7. Update your .env-cmdrc file or ConfigMap/Secret in Kubernetes with the following variables:
63+
- GIT_OAUTH_CLIENT_ID=your_client_id
64+
- GIT_OAUTH_CLIENT_SECRET=your_client_secret
65+
8. Update Switcher Management GITHUB_CLIENTID environment variable with your_client_id
66+
67+
#### Bitbucket OAuth App setup
68+
69+
1. Open your Bitbucket account or workspace settings
70+
2. Go to Apps and features > OAuth consumers
71+
3. Fill in the application details:
72+
- Name: Switcher API
73+
- Callback URL: https://switcher-management-url/login?platform=bitbucket
74+
4. Add permissions -> Account: Read
75+
5. Click on "Save"
76+
6. Copy the Key and Secret
77+
7. Update your .env-cmdrc file or ConfigMap/Secret in Kubernetes with the following variables:
78+
- BIT_OAUTH_CLIENT_ID=your_client_id
79+
- BIT_OAUTH_CLIENT_SECRET=your_client_secret
80+
8. Update Switcher Management BITBUCKET_CLIENTID environment variable with your_client_id
81+
4582
### Running Switcher API from Docker Composer manifest file
4683

4784
This option leverages Switcher API and Switcher Management with minimum settings required.
@@ -85,8 +122,8 @@ It is equivalent to an organization that can manage multiple projects, users, an
85122
- **New domain** - Domain: /domain/create [POST]
86123

87124
### Component
88-
Components are applications that are using Switcher API.<br>
89-
Each component has its own access token and needs to be linked to Switchers.
125+
Components are applications that will use Switcher API.<br>
126+
Each component has its own access API key to interact with Switcher API.
90127

91128
- **Create a component** - Component: /component/create [POST]
92129
- **Generating a new API Key** - Component: /component/generateApiKey [GET]
@@ -97,11 +134,11 @@ Groups are used to organize Switchers that share the same feature scope.
97134
- **New Group** - GroupConfig: /groupconfig/create [POST]
98135

99136
### Switcher
100-
Switchers are the main entities to control features.
137+
Switchers are the entry point to control features in your application.<br>
101138

102139
- **New Switcher** - Config: /config/create [POST]
103140

104141
### Strategy
105-
Customize the behavior of the Switcher by including strategy rules to your Switchers.
142+
Customize the Switcher behavior by including strategy rules to your Switchers.
106143

107144
- **New Strategy** - ConfigStrategy: /configstrategy/create [POST]

npm-shrinkwrap.json

Lines changed: 46 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
],
3737
"license": "MIT",
3838
"dependencies": {
39-
"axios": "^1.11.0",
39+
"axios": "^1.12.1",
4040
"bcryptjs": "^3.0.2",
4141
"cors": "^2.8.5",
4242
"express": "^5.1.0",
@@ -51,7 +51,7 @@
5151
"moment": "^2.30.1",
5252
"mongodb": "^6.19.0",
5353
"mongoose": "^8.18.1",
54-
"pino": "^9.9.4",
54+
"pino": "^9.9.5",
5555
"pino-pretty": "^13.1.1",
5656
"swagger-ui-express": "^5.0.1",
5757
"switcher-client": "^4.4.1",

src/api-docs/schemas/admin.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ export const admin = {
1717
type: 'boolean',
1818
description: 'Whether the admin is active or not'
1919
},
20+
auth_provider: {
21+
type: 'string',
22+
enum: ['email', 'github', 'bitbucket'],
23+
description: 'Authentication provider used'
24+
},
2025
teams: {
2126
type: 'array',
2227
items: {

src/models/admin.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ const adminSchema = new mongoose.Schema({
4040
code: {
4141
type: String
4242
},
43+
auth_provider: {
44+
type: String,
45+
enum: ['email', 'github', 'bitbucket'],
46+
default: 'email'
47+
},
4348
_gitid: {
4449
type: String
4550
},
@@ -176,6 +181,7 @@ adminSchema.statics.createThirdPartyAccount = async (
176181
admin = new Admin({
177182
name: userInfo.name,
178183
email: userInfo.email,
184+
auth_provider: platform,
179185
[`${attributeIdName}`]: userInfo.id,
180186
_avatar: userInfo.avatar,
181187
password: hash

tests/admin.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ describe('Testing Admin insertion', () => {
5555
// DB validation - document created
5656
const admin = await Admin.findById(response.body.admin._id).lean().exec();
5757
expect(admin).not.toBeNull();
58+
expect(admin.auth_provider).toBe('email');
5859

5960
//used at: ADMIN_SUITE - Should confirm access to a new Admin
6061
signedupUser = response.body.admin._id;
@@ -282,6 +283,7 @@ describe('Testing Admin insertion', () => {
282283
const admin = await Admin.findById(response.body.admin._id).lean().exec();
283284
expect(admin).not.toBeNull();
284285
expect(admin._gitid).toEqual('123456789');
286+
expect(admin.auth_provider).toBe('github');
285287

286288
// restore
287289
axiosPostStub.restore();
@@ -320,6 +322,7 @@ describe('Testing Admin insertion', () => {
320322
const admin = await Admin.findById(response.body.admin._id).lean().exec();
321323
expect(admin).not.toBeNull();
322324
expect(admin._bitbucketid).toEqual('123456789');
325+
expect(admin.auth_provider).toBe('bitbucket');
323326

324327
// restore
325328
axiosPostStub.restore();

0 commit comments

Comments
 (0)