Skip to content

Commit

Permalink
[Dart] Allow setting an accessToken for OAuth (#7528)
Browse files Browse the repository at this point in the history
* dart - allow setting an accessToken for oauth

* Remove unneeded accessToken member
  • Loading branch information
Jörn Ahrens authored and wing328 committed Jan 30, 2018
1 parent eb35870 commit f1638a6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit f1638a6

Please sign in to comment.