Skip to content

Extract scopes from request.routeOptions.schema.security #17

Description

@TastyPi

Describe the problem you'd like to have solved

If I have an endpoint:

fastify.post("/foo", {
  schema: {
    security: [{Auth0: ["foo"]}]
  },
  preParsing: fastify.requireAuth({ scopes: ["foo"] })
})

It would be nice if requireAuth could automatically extract the scopes from the schema, so I don't have to specify them in two places.

Describe the ideal solution

Maybe something like this:

fastify.post("/foo", {
  schema: {
    security: [{Auth0: ["foo"]}]
  },
  preParsing: fastify.requireAuth({ schema: [0, "Auth0"] })
})

Maybe a global config to allow for just fastify.requireAuth()

Alternatives and current work-arounds

  • Deal with the minor duplication
  • Define the scopes in a const

Additional context

It's just a nice to have, not a big deal

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions