question

sinitreo avatar image
sinitreo asked

Google OAuth2 Endpoint with Server Auth Code

I have set this URL in Google API console as valid redirect: https://oauth.playfab.com/oauth2/google

The url originates from Marco's blog post. The problem is, I can easily log in using old Access Token technique, but if I use Auth Code approach and let PlayFab server run the oauth, the only thing I get is this:

Which, according to message, has something to do with where PlayFab redirects the result. I've tried probing the mentioned URL with postman, using both get and post, but got 404.

download.png (39.4 KiB)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

Well first, all our endpoints are SSL secured, so if you were trying to hit LoginWithGoogleAccount using http, that could have been the problem.

Now, we have a number of titles using server auth codes to sign into the player Google Account, so we do know it works. So the thing to do here is to work out where the process is going wrong. Can you please provide the specifics on how you're obtaining the server auth code, and how you're calling LoginWithGoogleAccount?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sinitreo avatar image
sinitreo answered

Ok, so I'm not trying to hit anything myself. The google authentication service is what redirects the authentication request to the server, so server can authenticate the user. I'm positive it determines the protocol based on the Redirect URL I specify as a callback (https in this case).Please, refer to the Official Guide.


The diagram in the beginning of the article illustrates the flow:https://i.gyazo.com/ef9d339628b66191e5b0bdcba275bd55.png

The code I use is the following:

<!DOCTYPE html>
<html>
<head>

	<meta name="google-signin-client_id" content="==== CLIENT ID ====">
	<script src="https://apis.google.com/js/client:platform.js?onload=start" async defer>
	</script>
	<script src="https://download.playfab.com/PlayFabClientApi.js"></script>
</head>
<body>
    <p>Google Access Token Auth Example</p>

    <button onclick="signin()">Sign In</div>


    <script>
	    
		function start() {
			gapi.load('auth2', function() {
				auth2 = gapi.auth2.init();
			});
		}
		
		function signin() {
			auth2.grantOfflineAccess().then(onSignIn);
		}
		
		// Invoked when user has signed in with Google
		function onSignIn(args) {
					
			console.log(args);
					

			PlayFabClientSDK.LoginWithGoogleAccount({
                ServerAuthCode: args.code,
				CreateAccount : true,			
                TitleId: "====TITLE ID====",
            }, onPlayFabResponse);
	
		}
     

        function onPlayFabResponse(response) {
            
			if(!response || response.code != 200) {
                logLine("Problem authenticating via PlayFab: "+response.errorMessage);
            } else {
                logLine("Authenticated via PlayFab! Session Ticket "+response.data.SessionTicket);
            }
			
        }


        function logLine(message) {
            var textnode = document.createTextNode(message);
            document.body.appendChild(textnode);
            var br = document.createElement("br");
            document.body.appendChild(br);
        }


    </script>


</body>
    
</html>

Debugging shows that the auth code I send looks pretty valid, and the issue is PROBABLY badly configured redirect url (I use https://oauth.playfab.com/oauth2/google).


10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.