line / flutter_line_sdk

A Flutter plugin that lets developers access LINE's native SDKs in Flutter apps with Dart.
https://developers.line.biz/
Apache License 2.0
213 stars 43 forks source link

How to get email when i line login #46

Closed TAMILSELVAN943 closed 2 years ago

TAMILSELVAN943 commented 3 years ago

Is it a security issue?

If you believe you have discovered a vulnerability or have an issue related to security, please DO NOT open a public issue. Instead, send us a mail to dl_oss_dev@linecorp.com.

What did you do?

Please describe what you did before you encounter the issue.

What did you expect?

Please describe what you did expect to happen.

What happened actually?

Please describe what happened actually.

Your environment?

Some information of the environment in which the issue happened. Package version, Xcode version, iOS version, etc.

Sample project

It would be appreciated if you can provide a link to or update a sample project that we can download and reproduce the issue.

Selecao commented 2 years ago

If using this SDK we can get lineUserId:

final loginResult = await LineSDK.instance.login(scopes: ["profile", "openid", "email"]);
final lineUserId = loginResult.userProfile?.userId;

How we can get lineEmail?

onevcat commented 2 years ago

The Email is contained in the idToken in the "email" field, if the user set it in LINE. You can use this code to get it:

final result = await LineSDK.instance.login(scopes: ["profile", "openid", "email"]);
final idToken = result.accessToken.idToken;
final userEmail = (idToken != null) ? idToken['email'] : null;

Please be careful since the user can choose to not share his/her email with you, or he/she might even not yet set an email address bound to the LINE account, this value could be null and you have to consider a way to handle it.

It is now a bit hard to use and not obvious. We will soon add a getter for the email address and release a new version for it.

onevcat commented 2 years ago

Per #58, once it gets merged, you can use the email to get it:

final result = await LineSDK.instance.login(scopes: ["profile", "openid", "email"]);
final userEmail = result.accessToken.email;
Selecao commented 2 years ago

Per #58, once it gets merged, you can use the email to get it:

final result = await LineSDK.instance.login(scopes: ["profile", "openid", "email"]);
final userEmail = result.accessToken.email;

@onevcat there is no field .email after merging (already merged right?) but result.accessToken.idToken?['email']has what i need, thank you!

onevcat commented 2 years ago

Sorry for the confusion, it is not tagged/released yet. I meant you can use it from the next version of flutter_line_sdk. I will prepare a tag for it today but it should be totally fine to just use your current way. They are the same.

onevcat commented 2 years ago

Version 2.2.0 was just released with this change. Find more in the pub.dev or repo release page.