java - Only receive ServerAuthToken with Credential Manager? - Stack Overflow

is it possible to only receive the serverAuthCode with the Credential Manager [1] in an Android App wri

is it possible to only receive the serverAuthCode with the Credential Manager [1] in an Android App written in Java ?

Our backend expects only this information so it may make the request to Google to receive info about the user thats trying to login.

My current implementation is:

CredentialManager manager = CredentialManager.create(getApplicationContext());
            GetGoogleIdOption googleIdOption = new GetGoogleIdOption.Builder()
                    .setFilterByAuthorizedAccounts(true) // only existing google accounts, no "create new google account" screen
                    .setAutoSelectEnabled(true)
                    .setServerClientId("web_client_id")
                    .build();
            GetCredentialRequest request = new GetCredentialRequest.Builder()
                    .addCredentialOption(googleIdOption)
                    .build();

CredentialManagerCallback<GetCredentialResponse, GetCredentialException> credentialManagerCallback = new CredentialManagerCallback<GetCredentialResponse, GetCredentialException>() {
                @Override
                public void onResult(GetCredentialResponse result) {
                    // result here has all the data of the user, like email, name

                    // wanted: only serverAuthToken to send over to the backend which is then makeing the google api request
                }

                @Override
                public void onError(@NonNull GetCredentialException error) {
                    // handle error
                }
            };
            manager.getCredentialAsync(
                    _activity_instance,
                    request,
                    null,
                    Executors.newSingleThreadExecutor(),
                    credentialManagerCallback
            );

[1]

is it possible to only receive the serverAuthCode with the Credential Manager [1] in an Android App written in Java ?

Our backend expects only this information so it may make the request to Google to receive info about the user thats trying to login.

My current implementation is:

CredentialManager manager = CredentialManager.create(getApplicationContext());
            GetGoogleIdOption googleIdOption = new GetGoogleIdOption.Builder()
                    .setFilterByAuthorizedAccounts(true) // only existing google accounts, no "create new google account" screen
                    .setAutoSelectEnabled(true)
                    .setServerClientId("web_client_id")
                    .build();
            GetCredentialRequest request = new GetCredentialRequest.Builder()
                    .addCredentialOption(googleIdOption)
                    .build();

CredentialManagerCallback<GetCredentialResponse, GetCredentialException> credentialManagerCallback = new CredentialManagerCallback<GetCredentialResponse, GetCredentialException>() {
                @Override
                public void onResult(GetCredentialResponse result) {
                    // result here has all the data of the user, like email, name

                    // wanted: only serverAuthToken to send over to the backend which is then makeing the google api request
                }

                @Override
                public void onError(@NonNull GetCredentialException error) {
                    // handle error
                }
            };
            manager.getCredentialAsync(
                    _activity_instance,
                    request,
                    null,
                    Executors.newSingleThreadExecutor(),
                    credentialManagerCallback
            );

[1] https://developer.android/identity/sign-in/credential-manager

Share Improve this question asked Nov 20, 2024 at 16:45 pasklpaskl 6115 silver badges25 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

No, that is not possible. You can only receive an auth code if you use the Authorization APIs; Credential Manager is aimed at authentication and not authorization.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742343717a4426125.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信