swagger-api / swagger-api/swagger-codegen

[Dart] not possible to set authentication properties (apikey, username/password)

Open
#9,807 0 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Using the Dart generator, it is not possible to actually set authentication values for APIKeyAuth and HttpBasicAuth.

The ApiClient class generated maintains a map of authentication schemes:

Map<String, Authentication> _authentications = {};

The map is filled with schemes in ApiClient's constructor based on the Swagger API definition.

In use, it is not possible to actually set an API Key when using ApiKeyAuth, nor is it possible to actually set the username and password when using HttpBasicAuth.

As the _authentications map is private to the library (name starts with _), the authentications cannot be accessed externally, such as in an app using the generated API library.

PR https://github.com/swagger-api/swagger-codegen/pull/7528 made it possible to set the access token for OAuth authentication, but it is not possible to set authentication properties for the other auth schemes.

Swagger-codegen version

2.48 (compiled from Github master 31e7ea9248ef35917ba3659150031d576fc7c554)

Swagger declaration file content or url

N/A

Command line used for generation

N/A

Steps to reproduce

N/A

Related issues/PRs

https://github.com/swagger-api/swagger-codegen/pull/7528

Suggest a fix/enhancement

the OAuth implementation added a method to ApiClient to allow setting the access token. Either additional methods could be added for the equivalent functionality in ApiKeyAuth and HttpBasicAuth, or alternatively, the _authentications map could be made publicly visible, so that client code can directly set the authentication properties.

I'm happy to make a PR that resolves this, but would like some feedback on preferred approaches.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the Dart generator templates and the generated ApiClient class that owns the private _authentications map. Trace how APIKeyAuth and HttpBasicAuth are constructed, then check existing OAuth access-token handling. Done means generated clients expose a supported way to set API-key and username/password values, with coverage for those authentication schemes.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
api, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.