@@ -53,26 +53,33 @@ class LoginCommand extends PubCommand {
53
53
return await oauth2.withClient ((client) async {
54
54
final discovery = await oauth2.fetchOidcDiscoveryDocument ();
55
55
final userInfoEndpoint = discovery['userinfo_endpoint' ];
56
+
56
57
if (userInfoEndpoint is ! String ) {
57
- log.fine ('Bad discovery document. userinfo_endpoint not a String' );
58
+ log.fine (
59
+ 'Invalid discovery document: userinfo_endpoint is not a String' ,
60
+ );
58
61
return null ;
59
62
}
60
- final userInfoRequest = await client.get (Uri .parse (userInfoEndpoint));
61
- if (userInfoRequest.statusCode != 200 ) return null ;
63
+
64
+ final response = await client.get (Uri .parse (userInfoEndpoint));
65
+ if (response.statusCode != 200 ) {
66
+ log.fine ('Failed to fetch user info: HTTP ${response .statusCode }' );
67
+ return null ;
68
+ }
69
+
62
70
try {
63
- switch (json.decode (userInfoRequest.body)) {
64
- case {'name' : final String ? name, 'email' : final String email}:
65
- return _UserInfo (name, email);
66
- default :
67
- log.fine (
68
- 'Bad response from $userInfoEndpoint : ${userInfoRequest .body }' ,
69
- );
70
- return null ;
71
+ final decoded = json.decode (response.body);
72
+ if (decoded case {
73
+ 'name' : final String ? name,
74
+ 'email' : final String email,
75
+ }) {
76
+ return _UserInfo (name, email);
77
+ } else {
78
+ log.fine ('Unexpected user info format: ${response .body }' );
79
+ return null ;
71
80
}
72
81
} on FormatException catch (e) {
73
- log.fine (
74
- 'Bad response from $userInfoEndpoint ($e ): ${userInfoRequest .body }' ,
75
- );
82
+ log.fine ('Failed to decode user info: $e \n Response: ${response .body }' );
76
83
return null ;
77
84
}
78
85
});
0 commit comments