diff --git a/modules/swagger-codegen/src/main/resources/dart/api_client.mustache b/modules/swagger-codegen/src/main/resources/dart/api_client.mustache index 7ab9ae90c710..e8e6a515b44c 100644 --- a/modules/swagger-codegen/src/main/resources/dart/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/dart/api_client.mustache @@ -153,4 +153,12 @@ class ApiClient { auth.applyToParams(queryParams, headerParams); }); } + + void setAccessToken(String accessToken) { + _authentications.forEach((key, auth) { + if (auth is OAuth) { + auth.setAccessToken(accessToken); + } + }); + } } diff --git a/modules/swagger-codegen/src/main/resources/dart/auth/oauth.mustache b/modules/swagger-codegen/src/main/resources/dart/auth/oauth.mustache index 4b26a7a8ddf9..5b96ecc9d7a9 100644 --- a/modules/swagger-codegen/src/main/resources/dart/auth/oauth.mustache +++ b/modules/swagger-codegen/src/main/resources/dart/auth/oauth.mustache @@ -1,9 +1,19 @@ part of {{pubName}}.api; class OAuth implements Authentication { + String accessToken; + + OAuth({this.accessToken}) { + } @override void applyToParams(List queryParams, Map headerParams) { - // TODO: support oauth + if (accessToken != null) { + headerParams["Authorization"] = "Bearer " + accessToken; + } + } + + void setAccessToken(String accessToken) { + this.accessToken = accessToken; } }