Your LoginWithGooglePlusSDK and your presented sample are deprecated

we can’t use LoginWithGooglePlusSDK and GoogleApiClient classes anymore. both are deprecated. your presented sample at your site for login by other social services needs to be updated. is there other solution?

Hello,

Please see the documentation for the OAuth2 login:
https://backendless.com/docs/android/users_oauth2.html

Regards,
Mark

Thank you Mark for your quick reply. I have seen your tutorial documentation for the OAuth2 login and was able to go through with it. But, in there some steps are deprecated too or slightly changed. For example, in “Login with Google” part, step 5, there is no CONFIGURE CONSENT SCREEN (it transferred) or in step 14, there is no link available such as “Firebase” anymore, or in step 20, I was not able to find and download google-services.json file.

However, I adopted myself to all slight changes and was able to implement the the Authorization with URL API successfully. But, for OAuth2 Login API, I still have problem with how to deal with “accessToken” in (Backendless.UserService.loginWithOAuth2(
String providerCode,
String accessToken,…)

Sorry Mark, I am not an expert in web programming. We utilize Backendless for relief that you have provided us in comparison with other platforms and so far, we are satisfied with your brilliant facilities. Therefore, we would be so grateful if you update your example or present a straightforward android java code as before (especially for login with Google account).

Best Regards

Hello, @Nestech_Co1, and thanks for your comment.

I created an internal ticket(BKNDLSS-26295). We are working on updating the documentation.
Best regards, Nikita.

The accessToken is obtained from a call you use from the Google’s SDK. Here’s Google’s API page describing the process of using their SDK. The page references the getIdToken method that returns the access token you use in our API:

Thank you Mark. I managed to get the IdToken by the tutorial that you have enclosed.
Ironically, even Google in this tutorial, uses the method “startActivityForResult” which is deprecated by Google itself.
I’ll let you know if this token will work successfully with your presented APIs.
Regards

well, here is the result Mark:
in spite of successful login with your URL API (Backendless.UserService.getAuthorizationUrlLink(…)), and successful creating the user table, I am still not able to connect with your OAuth2 Login API.
I can connect and login with google APIs and extract the idToken by getIdToken() method. But, when using this Id in Backendless.UserService.loginWithOAuth2(…), here is the fault error message:
GUID: E62F8366-709C-6CBF-FF5A-D0DC21021200
Error during obtaining user data.
Response from OAuth2 provider server: Unauthorized
{
“error”: {
“code”: 401,
“message”: "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
“status”: “UNAUTHENTICATED”
}
}

here is a part of token: IdToken is: eyJhbGciOiJSUzI1NiIsImtpZCI6Ijc0MjE3YjhkYWRiYjM2NTc4MzU4MGY5ZTkyNDg3ZDcwMWNkMzhmZTYiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL…

Hello,

There is something that is not clear to me. You mentioned you’re using Google SDKs to get the auth token, however, you also mentioned you’re using the getAuthorizationLink method from our SDK. Here’s a snippet from our documentation:

Notice that it says that the getAuthorizationURL should be used when you’re not using a provider SDK. This tells me that the authorization flow in your implementation is incorrect.

Additionally, have you configured the Authorized redirect URL on the google side? Please attach screenshots demonstrating the configuration.

Regards,
Mark

Dear Mark, I wrote Two test apps. one, for testing your " Get Authorization URL API" part and here is the snippet:

Button btnLogin, btnLogout;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    btnLogin = findViewById(R.id.btnLogin);
    btnLogout = findViewById(R.id.btnLogout);

    btnLogin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {


            Backendless.UserService.getAuthorizationUrlLink("googleplus", null, null, new AsyncCallback<String>() {
                @Override
                public void handleResponse(String response) {

                    Log.d(TAG, "Success: the URL is: " + response);

                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(response));
                    startActivity(intent);

                }

                @Override
                public void handleFault(BackendlessFault fault) {

                    Log.d(TAG, "Fault: " + fault.getMessage());
                    Toast.makeText(MainActivity.this, fault.getMessage(), Toast.LENGTH_SHORT).show();

                }
            });


        }
    });

it work fine, by which, I concluded that my google cloud and firebase setting, according to your tutorial is correct!

the second app I wrote, is for testing your " OAuth2 Login API" with the same Backendless subdomain, Application I, Android API key and other setting…
here is the snippet:

private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {


    try {

        GoogleSignInAccount account = completedTask.getResult(ApiException.class);

        // Signed in successfully, show authenticated UI.
        Log.d(TAG, "handleSignInResult: Signed in successfully");

        GoogleSignInAccount acct = GoogleSignIn.getLastSignedInAccount(MainActivity.this);

        if (acct != null) {

            Log.d(TAG, "handleSignInResult: IdToken is:" + acct.getIdToken());
           
        }

        assert acct != null;
        Backendless.UserService.loginWithOAuth2("googleplus", account.getIdToken(), null, new AsyncCallback<BackendlessUser>() {
            @Override
            public void handleResponse(BackendlessUser response) {

                Log.d(TAG, "Backendless login Successfully");

            }

            @Override
            public void handleFault(BackendlessFault fault) {

                Log.d(TAG, "Backendless login NOT Successfully because: " + fault.getMessage());

            }
        }, false);



    } catch (ApiException e) {
        // The ApiException status code indicates the detailed failure reason.
        // Please refer to the GoogleSignInStatusCodes class reference for more information.
        Log.w(TAG, "signInResult:failed code=" + e.getStatusCode());
        Log.d(TAG, "handleSignInResult: Signed in is NOT successfully");
        
    }
}

getting the tokenId is OK but the result is an error according to my previous post

and this is my credential page

and yes. I configured the Authorized redirect URL according to your tutorial…

Hello @Nestech_Co2

In the second application, did you add the backendless sub-domain to the authorized requests or did you only add the url https://api.backendless.com/APP-ID/API-KEY/users/social/googleplus/authorize

Regards,
Inna

Hi Inna, I did whatever requested in your tutorial in this link:
https://backendless.com/docs/android/users_oauth2.html
including step 25 about adding backendless sub-domain

is there anything else I must do?

Dear mark,
Apparently, the accessToken achieved by this tutorial is not suitable or enough for your presented method (Backendless.UserService.loginWithOAuth2(…))

the error is still going on…

GUID: 985C2B58-F4B3-D608-FFB8-12B978C84900
Error during obtaining user data.
Response from OAuth2 provider server: Unauthorized
{
“error”: {
“code”: 401,
“message”: "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
“status”: “UNAUTHENTICATED”
}
}

OAuth2 site, expressed that for authorization, there has to be TWO parameters available, which are required! (access_token & token type ) as follows:

"The response with an access token should contain the following properties:

access_token (required) The access token string as issued by the authorization server.
token_type (required) The type of token this is, typically just the string “bearer”. "

the presented Backendless method Backendless.UserService.loginWithOAuth2(…) needs just access_token. where is the required token_type ?
could this have made the current problem?

Hi @Nestech_Co3 !

This method expects that you will pass access token, not the ID token.
You should extract auth code from GoogleSignInAccount using getServerAuthCode() method ( GoogleSignInAccount  |  Google Play services  |  Google Developers ) and then echange it using this method AuthorizationCodeFlow (google-oauth-java-client 1.32.1)

More information about auth flow with Google you can get by this link Using OAuth 2.0 with the Google API Client Library for Java

Regards, Andriy