mulesoft-labs / js-client-oauth2

A JavaScript implementation of an oauth2 client, for inclusion in the JavaScript client generator for APIs described with RAML.
Other
538 stars 146 forks source link

token.refresh failing finally() not defined #170

Open sdetweil opened 3 years ago

sdetweil commented 3 years ago

I am trying to upgrade the dependencies on a node/browser app to current levels to get rig of a grpc problem.

one, google-assistant, uses a module that uses popsicle

└─┬ client-oauth2@4.3.3
  └─┬ popsicle@12.1.0
    └── popsicle-transport-http@1.1.2 

i call a client-oauth method to refresh my oauth2 token and now get an error that finally is not defined..

if i change the finally()'s to .then() (workaround) i now get a : socket.ref is not a function both from popsicle-transport-http

running node 14.15.3 in electron 11.3.0

i read in my old refresh token and then update it

                GA_Auth = new ClientOAuth2({
                    clientId: keyinfo.installed.client_id,
                    clientSecret: keyinfo.installed.client_secret,
                    accessTokenUri: keyinfo.installed.token_uri,
                    authorizationUri: keyinfo.installed.auth_uri,
                    redirectUri: "http://localhost:5000/assistant_auth", 
                    scopes: ["https://www.googleapis.com/auth/assistant-sdk-prototype"],
                });
...
                    let tokeninfo = JSON.parse(
                        fs.readFileSync(_gp.resolve(_ourpath, "token.json"))
                    );
                    var token = GA_Auth.createToken(
                        tokeninfo.access_token,
                        tokeninfo.refresh_token ? tokeninfo.refresh_token : null
                    );

                    // Set the token TTL.
                    token.expiresIn(60 * 24 * 60); //seconds
                    console.log("assistant refreshing access token on startup");
                    // Refresh the users credentials and save the new access token and info.
                    token
                        .refresh()
                        .then((user) => {
                            console.log("assistant saving tokens on startup");
                            saveTokens(user);
                            AssistantInit(gaconfig, geoposition);
                        })
                        .catch((error) => {
                            console.log("error on startup refresh ="+error);   //< code goes here on finally/socket.ref
                        });
sdetweil commented 3 years ago

also socket once() not found

 line 576               // Existing socket may already have negotiated ALPN protocol.
                if (socket.alpnProtocol != null)
                    return onConnect();
                socket.once("secureConnect", onConnect);
                socket.once("error", onError);
                socket.once("close", onClose);