Skip to content

Commit 2775e25

Browse files
authored
feat: stripping out all jwt work as it was an unused experiment (#7)
1 parent 2e1bc33 commit 2775e25

8 files changed

+1611
-6225
lines changed

package-lock.json

+1,610-5,994
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/node/__tests__/create-jwt-link.test.js

-41
This file was deleted.

packages/node/__tests__/get-readme-data.test.js

-39
This file was deleted.

packages/node/__tests__/index.test.js

-69
Original file line numberDiff line numberDiff line change
@@ -126,73 +126,4 @@ describe('#metrics', () => {
126126
mock.done();
127127
}, 5000);
128128
});
129-
130-
describe('#login', () => {
131-
beforeEach(() => {
132-
nock.disableNetConnect();
133-
nock.enableNetConnect('127.0.0.1');
134-
});
135-
136-
afterEach(() => nock.cleanAll());
137-
138-
it('should error if missing apiKey', () => {
139-
expect(() => {
140-
middleware.login();
141-
}).toThrow('You must provide your ReadMe API key');
142-
});
143-
144-
it('should error if missing user function', () => {
145-
expect(() => {
146-
middleware.login(apiKey);
147-
}).toThrow('You must provide a function to get the user');
148-
});
149-
150-
describe('redirect flows', () => {
151-
beforeEach(() => {
152-
nock(config.readmeUrl)
153-
.get('/api/v1/')
154-
.basicAuth({
155-
user: apiKey,
156-
pass: '',
157-
})
158-
.reply(200, { jwtSecret: 'jwt', baseUrl: 'http://readme.readme.io' });
159-
});
160-
161-
it('should redirect if no user', () => {
162-
const app = express();
163-
164-
app.get(
165-
'/readme',
166-
middleware.login(apiKey, () => false, {
167-
loginUrl: '/login',
168-
})
169-
);
170-
171-
return request(app)
172-
.get('/readme')
173-
.expect(302)
174-
.expect(res => {
175-
expect(res.header.location.startsWith('/login?redirect=')).toBe(true);
176-
});
177-
});
178-
179-
it('should redirect to readme if user', () => {
180-
const app = express();
181-
182-
app.get(
183-
'/readme',
184-
middleware.login(apiKey, () => ({ name: 'marc' }), {
185-
loginUrl: '/login',
186-
})
187-
);
188-
189-
return request(app)
190-
.get('/readme')
191-
.expect(302)
192-
.expect(res => {
193-
expect(res.header.location.startsWith('http://readme.readme.io?auth_token=')).toBe(true);
194-
});
195-
});
196-
});
197-
});
198129
});

packages/node/index.js

-32
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ const request = require('r2');
22
const config = require('./config');
33

44
const constructPayload = require('./lib/construct-payload');
5-
const createJWTLink = require('./lib/create-jwt-link');
6-
const getReadmeData = require('./lib/get-readme-data');
75

86
// We're doing this to buffer up the response body
97
// so we can send it off to the metrics server
@@ -73,33 +71,3 @@ module.exports.metrics = (apiKey, group, options = {}) => {
7371
return next();
7472
};
7573
};
76-
77-
module.exports.login = (apiKey, getUser, options = {}) => {
78-
if (!apiKey) throw new Error('You must provide your ReadMe API key');
79-
if (!getUser) throw new Error('You must provide a function to get the user');
80-
81-
// Make sure api key is valid
82-
getReadmeData(apiKey);
83-
84-
return async (req, res, next) => {
85-
let u;
86-
try {
87-
u = getUser(req);
88-
} catch (e) {
89-
// User isn't logged in
90-
}
91-
92-
if (!u) {
93-
const domain = req.headers['x-forwarded-host'] || req.get('host');
94-
const fullUrl = `${req.protocol}://${domain}${req.originalUrl}`;
95-
return res.redirect(`${options.loginUrl}?redirect=${encodeURIComponent(fullUrl)}`);
96-
}
97-
98-
try {
99-
const jwtUrl = await createJWTLink(apiKey, u, req.query.redirect);
100-
return res.redirect(jwtUrl);
101-
} catch (e) {
102-
return next(e);
103-
}
104-
};
105-
};

packages/node/lib/create-jwt-link.js

-24
This file was deleted.

packages/node/lib/get-readme-data.js

-23
This file was deleted.

packages/node/package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
},
88
"dependencies": {
99
"content-type": "^1.0.4",
10-
"jsonwebtoken": "^8.3.0",
1110
"lodash": "^4.17.15",
12-
"r2": "^2.0.1",
13-
"uuid": "^8.1.0"
11+
"r2": "^2.0.1"
1412
},
1513
"scripts": {
1614
"lint": "eslint .",

0 commit comments

Comments
 (0)