Skip to content

Commit 6b59c7b

Browse files
authored
Merge pull request #238 from map-of-pi/revisit-header-extraction
Self approved.
2 parents 617ebba + ba34aa4 commit 6b59c7b

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

src/config/docs/UsersSchema.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
components:
2+
securitySchemes:
3+
BearerAuth:
4+
type: http
5+
scheme: bearer
6+
27
schemas:
38
AuthenticateUserRq:
49
type: object

src/middlewares/isPioneerFound.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@ export const isPioneerFound = async (
88
res: Response,
99
next: NextFunction
1010
) => {
11-
const auth = req.body.pioneerAuth;
11+
const authHeader = req.headers.authorization;
12+
const tokenFromHeader = authHeader && authHeader.split(" ")[1];
1213

1314
try {
1415
logger.info("Verifying user's access token with the /me endpoint.");
1516
// Verify the user's access token with the /me endpoint:
1617
const me = await platformAPIClient.get(`/v2/me`, {
17-
headers: { 'Authorization': `Bearer ${auth.accessToken}` }
18+
headers: { 'Authorization': `Bearer ${ tokenFromHeader }` }
1819
});
1920

20-
if (me) {
21+
if (me && me.data) {
2122
const user = {
2223
pi_uid: me.data.uid,
2324
pi_username: me.data.username,

src/routes/user.routes.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,9 @@ const userRoutes = Router();
2929
* post:
3030
* tags:
3131
* - User
32-
* summary: Authenticate the user's access token
33-
* requestBody:
34-
* required: true
35-
* content:
36-
* application/json:
37-
* schema:
38-
* type: object
39-
* properties:
40-
* pioneerAuth:
41-
* type: object
42-
* properties:
43-
* accessToken:
44-
* type: string
45-
* example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2NjZiYmFlNGEwNWJjYzNkOGRmYWI1NjMiLCJpYXQiOjE3MTgzMzk0MDksImV4cCI6MTcyMDkzMTQwOX0.gFz-EdHoOqz3-AuFX5R4uGtruFaTMH8sTOXEX-3c7yw
46-
* required:
47-
* - pioneerAuth
32+
* summary: Authenticate the user's access token *
33+
* security:
34+
* - BearerAuth: []
4835
* responses:
4936
* 200:
5037
* description: Successful response

0 commit comments

Comments
 (0)