Skip to content

Commit 9a8c3fd

Browse files
committed
Removed JWT tokens logic
1 parent 5d09651 commit 9a8c3fd

File tree

6 files changed

+6
-32
lines changed

6 files changed

+6
-32
lines changed

plugins/stack-overflow-teams-backend/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The **Stack Overflow for Teams Backend plugin** is responsible for:
1313
- `/questions`
1414
- Posting new questions via `/questions`
1515
- **Managing OAuth authentication flow** to securely access Stack Overflow private instances via ``createStackOverflowAuth``
16-
- **Encrypts** the Stack Overflow Token before sending it as an http-only cookie to the frontend.
16+
- **HTTP-only cookie** the Stack Overflow Token is set as a secure http-only cookie to the frontend with 24 hours expiration.
1717

1818
## OAuth Authentication Flow
1919

@@ -33,8 +33,7 @@ The backend is the only component that directly utilizes the **encrypted Stack O
3333
- Retrieves the stored **Code Verifier** and **State**.
3434
- Validates that the received **state** matches the one from Stack Overflow's query string parameter.
3535
- The backend requests an **Access Token** using the stored **Code Verifier**.
36-
- Backend **encrypts the token**, using the JWT secret stored in memory.
37-
- Stores the **encrypted Stack Overflow Access Token** in a **secure, HTTP-only cookie**.
36+
- Stores the **Stack Overflow Access Token** in a **secure, HTTP-only cookie**.
3837

3938
## Installation
4039

plugins/stack-overflow-teams-backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "backstage-plugin-stack-overflow-teams-backend",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"main": "src/index.ts",
55
"types": "src/index.ts",
66
"license": "Apache-2.0",

plugins/stack-overflow-teams-backend/src/plugin.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
coreServices,
33
createBackendPlugin,
44
} from '@backstage/backend-plugin-api';
5-
import { randomBytes } from 'crypto'
65
import { createRouter } from './router';
76
import { createStackOverflowService } from './services/StackOverflowService';
87
import { StackOverflowConfig } from './services/StackOverflowService';
@@ -13,8 +12,6 @@ import { StackOverflowConfig } from './services/StackOverflowService';
1312
* @public
1413
*/
1514

16-
const JWT_SECRET = randomBytes(64).toString('hex')
17-
1815
export const stackOverflowTeamsPlugin = createBackendPlugin({
1916
pluginId: 'stack-overflow-teams',
2017
register(env) {
@@ -41,8 +38,7 @@ export const stackOverflowTeamsPlugin = createBackendPlugin({
4138
await createRouter({
4239
stackOverflowConfig,
4340
logger,
44-
stackOverflowService,
45-
jwtSecret: JWT_SECRET
41+
stackOverflowService
4642
}),
4743
);
4844
},

plugins/stack-overflow-teams-backend/src/router.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,15 @@ import {
66
StackOverflowConfig,
77
} from './services/StackOverflowService/types';
88
import { createStackOverflowAuth } from './api';
9-
import { decryptToken, encryptToken } from './utils';
109

1110
export async function createRouter({
1211
logger,
1312
stackOverflowConfig,
1413
stackOverflowService,
15-
jwtSecret,
1614
}: {
1715
logger: LoggerService;
1816
stackOverflowConfig: StackOverflowConfig;
1917
stackOverflowService: StackOverflowAPI;
20-
jwtSecret: string;
2118
}): Promise<express.Router> {
2219
const router = Router();
2320
const authService = createStackOverflowAuth(stackOverflowConfig, logger);
@@ -42,7 +39,7 @@ export async function createRouter({
4239
const cookiesToken = cookies['stackoverflow-access-token'];
4340

4441
try {
45-
const authToken = decryptToken(cookiesToken, jwtSecret);
42+
const authToken = cookiesToken
4643
if (!authToken) {
4744
res.clearCookie('stackoverflow-access-token');
4845
return null;
@@ -94,12 +91,11 @@ export async function createRouter({
9491
codeVerifier,
9592
);
9693

97-
const encryptedToken = encryptToken(accessToken, jwtSecret);
9894
// The cookie's max age is linked to the Token's expiration, the default expiration is 24 hours.
9995
return res
10096
.clearCookie('socodeverifier')
10197
.clearCookie('state')
102-
.cookie('stackoverflow-access-token', encryptedToken, {
98+
.cookie('stackoverflow-access-token', accessToken, {
10399
httpOnly: true,
104100
secure: process.env.NODE_ENV === 'production',
105101
sameSite: 'strict',
@@ -227,7 +223,6 @@ export async function createRouter({
227223
const tags = await stackOverflowService.getTags(authToken);
228224
return res.send(tags);
229225
} catch (error: any) {
230-
// Fix type issue when including the error for some reason
231226
logger.error('Error fetching tags', { error });
232227
return res.status(500).send({
233228
error: `Failed to fetch tags from the Stack Overflow instance`,
@@ -246,7 +241,6 @@ export async function createRouter({
246241
const users = await stackOverflowService.getUsers(authToken);
247242
return res.send(users);
248243
} catch (error: any) {
249-
// Fix type issue when including the error for some reason
250244
logger.error('Error fetching users', { error });
251245
return res.status(500).send({
252246
error: `Failed to fetch users from the Stack Overflow instance`,

plugins/stack-overflow-teams-backend/src/utils/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

plugins/stack-overflow-teams-backend/src/utils/jwtUtils.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)