[Dart] Allow setting an accessToken for OAuth (#7528)

* dart - allow setting an accessToken for oauth

* Remove unneeded accessToken member
This commit is contained in:
Jörn Ahrens 2018-01-30 04:04:04 +01:00 committed by William Cheng
parent eb35870d11
commit f1638a659a
2 changed files with 19 additions and 1 deletions

View File

@ -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);
}
});
}
}

View File

@ -1,9 +1,19 @@
part of {{pubName}}.api;
class OAuth implements Authentication {
String accessToken;
OAuth({this.accessToken}) {
}
@override
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
// TODO: support oauth
if (accessToken != null) {
headerParams["Authorization"] = "Bearer " + accessToken;
}
}
void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
}