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

Multi authentication & authorization for routes #275

Merged
merged 5 commits into from
Sep 20, 2021
Merged

Multi authentication & authorization for routes #275

merged 5 commits into from
Sep 20, 2021

Conversation

icebob
Copy link
Member

@icebob icebob commented Sep 20, 2021

This PR adds feature to define custom authentication and authorization methods for every routes. In this case you should set the method name instead of true value.

Example

module.exports = {
    mixins: ApiGatewayService,

    settings: {

        routes: [
            {
                path: "/aaa",
                authentication: "aaaAuthn",
                authorization: "aaaAuthz",
                aliases: {
                    "GET hello": "test.hello"
                }
            },
            {
                path: "/bbb",
                authentication: "bbbAuthn",
                authorization: "bbbAuthz",
                aliases: {
                    "GET hello": "test.hello"
                }
            },
            {
                path: "/ccc",
                authentication: true,
                authorization: true,
                aliases: {
                    "GET hello": "test.hello"
                }
            }
        ]
    },

    methods: {
        aaaAuthn() {
            this.logger.info("Called 'aaaAuthn' method.");
        },
        aaaAuthz() {
            this.logger.info("Called 'aaaAuthz' method.");
        },

        bbbAuthn() {
            this.logger.info("Called 'bbbAuthn' method.");
        },
        bbbAuthz() {
            this.logger.info("Called 'bbbAuthz' method.");
        },

        authenticate() {
            this.logger.info("Called original 'authenticate' method.");
        },
        authorize() {
            this.logger.info("Called original 'authorize' method.");
        }
    }
}

@icebob icebob merged commit d5cbf35 into master Sep 20, 2021
@icebob icebob deleted the multi-auth branch September 20, 2021 20:37
@intech
Copy link
Member

intech commented Sep 21, 2021

@icebob I propose to add the ability not only to the name of the method, but also to specify the service.action.

@icebob
Copy link
Member Author

icebob commented Sep 21, 2021

I don't feel it's a common use-case, because for authentication you should access to the req which is not serializable, so you can't send it to a remote action. It's most common, if you get the info from req and make an action call in a method.

@intech
Copy link
Member

intech commented Sep 21, 2021

You're right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants