forked from loafle/openapi-generator-original
[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:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user