blob: 4a1d8b23d0ee7bd3e505ded7e7f501e27b286e90 [file] [log] [blame] [edit]
// Copyright 2021 Google LLC
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
import 'access_token.dart';
/// OAuth2 Credentials.
class AccessCredentials {
/// An access token.
final AccessToken accessToken;
/// A refresh token, which can be used to refresh the access credentials.
final String? refreshToken;
/// A JWT used in calls to Google APIs that accept an id_token param.
final String? idToken;
/// Scopes these credentials are valid for.
final List<String> scopes;
AccessCredentials(
this.accessToken,
this.refreshToken,
this.scopes, {
this.idToken,
});
factory AccessCredentials.fromJson(Map<String, dynamic> json) =>
AccessCredentials(
AccessToken.fromJson(json['accessToken'] as Map<String, dynamic>),
json['refreshToken'] as String?,
(json['scopes'] as List<dynamic>).map((e) => e as String).toList(),
idToken: json['idToken'] as String?,
);
Map<String, dynamic> toJson() => <String, dynamic>{
'accessToken': accessToken,
if (refreshToken != null) 'refreshToken': refreshToken,
'idToken': idToken,
'scopes': scopes,
};
}