Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #4972
Closed
Open
Issue created Jan 11, 2020 by Administrator@rootContributor

[REQ] [Dart] Add Bearer token support to Dart2.x generation

Created by: froehlichA

Is your feature request related to a problem? Please describe.

The Dart2.x client generator currently only has support for the ApiKeyAuth, HttpBasicAuth and OAuth authentification schemes (available in lib/auth/), which are defined for the OpenAPI security schemes type: apiKey, type: http, scheme: basic and type: oauth2 respectively. No support for Bearer token authentication (type: http, scheme: bearer) exists.

Curiously, the OAuth scheme named oauth.dart doesn't define an oauth flow, but instead bearer auth.

Describe the solution you'd like

  • In the generated lib/auth/ folder, a http_bearer_auth.dart file should be created, that defines a bearer auth implementation (called HttpBearerAuth) like the current oauth.dart file.
  • If a OpenAPI security scheme such as type: http, scheme: bearer is defined, api_client.dart should automatically specify the bearer auth flow in it's constructor, like it does with current implementations:
class ApiClient {
  ...
  ApiClient({this.basePath = "https://dev.api.paketbox-systems.at/v1"}) {
    // Setup authentications (key: authentication name, value: authentication).
    _authentications['<auth-name>'] = HttpBearerAuth();
  }
}

Describe alternatives you've considered

It is possible to use bearer authentification right now, but only by specifying an apiKey security scheme, which might generate the correct dart code, but doesn't work well with other tools such as Postman.

The api specification of my team defines the following security scheme:

securitySchemes:
    simpleToken:
      type: apiKey # actually bearer
      in: header
      name: Authorization

and our dart code for setting for setting authentication looks like this:

defaultApiClient.getAuthentication<ApiKeyAuth>('simpleToken')
      ..apiKeyPrefix = 'Bearer'
      ..apiKey = loginFuture.value.accessToken;

Additional context

As far as I know, @dalewking implemented the current functionality in this merge request, so maybe he should take a look at this too.

Assignee
Assign to
Time tracking