line / line-sdk-unity

Provides a modern way of implementing LINE APIs in Unity games, for iOS and Android.
https://developers.line.biz/
Apache License 2.0
117 stars 24 forks source link

Get user's email from IDToken? #31

Closed xuancelestial closed 3 years ago

xuancelestial commented 3 years ago

Is there anyway I could get user's email from this SDK?

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. LINE SDK version, Unity version, Android 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.

onevcat commented 3 years ago

Hi,

Yes. You can get the IdTokenRaw from the AccessToken in the login result. However, this is a raw ID token string (JWT) without parsed, so you need to convert it to a JSON and get its email field manually. This is not convenient for now and we will add to our backlog! Before we can have a built-in way to parse it, you can try to find some other library or parse it yourself (Basically it is a base64 URL encoded string, and you can find a few existing libraries for this purpose.)

The detailed steps:

var scopes = new string[] {"profile", "openid", "email"};
LineSDK.Instance.Login(scopes, result => {
  //...
}
var raw = result.AccessToken.IdTokenRaw; // Remember to check null.
var jwt = SomeJWTLib.convertToDictionary(raw);
var email = jwt["email"]; // Remember to check null. Users can choose not allow you access the email.
xuancelestial commented 3 years ago

Thank you! will try it out