[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, ahttp_bearer_auth.dart
file should be created, that defines a bearer auth implementation (calledHttpBearerAuth
) like the currentoauth.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.