Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: Unify restricted use token generation and validation #70

Closed
2 tasks done
tiblu opened this issue Dec 19, 2018 · 4 comments
Closed
2 tasks done

API: Unify restricted use token generation and validation #70

tiblu opened this issue Dec 19, 2018 · 4 comments
Assignees
Labels
enhancement Making an existing feature better. good first issue Good for newcomers.

Comments

@tiblu
Copy link
Member

tiblu commented Dec 19, 2018

Overview

We issue restricted use JWT tokens for very specific authorization:

  • We issue a token to Topic Moderators, to moderate a Topic. This token is sent in e-mail.
  • We issue a token to User after singing a Vote so that signed container can be downloaded. Not all Users have to be logged in for signing thus enables unauthenticated download of their Vote.
  • We issue a token to Riigikogu (Parliament) so that they can add updates to Events (follow-up phase)
  • We issue a token to Riigikogu (Parliament) so that they can download signed Topic container.
    ...

Problem

The restricted use token format varies quite a bit in the system and creates significant amount of complexity/confusion/overhead in the code-base. It calls for a rewrite so that we can reuse the issuing and validation code.

What token formats are present, where are they issued?

Token usually contains JWT standard parts + Citizen OS extras. The variance is in the Citizen OS extras. For example path (string), paths (Array) where there may or may not be req.method prefix.

Different path/method format used:here that format is used.

Proposed solution

  • Rewrite all restricted token issuing code to use audience claim (aud) to specify the scope of use:
    • aud (was path/paths) - Array - with REST method everywhere. Separated by space instead of "_". For example: "aud": ["GET /api/users/self/topics/:topicId/votes/:voteId/downloads/bdocs/final"]
  • Create a new middleware to validate these tokens. Call it authTokenRestrictedUse.
    • NOTE: MUST be backward compatible (path vs paths, vs scope) with formats above. Make a comment that other formats are deprecated so that if we know that it's unlikely for an old token to be used, we can delete the backward compatibility.
@tiblu tiblu mentioned this issue Dec 19, 2018
25 tasks
@tiblu tiblu self-assigned this Dec 19, 2018
@tiblu tiblu added this to Wish list in Winter Push For Perfection (WPFP) via automation Dec 19, 2018
@tiblu tiblu added enhancement Making an existing feature better. good first issue Good for newcomers. labels Dec 19, 2018
@tiblu tiblu moved this from Wish list to In Progress - assigned and worked on in Winter Push For Perfection (WPFP) Dec 19, 2018
tiblu added a commit that referenced this issue Jan 8, 2019
@tiblu
Copy link
Member Author

tiblu commented Jan 9, 2019

Expects tokens payload path to match req.path:

  • GET /api/users/:userId/topics/:topicId/votes/:voteId/downloads/bdocs/final
    • Update tests
  • GET /api/topics/:topicId/votes/:voteId/downloads/bdocs/final - the Parliament e-mail! BW COMP!
    • Update tests
    • BW comp test
  • GET /api/users/:userId/topics/:topicId/votes/:voteId/downloads/zip/final
    • Update tests
  • GET /api/topics/:topicId/votes/:voteId/downloads/zip/final
    • Update tests
  • POST /api/topics/:topicId/events - the Parliament e-mail! BW COMP!
    • Update tests
    • BW comp test
  • GET /api/topics/:topicId/comments/:commentId/reports/:reportId
    • Update tests
    • BW comp test
  • GET /api/users/:userId/topics/:topicId/comments/:commentId/reports/:reportId
    • Update tests
    • BW comp test
  • POST /api/topics/:topicId/comments/:commentId/reports/:reportId/moderate
    • Update tests
    • BW comp test

@tiblu
Copy link
Member Author

tiblu commented Jan 14, 2019

Created a library to issue and verify the restricted use tokens - https://github.com/citizenos/citizenos-api/blob/master/libs/cosJwt.js
Created a middleware to validate restricted use tokens and used where possible - https://github.com/citizenos/citizenos-api/blob/master/libs/middleware/authTokenRestrictedUse.js

@tiblu
Copy link
Member Author

tiblu commented Jan 14, 2019

Idea for TESTING ONLY: sniffer that validates all API links sent in e-mails, checks that they work.
#81

@tiblu
Copy link
Member Author

tiblu commented Jan 15, 2019

Live.

@tiblu tiblu closed this as completed Jan 15, 2019
Winter Push For Perfection (WPFP) automation moved this from In Progress - assigned and worked on to DONE - deployed to production Jan 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Making an existing feature better. good first issue Good for newcomers.
Projects
No open projects
Winter Push For Perfection (WPFP)
  
DONE - deployed to production
Development

No branches or pull requests

1 participant