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

Bearer Token #87

Open
pgsnimble opened this issue Apr 29, 2022 · 2 comments
Open

Bearer Token #87

pgsnimble opened this issue Apr 29, 2022 · 2 comments

Comments

@pgsnimble
Copy link

Hey, how u doing?

How should I configure the ApiPath annotation to accept bearer authentication?

Thank you

@pgsnimble
Copy link
Author

I have discovered. I think we could add it into the README documentation since it will help others. If you allow, I will create a fork adding this section.

For who is also trying to configure it, just follow the bellow steps:

  1. Add the securityDefinitions section in your app
this.express.use(swagger.express(
            {
                definition: {
                    info: {
                        title: 'Backend',
                        version: '0.0.1'
                    },
                    host: 'localhost:3000',
                    securityDefinitions: {
                        bearerAuth: {
                            type: SwaggerDefinitionConstant.Security.Type.API_KEY,
                            in: SwaggerDefinitionConstant.Security.In.HEADER,
                            name: 'Authorization'
                        }
                    }
                }
            }
        ))
  1. In your controllers put the bearer auth
@ApiPath({
    path: '/companies',
    name: 'Company',
    security: {
        bearerAuth: []
    }
})

In the swagger authorization don't forget to put the access token in the follow format: Bearer {your access_token}

@theCreatorAniket
Copy link

Hi! Thank You so much for this solution. I have another doubt. I want to upload a file in one of the APIs. I am not able to figure out how to achieve this. It would be really helpful if you can help me out with this.

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

No branches or pull requests

2 participants