question

oaicc06 avatar image
oaicc06 asked

html5 Google oAuth2 Access blocked: Authorization Error

Hi, I'm trying to implement google authentication with playfab SDK for my WebGL, I followed the tutorial for HTML5 games to implement it, I used the code provived

 <!DOCTYPE html>
 <html>
   <head>
     <script src="https://accounts.google.com/gsi/client" onload="initClient()" async defer></script>
     <script src="https://download.playfab.com/PlayFabClientApi.js"></script>
   </head>
   <body>
     <script>
       var client;
       function initClient() {
           console.log("Initializing Google token client on page load");
           client = google.accounts.oauth2.initTokenClient({
               client_id: "YOUR_CLIENT_ID", // TODO: PUT YOUR GOOGLE CLIENT_ID HERE!
               callback: "onTokenResponse",
               scope: "https://www.googleapis.com/auth/userinfo.profile",
               callback: (tokenResponse) => {
                   access_token = tokenResponse.access_token;
                   onSignIn();
               }
           });
       }
    
       function getToken() {
         client.requestAccessToken();
       }
    
       // Invoked after user has signed in with Google
       function onSignIn() {
           // Execute LoginWithGoogleAccount API call using the Google access token. Please replace TitleId.
           logLine("Attempting PlayFab Sign-in using LoginWithGoogleAccount");
           PlayFabClientSDK.LoginWithGoogleAccount({
               AccessToken: access_token, // This access token is generated after a user has signed into Google
               CreateAccount: true,
               TitleId: "YOUR_PLAYFAB_TITLE", // TODO: PUT YOUR TITLE ID HERE!
           }, onPlayFabResponse);
       }
    
       // Handles response from PlayFab
       function onPlayFabResponse(response, error) {
           if (response)
               logLine("Response: " + JSON.stringify(response));
           if (error)
               logLine("Error: " + JSON.stringify(error));
       }
    
       function logLine(message) {
           var textnode = document.createTextNode(message);
           document.body.appendChild(textnode);
           var br = document.createElement("br");
           document.body.appendChild(br);
       }
     </script>
     <h1>Google Access Token Auth Example</h1>
     <!-- Clicking this button will prompt the user to sign into Google. Once they have signed into Google, LoginWithGoogleAccount is automatically called. -->
     <button onclick="getToken();">Sign into Google</button><br><br>
   </body>
 </html>

I changed the cliend ID with my own and same for PlayFab title ID, but when I try to sign in I receive the Errore 400: invalid_request Access blocked: Authorization Error Anyone can help me please to solve the problem

unity3dAuthentication
10 |1200

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

1 Answer

·
Xiao Zha avatar image
Xiao Zha answered

I follow the Running an HTTP server for testing - PlayFab | Microsoft Learn to run a local web server for testing(the host file doesn’t need to change), then follow the Setting up PlayFab authentication using Google and HTML5 - PlayFab | Microsoft Learn to set up the Google API project, the URLs I set are like below(Google Web Application needs valid URL, “playfab.example” doesn’t meet the requirement), then enter the “localhost” in the browser address bar to run the JavaScript, everything works fine. And as the documentation Setting up PlayFab authentication using Google and HTML5 - PlayFab | Microsoft Learn says, a server with a valid domain is required for testing, have you run the local web server? 6215-3.png


3.png (16.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.

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.