最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论