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

Use Authorization in Swagger UI with SecurityDefinition in .swagger.json #1683

Closed
SwissGipfel opened this issue Jan 9, 2024 · 2 comments
Closed
Labels
enhancement New feature or request stale

Comments

@SwissGipfel
Copy link

SwissGipfel commented Jan 9, 2024

Why

Since headscale currently has no WebUI, it would be a quality of life feature to enable using the Swagger UI directly in the web browser without installing an add-on. (For what I've seen so far, a relatively small change)

Description

Swagger 2.0 lets you define an authentication type for each API endpoint. This definition will also be displayed in swagger UI and is usable as such. With it an admin can leverage the APIs listed on the /swagger endpoint directly without using cli tools or browser add-on.

Even though the documentation for version 2.0 does not mention bearer tokens for authentication, it is still usable if type: apikey together with name: Authorization is used in the securityDefinitions. With this configuration, an admin can brows /swagger, press Authorize and provide the value "Bearer " followed by the effective token.

What I've tried by myself

I think I know what changes have to be made to the .swagger.json files to enable this feature. I've a locally development build version running (in a container) and as far as I can see it works, with:

{
  "swagger": "2.0",
  "info": {
    "title": "headscale/v1/headscale.proto",
    "version": "version not set"
  },
  "securityDefinitions": {
    "Bearer": {
      "type": "apiKey",
      "name": "Authorization",
      "in": "header",
      "description": "Bearer token for authentication. Please type in 'Bearer' followed by a space and then the token."
    }
  },
  "security": [
    {
      "Bearer": ["read", "write"]
    }
  ],
  // followed by the rest of the generated .swagger.json file

in /gen/openapiv2/headscale/v1/headscale.swagger.json.

But I do currently not know, what kind of changes I've to make, so that the next make generate command won't overwrite the files.

@SwissGipfel SwissGipfel added the enhancement New feature or request label Jan 9, 2024
@SwissGipfel SwissGipfel changed the title Use Authorization in Swagger UI with SecuirtyDefinition in .swagger.json Use Authorization in Swagger UI with SecurityDefinition in .swagger.json Jan 9, 2024
Copy link
Contributor

github-actions bot commented Apr 9, 2024

This issue is stale because it has been open for 90 days with no activity.

@github-actions github-actions bot added the stale label Apr 9, 2024
Copy link
Contributor

This issue was closed because it has been inactive for 14 days since being marked as stale.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request stale
Projects
None yet
Development

No branches or pull requests

1 participant