Google Signin for Unity (Windows standalone build) - invalidGoogleToken when used with Playfab - unity3d

Hopefully someone can point me in the right direction here, I'm attempting to log into Playfab using a google auth code retrieved from an async call in Unity, the flow is as follows:
Click my login to google button in Unity.
Unity begins to listen for the response and opens a google login browser session.
User clicks email/signs into email they want.
This response is returned to Unity with an auth code.
I have then attempted to use the returned google auth code with playfabs LoginWithGoogleAccount method":
PlayFabClientAPI.LoginWithGoogleAccount(new LoginWithGoogleAccountRequest()
{
TitleId = PlayFabSettings.TitleId,
ServerAuthCode = returnedWindowsGoogleAuthCode,
CreateAccount = true,
}, OnPlayfabGooglePlayAuthComplete, OnPlayfabGooglePlayAuthFailed);
This then fails with a returned response from playfab with "invalidGoogleToken".
From what I've read from what I've come across on google is that this token is possibly in a "used" state by the time I am calling LoginWithGoogleAccount and I possibly need a refreshed token? but I am not too familiar with the Google API so I could be completely off the mark there? But if this is the case what should I do here? How do I re-request a valid token without going back to the browser to do the same thing again?
To give you an idea of pretty much the exact code I'm looking at but I've altered slightly to get it to work in Unity I am following the Google Sample OAuthDesktopApp code:
OAuthDesktopApp Sample Code
I am calling the method "button_Click", this runs and makes the request, Unity then begins listening for the google response at line 72 and the auth code is then output to logs at line 129.
This auth code output at line 129 is what I have then been passing back in to LoginWithGoogleAccount which then results in the failed "invalidGoogleToken", this does also then run a request for user information which does correctly return the name/email of the user you signed in with etc.
Just to add to my previous comments, if I remove the call to performCodeExchange line 132 (I read somewhere that at that point I am swapping the auth code for a token and thus the auth code will no longer work? I'm guessing here) and then if I call PlayFabClientAPI.LoginWithGoogleAccount with the auth code I am presented with:
PlayFabError error:
error.GetHashCode(): 2051826304
error.Error: InvalidGoogleToken
error.ErrorMessage: invalid_grant details: Missing code verifier.
error.ErrorDetails: null
Hopefully this may help someone guide me.

First thanks to those that replied to this, So I've managed to solve this after a comment from a Playfab mod, There appears to be no official way from Google to login using a standlone Unity build nor an official way to then login to Playfab using the same build method.
The solution I've used uses a modified Unity version of one of the Google samples from OAuth 2.0 for Mobile & Desktop Apps .
This will allow you to get the oauth code within Unity then you can pass this oauth code to Playfab for login, BUT Playfab has since deprecated the way to do this (which is silly if its the only solution) so you need to modifiy Playfabs SDK to include the accesstoken then you can use this to finally login.

Related

Facebook login with Azure Service and get user info error

I've implemented facebook login following this blog https://ahoycoders.com/2015/07/09/xamarin-forms-social-authentication-with-azure-mobile-services-part-3/
That blog is based on old Azure portal.
But, I'm using new Azure portal.
1. In the new Azure portal I used Easy APIs option for creating custom API as mentioned in the blog.
2. I copied the scrip mentioned in the blog for my custom API and I'm using only Facebook.
I authenticated via Facebook and then called the following,
return await mobileService.InvokeApiAsync("getextrauserinfo", HttpMethod.Get, null);
Unfortunately, I'm getting the following error,
"Cannot read property 'getIdentities' of undefined"
I don't know what's wrong, please help me in fixing this.
currentUser is no longer obtained from request as .user, it is now request.azureMobile.user
They changed the method calls. It is also no longer getIdentities.
Its getIdentity.
A few other calls slightly changed as well.
I suggest anyone wanting to use that guide use console.log to see what each object actually returns and then switch out the old code for the right call.
Logic in that example should still be fine, just slightly different calls/names.

Facebook auth serverside calls back 2 times with the same code

On our server-side authentication with Facebook we get a random and weird issue. Facebook calls the call back URL two times with the same code. This is only happening for some users and not on every login.
This is the flow we have implemented on our side: https://developers.facebook.com/…/manually-build-a-login-fl… . We have been using it since the beginning of 2013 and we haven't noticed any issues so far.
And this is the error we get when we are exchanging the code for an access token the second time.
{"error":{"message":"This authorization code has been used.","type":"OAuthException","code":100,"fbtrace_id":"traceID"}}
We tried to log this issue as a bug on https://developers.facebook.com/bugs but unfortunately it doesn't work.
It keeps showing unexpected error. Not to mention that i was unable to find the correct bug category.
Any idea on how we can fix this?
Thanks!
Could it be that users are clicking twice to process auth service? Try disabling the button before calling Facebook auth service
What language are you using?
I just had this problem in Ruby using Devise for Rails. I had created an omniauth.rb initializer file, and added a config line item in the devise.rb initializer file.
If you did this too, you can remove the omniauth.rb initializer file and you should be good to go!

I can't get my generated App Access Token to work

I'm trying to use my generated App Access Token with requests to the Graph API, but for some unknown reason it simply will not work. I always get the dreaded Invalid OAuth access token signature error.
Now, let me clarify: I'm pretty sure I know what I'm doing. I did get it to work with a different FB app. I used the /oauth/access_token call to generate the App Access Token, and I can use that Token successfully in further graph calls for that FB app.
But when I try it for my new FB application, it fails. This is the Rails snippet:
app_access_token = URI.escape(ENV["FACEBOOK_APP_ACCESS_TOKEN"])
url = "https://graph.facebook.com/debug_token?input_token=#{user_access_token}&access_token=#{app_access_token}"
response = HTTParty.get(url)
I've also tried not-encoding the token; as expected, it doesn't work (and shouldn't).
I've double- and triple-checked my App ID and App Secret, and re-ran the generation (via curl), and I think it's all correct and copy/pasted without error. The only possibly-notable difference between the generated token of my old app and that of my new one is that the latter has a hyphen in it. Is that relevant?
I am currently working around this by using <App ID>|<App Secret> in place of the generated token, but I'd really like to get back to doing it the right way.
Argh! It turns out that I had a few extra characters that somehow got attached to the end of my generated token!
I don't know how those got there, but that was the problem. Just dumb old human error.
EDIT: Oh my god, every Facebook developer should know this page:
https://developers.facebook.com/tools/accesstoken/
Why isn't that linked from the docs about the access token? It would have saved me so much time and probably prevented my mistake!

Fitbit OAuth 2.0 and Unity Project (RestSharp as well)

I've been trying to get OAuth 2.0 to work correctly. I have managed to make the url that that will do the "deny/allow" for my app by opening a webpage with just
Application.OpenUrl(uri.ToString());
The problem is that I have no idea how to get the redirect and the auth token from the page if the user hits allow. When you hit allow, right now nothing happens it just sits on the page. Checking Networking in chrome debug does have the redirect and token there but it never actually sends it..
I was recommended to use RestSharp but I again have no idea how to use it with Unity as there are lot of resources for Android/iOS PC etc. but I can't get any of them to work for this Unity project...
var client = new RestClient("https://www.fitbit.com/oauth2/authorize?response_type=code&client_id=*clientID*&redirect_uri=http%3A%2F%2FfitRPGcallback&scope=activity%20profile%20sleep%20social");
Debug.Log("client made");
var request = new RestRequest(Method.POST);
request.Resource = ("profile%20sleep%20social");
client.ExecuteAsync(request, response => { Debug.Log("response is : " + response.Content);});
Application.OpenURL(client.BaseUrl.ToString());
In the URL I do have the correct clientID in there as well just not sure what I can and can't show for security reasons etc.
Biggest problem is just having no idea how to get the return value from the webpage after the user hits allow/deny...
Any insights would be super super appreciated cause I just want to start making the actual game but there's not as much point if I can't get this data...
So, I'm posting on a few other applicable questions as well since I have finally figured out my answer.
Unfortunately I'm not using REST so that part is still up in the air BUT I did get it to work with just Fitbit, Unity and a Webview plugin (you will need a webview OR a way to get the initial code back from your first OAuth2 call)
You can find steps here.
http://technicalartistry.blogspot.nl/2015/07/oauth2-unity-and-month-of-cursing.html
EDIT:
So I had to change how I did it because Fitbit changed their ToS where we are no longer allowed to use Webview based Authenticators (which is what I was using in the above blogpost.)
Give this next post a look for how to make an Android Plugin that will grab the Accesstoken from Fitbit's OAuth. This is a FREE way to do it since you make it yourself and it's ezmode :)
http://technicalartistry.blogspot.ca/2016/01/fitbit-unity-oauth-2-and-native.html

facebook chat on the iphone using xmppframework

Well i started of by following all the instructions here:
http://code.google.com/p/xmppframework/wiki/FacebookChatHowTo
I used the recommended fork of the facebook api and tried the latest from:
https://github.com/facebook/facebook-ios-sdk/
My problem starts with the following error:
< failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl">< not-authorized/></failure>
The error is a reply from facebook to xmppframework s response to a authentication challenge. The response that is made by the iphone is base64 encoded msg when i decode it i find 2 of the values are null:
api_key=(null)
and the
session_key=(null)
This is obviously the reason facebook is returning that error. But the problem i have is i cant seem to find any where to set these values in the framework. Besides i think the session_key should be pulled in from facebook anyway.
I guess what i want to know is a couple of things.
Has any one got the xmppframework working with facebook on a iDevice?
If you have got it working did you have to stray from the path of the instructions on http://code.google.com/p/xmppframework/wiki/FacebookChatHowTo ?
do you know of any other method to get facebook chat working on the iphone?
Any suggestions or help for my current dilemma would be appreciated. Happy to share my code if you want.
cheers
I wrote the Facebook integration for XMPPFramework. The api_key and session_key, come from a call to auth.PromoteSession. Facebook is trying to deprecate that call, so to enable it, you must follow step 7, in the HowTo:
Under Migrations, change Disable Deprecated Auth Methods from Enabled to Disabled and Save Changes.