From f1638a659af59b6ad2c369fb58604321a273a1bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Ahrens?= Date: Tue, 30 Jan 2018 04:04:04 +0100 Subject: [PATCH] [Dart] Allow setting an accessToken for OAuth (#7528) * dart - allow setting an accessToken for oauth * Remove unneeded accessToken member --- .../src/main/resources/dart/api_client.mustache | 8 ++++++++ .../src/main/resources/dart/auth/oauth.mustache | 12 +++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) 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 7ab9ae90c71..e8e6a515b44 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 4b26a7a8ddf..5b96ecc9d7a 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; } }