Giter Site home page Giter Site logo

sum-jwt's Introduction

Coding Assignment

  • A 2021 code assigment- The goal of this assignment is to build a simple HTTP service (with the appropriate unit tests) with two endpoints:

POST /auth

Accepts JSON input in the format:

{"username": "<user name>", "password": "<user password>"}

and returns JWT OAUTH 2/OIDC token with the username as a subject. The username and the password don't have to be verified, but should not accept empty strings. The JWT token should expire in one hour.

It should return appropriate error status code if the JSON payload is not valid, or the username and password are not valid (are empty)

POST /sum

Protected with a valid JWT token, generated by the /auth endpoint, provided as a Bearer Authorization header.

Accepts arbitrary JSON document as payload, which can contain a variety of things: arrays [1,2,3,4], objects {"a":1, "b":2, "c":3}, numbers, and strings. The endpoint should find all of the numbers throughout the document and add them together.

For example:

  • [1,2,3,4] and {"a":6,"b":4} both have a sum of 10.
  • [[[2]]] and {"a":{"b":4},"c":-2} both have a sum of 2.
  • {"a":[-1,1,"dark"]} and [-1,{"a":1, "b":"light"}] both have a sum of 0.
  • [] and {} both have a sum of 0.

The response should be the SHA256 hash of the sum of all numbers in the document. It should return the appropriate error status code if the JWT token or the JSON payload are not valid.

Architecture:

  • Hexagonal(Onion) like design, build to separate different adapters, from the application and domain layers, achieved by relaying on dependency injection through interfaces.
  • Logs and custom error handling were left out due the simplicity of the task and the time.
  • No third party lib for testing, thanks to the design everything can be mocked easily.
  • JWT is based on this article

Note: Beside the documentation there are plenty of comments as notes in the code that describe what should be done or improved.

sum-jwt's People

Watchers

Robert Marinov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.