[dart] Fix authentication for dart (#2419)

* [dart] Fix authentication so all forms of Swagger 2.0 authentication work

* Run changes on petstore examples

* Amend dart2 generated README to cover basic authentication

* Amend dart2 generated README to cover authentication methods

* [dart] Fix authentication so all forms of Swagger 2.0 authentication work

* Run changes on petstore examples
This commit is contained in:
Dale King
2019-03-18 22:08:43 -04:00
committed by William Cheng
parent 1f45ea7d1a
commit d93fd31bb1
70 changed files with 425 additions and 365 deletions

View File

@@ -4,18 +4,20 @@ class ApiKeyAuth implements Authentication {
final String location;
final String paramName;
String apiKey;
String _apiKey;
String apiKeyPrefix;
set apiKey(String key) => _apiKey = key;
ApiKeyAuth(this.location, this.paramName);
@override
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
String value;
if (apiKeyPrefix != null) {
value = '$apiKeyPrefix $apiKey';
value = '$apiKeyPrefix $_apiKey';
} else {
value = apiKey;
value = _apiKey;
}
if (location == 'query' && value != null) {

View File

@@ -2,13 +2,15 @@ part of openapi.api;
class HttpBasicAuth implements Authentication {
String username;
String password;
String _username;
String _password;
@override
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
String str = (_username == null ? "" : _username) + ":" + (_password == null ? "" : _password);
headerParams["Authorization"] = "Basic " + base64.encode(utf8.encode(str));
}
set username(String username) => _username = username;
set password(String password) => _password = password;
}

View File

@@ -1,18 +1,16 @@
part of openapi.api;
class OAuth implements Authentication {
String accessToken;
String _accessToken;
OAuth({this.accessToken});
OAuth({String accessToken}) : _accessToken = accessToken;
@override
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
if (accessToken != null) {
headerParams["Authorization"] = "Bearer " + accessToken;
if (_accessToken != null) {
headerParams["Authorization"] = "Bearer $_accessToken";
}
}
void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
set accessToken(String accessToken) => _accessToken = accessToken;
}