JamesRandall / FunctionMonkey

Write more elegant Azure Functions with less boilerplate, more consistency, and support for REST APIs. Docs can be found at https://functionmonkey.azurefromthetrenches.com
MIT License
294 stars 50 forks source link

OpenAPI - Bearer Authentication #85

Open detroitpro opened 5 years ago

detroitpro commented 5 years ago

I followed the excellent guide to configuration bearer auth and configured our functions to generate swagger documentation but the swagger UI does not allow setting the bearer token.

Here is our FunctionAppConfiguration, are we doing something incorrect or is enabling setting the token in the openapi UI not a feature (yet)?

 public void Build(IFunctionHostBuilder builder)
    {
      builder
          .Setup((serviceCollection, commandRegistry) =>
          {
            serviceCollection
                  .AddApplication(commandRegistry)
                  .AddAutoMapper(typeof(SubSystemRegistration));
          })
          .Authorization(authorization => authorization
               .AuthorizationDefault(AuthorizationTypeEnum.TokenValidation)
               .TokenValidator<BearerTokenValidator>())
          .OpenApiEndpoint(openApi => openApi
              .Title("Open API Spec").UserInterface().Version("1.0.0"))
          .Functions(functions => functions
               .HttpRoute("dashboard", route => route.HttpFunction<DashboardQuery>(HttpMethod.Get))
          );
    }

I checked the generated openapi.yaml and it seems to be missing the section related to auth as described here: https://swagger.io/docs/specification/authentication/bearer-authentication/ - I'm just not sure if I am doing something wrong or if we should send a PR :)

image

JamesRandall commented 5 years ago

A PR would be gratefully received :)