Skip to content

Commit 0fea485

Browse files
authored
Merge pull request #58 from line/feature/email-getter
Add an email getter for access token
2 parents 66da15e + a774d08 commit 0fea485

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

example/lib/src/screen/home_page.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ class _HomePageState extends State<HomePage>
149149
.login(scopes: _selectedScopes.toList(), option: loginOption);
150150
final accessToken = await LineSDK.instance.currentAccessToken;
151151

152-
final idToken = result.accessToken.idToken;
153-
final userEmail = (idToken != null) ? idToken['email'] : null;
152+
final userEmail = result.accessToken.email;
154153

155154
setState(() {
156155
_userProfile = result.userProfile;
@@ -167,6 +166,7 @@ class _HomePageState extends State<HomePage>
167166
await LineSDK.instance.logout();
168167
setState(() {
169168
_userProfile = null;
169+
_userEmail = null;
170170
_accessToken = null;
171171
});
172172
} on PlatformException catch (e) {

lib/src/model/access_token.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,13 @@ class AccessToken {
9797
/// The expected authorization type when this token is used in a request
9898
/// header. Fixed to `Bearer` for now.
9999
String get tokenType => _data['token_type'];
100+
101+
/// The email address set by the user. This value only exists when `idToken` is
102+
/// valid and the user has set the email address in LINE and agreed to share it
103+
/// with you. Both "openid" and "email" scopes are required to get the user email.
104+
///
105+
/// If you are not applying an ID Token when login, or the user does not set
106+
/// the email for the LINE account, or the user refuses to grant your access,
107+
/// `null` is returned.
108+
String? get email => idToken?['email'];
100109
}

0 commit comments

Comments
 (0)