Skip to content

get Firebase Access token (oAuth2) #882

Open
@waleedmakarem

Description

@waleedmakarem

Can i use the library to get Firebase Access token (oAuth2) . I have firebase ServiceAccount json data. below is my running java code that works using

private static final String firebaseMessagingScope = "https://www.googleapis.com/auth/firebase.messaging";

public void getAccessTokenfromFile(Context mcontext, AccessTokenCallback callback) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                InputStream stream = mcontext.getAssets().open("serviceaccount.json");
                GoogleCredentials googleCredentials = GoogleCredentials.fromStream(stream).createScoped(firebaseMessagingScope);
                googleCredentials.refresh();
                final String token = googleCredentials.getAccessToken().getTokenValue();
                // Handle the token here
                callback.onAccessTokenReceived();
            } catch (Exception e) {
                callback.onAccessTokenError(e.getMessage());
            }
        }
    }).start();

}

my service account file as below data headers:

<title></title> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px '.AppleSystemUIFont'} table.t1 {border-collapse: collapse} td.td1 {border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #9a9a9a #9a9a9a #9a9a9a #9a9a9a; padding: 1.0px 5.0px 1.0px 5.0px} </style>

type

project_id
private_key_id
private_key
client_email
client_id
auth_uri
token_uri
auth_provider_x509_cert_url
client_x509_cert_url
universe_domain

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugtriageIssues that need to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions