baumblatt / capacitor-firebase-auth

Capacitor Firebase Authentication Plugin
MIT License
261 stars 129 forks source link

Add method for getting current Access Token (Facebook) #133

Open zdenekhatak opened 3 years ago

zdenekhatak commented 3 years ago

Hello,

since Facebook API returns access_token only after initial login phase, it would be really handy if the plugin offered this method as well (the currentAccessToken).

https://developers.facebook.com/docs/facebook-login/access-tokens#usertokens - here you can see the method

One could then use the Access Token to for example get user's avatar which is now only available with valid Access Token.

baumblatt commented 3 years ago

Hello Zdeněk,

Can you please take a look at alternative facade? The docs are here.

This is how we solve the same requirements for Twitter.

Please let me know if this is not solve your case, and if not, we can change the label to enhancement.

Best regards.

zdenekhatak commented 3 years ago

Hi @baumblatt ,

thank you for the quick reply.

Well I use the alternative facade already when the user clicks the Login button in my application. Since I am using the alternative version - it also returns the native layer payload (Facebook access_token in this case) and everything is great.

The problem is when is user is (in terms of firebase) already logged in – user closes the application for example and then launches it again - I do not want to force the user to click the button again so I use firebase.auth().onAuthStateChanged() to find out that user is already logged in but logically there is no Facebook AccessToken in the User object.

The "workaround" is to use FB.getLoginStatus on web. But this does not work in native platforms - that is what FB API getCurrentAccessToken is for.

Did I explain the problem correctly?

Thank you in advance

baumblatt commented 3 years ago

Hello Zdeněk,

Ok, I got this, and I will put this on the roadmap.

I will take a look this weekend on this and if is easy as appears, you will hear from me soon.

Best regards.

zdenekhatak commented 3 years ago

Thank you,

yes, it should be easy in fact. And also very useful for everybody since the Graph API change that happened like a month ago I can't see a proper way of getting user avatar from Facebook other that than using accessToken.

Looking forward to it, cheers!

zdenekhatak commented 3 years ago

@baumblatt

Hello, may I ask how things are going? Did you have time to look at it?

Thank you

zdenekhatak commented 3 years ago

I tried to implement this feature in my fork.

https://github.com/zdenekhatak/capacitor-firebase-auth/pull/1/files

The implementation is probably not of the best quality since I have zero experience with Swift & Java.