Git Product home page Git Product logo

Comments (3)

Johnz86 avatar Johnz86 commented on July 29, 2024

There is no Authorize annotation, for which you can add your login handler like in Java JSR.
The best answer to get authorization to work is this:

#23

I do not like it, because you need to register authenticated routes with midlleware. It would be nicer, if we could use annotation for path with list of roles as parameter. Similar to @RolesAllowed and @secured in Java.

from typescript-rest.

ngraef avatar ngraef commented on July 29, 2024

Check out the new @Preprocessor feature as another way to implement this.

from typescript-rest.

creadicted avatar creadicted commented on July 29, 2024

I used header parameter:
@HeaderParam('Authorization') token: string;
and used that data in every controller i required a authentication

public async getById(@PathParam('id') id: number): Promise<ReturnType> {
        const requestUser: User = await verifyToken(this.token);
        return new Promise<any>(async function (resolve, reject) {
            if (!requestUser) {
                throw new Errors.BadRequestError('The request was not valid');
            } 

It is not the nicest way but it also gives me the user that made the request to make additional validations further down the line.
Not sure if the @preprocessor also allows the return of a value.

from typescript-rest.

Related Issues (20)

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.