-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathauth-data.dart
74 lines (66 loc) · 2.08 KB
/
auth-data.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import 'dart:convert';
/// This class contains the access token and
/// variables that provide easy access to the
/// common properties of a user. It also contains
/// all data from the authentication response and
/// the user response in 'response' and 'userJson'
/// respectively.
class AuthData {
const AuthData({
this.clientID,
this.accessToken,
this.firstName,
this.lastName,
this.userID,
this.email,
this.profileImgUrl,
this.userJson,
this.response,
});
final String? userID; // User's profile id
final String? clientID; // OAuth client id
final String? accessToken; // OAuth access token
final String? firstName; // User's first name
final String? lastName; // User's last name
final String? email; // User's email
final String? profileImgUrl; // User's profile image url
final Map<String, dynamic>? userJson; // Full returned user json
final Map<String, String>? response; // Full returned auth response.
/// Creates a formatted string from
/// the response data.
String _formatResponse() {
StringBuffer result = StringBuffer('\n');
if (response != null) {
for (MapEntry data in response!.entries) {
result.write('\t\t\t\t');
result.write(data.key);
result.write(' = ');
result.write(data.value);
result.write('\n');
}
}
return result.toString();
}
/// Formats user json for printing
String _formatJson() {
return JsonEncoder.withIndent(' ').convert(userJson);
}
/// The only public method in this class
/// Returns all the data in this class as
/// a formatted string.
@override
String toString() {
String responseString = _formatResponse();
String prettyUserJson = _formatJson();
return 'AuthData {\n\n'
'\t\ttoken: $accessToken\n\n'
'\t\tuser id: $userID\n\n'
'\t\tfirst name: $firstName\n\n'
'\t\tlast name: $lastName\n\n'
'\t\temail: $email\n\n'
'\t\tprofile image: $profileImgUrl\n\n'
'\t\tresponse: $responseString\n'
'\t\tuser json: $prettyUserJson\n\n'
'}';
}
}