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

Enquiry for LINE API implementation for Unity WebGL #38

Closed xuancelestial closed 2 years ago

xuancelestial commented 3 years ago

First of all, sorry for creating issue here, as I can't think of anywhere else to get this answered. As I read through issue #11, there is no plan of putting up WebGL support from this sdk.

My question is, if I wanted to implement Line API for Unity WebGL, which approach the would the devs suggest us to implement Line API in our Unity WebGL Game if there is no direct sdk for it.

Is it a security issue?

no

What did you do?

Trying to implement LINE API login for Unity WebGL Games

What did you expect?

Approaches or direction should we go if we wanted to implement it

What happened actually?

-

Your environment?

Unity 2020.3.12f1

Sample project

-

onevcat commented 3 years ago

Hi,

Thanks for opening this issue. As you mentioned, there is no plan for Unity WebGL currently. LINE SDK provides a native integration of using LINE Login in iOS or Android app.

which approach the would the devs suggest us to implement Line API in our Unity WebGL Game if there is no direct sdk for it.

For WebGL, considering the fact that the game (app) is running in a browser, I would suggest you check the plain LINE Login (https://developers.line.biz/en/docs/line-login/integrate-line-login/) guide to get started.

As I know now, LINE is not providing a specified web app library (say a JavaScript library or so), so you might need to implement it by yourself. However, the good news is LINE Login is fully compatible with OAuth2 now, you can use any existing OAuth2 client library and give it the correct information (request URL and token exchange URL, for example), to make the task much easier! (I am not an expert on this, but after some search I found this https://github.com/mulesoft-labs/js-client-oauth2 and it looks good to me.)

xuancelestial commented 3 years ago

Hi,

Thank you for your responses, it helps a lot, and I think I facing some final issue before I able to retrieve my IDToken to have user profile.

So I was getting this error when trying to get token from the 'https://api.line.me/oauth2/v2.1/token' API

{ "error": "invalid_request", "error_description": "the redirect_uri is malformed" }

but the 'redirect_uri' I included in the body was exactly same as the one I set up in the developer console.

Any clue for this?


Another issue is just double confirming, for unity line SDK, the user id is under:

LoginResult.UserProfile.UserId

meanwhile, if I use login endpoint API to retrieve user profile with IDToken, from the response, is the field 'sub' equivalent to the 'LoginResult.UserProfile.UserId'?


After I successfully implement LINE API for Unity WebGL, I will add on more detail on this issue on how I did it.

Thanks!

onevcat commented 3 years ago

but the 'redirect_uri' I included in the body was exactly same as the one I set up in the developer console.

I am just guessing it, but if I remember correctly, the redirect_uri is passed as an argument of the initial login request URL.

So maybe you need to encode it (and even twice encoding if it is a "parameter of another parameter"!) before sending to LINE and opening the login page. So LINE server would get the correct one.

from the response, is the field 'sub' equivalent to the 'LoginResult.UserProfile.UserId'?

Yes, it is!

A small tip: you can check the doc in the source of Swift SDK here, which was written pretty well.