npm angular-oauth2-oidc Token has Expired issue - angular9

In the middle of my application I am getting "Token has expired" issue, please help me how to subscribe token expire method and logout the application or else increase the expiry time. Please find below error screenshot for your reference. Thank you in advance.

You need to refresh your token before it expires. Check out the documentation here (if you're using Code Flow) or here (if you're using implicit flow)
In your app.component.ts file you could also try to subscribe to the "token_expires" event after configuring your oAuthService (after calling this.oauthService.loadDiscoveryDocumentAndTryLogin();)
this
.oauthService
.events
.filter(e => e.type == 'token_expires')
.subscribe(e => {
this.oauthService.silentRefresh();
});

Related

Permission denied when calling firebase cloud function

Created a new Firebase project.
Created a test function, as described here.
Trying to call this function, I get PERMISSION DENIED, both when trying to call it from my flutter app, or directly (403 Forbidden).
Suggestions from this post didn't help...
This is my second flutter-firebase project. The first one runs just fine, can't see any differences between them that might explain this behaviour. Appreciate any help with this issue :)
my code:
const functions = require('firebase-functions');
exports.helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello from Firebase!");
});
Well, found the solution here ("Allowing unauthenticated function invocation"):
"As of January 15, 2020, HTTP functions require authentication by default. You can specify whether a function allows unauthenticated invocation at or after deployment"

Yammer authentication issues

I'm creating an app on Outsystems, which uses the Yammer API. The issue is the Yammer authentication is causing some problems. In the "OnReady" property of the page, I've added the following code:
yam.getLoginStatus(
function(response) {
if (response.authResponse) {
console.log("logged in");
$parameters.Token = response.access_token.token;
console.dir(response); //print user information to the console
}
else {
yam.platform.login(function (response) { //prompt user to login and authorize your app, as necessary
if (response.authResponse) {
console.dir(response); //print user information to the console
console.dir(response.access_token.token);
$parameters.Token = response.access_token.token;
console.dir($parameters.Token);
}
});
}
}
);
It successfully returns a token, which I am able to verify using console.log(). Additionally, I've added a Login button which has the same code in its OnClick property.
The issue is, when I try to perform the Get Messages API call (Endpoint: https://www.yammer.com/api/v1/messages.json) from OnReady, it gives me the 401 Unauthorized access error. But, when I additionally use the OnReady, and also click the Login button, the API call is successful. I don't understand why, because the token received by both calls are the exact same, but it works after the user logs in twice? Any way to rectify this?
P.S. I've tried using the other endpoint (https://api.yammer.com/api/v1/messages.json). I'm getting the same problem.
Try adding a $resolve() inside the callback function. This way the code will wait until it finished before continuing to your next jav

What are the difference between `pushManager.subscribe` and `pushManager.getSubscription` Service Worker's

PushManager.getSubscription()
Retrieves an existing push subscription. It returns a Promise that resolves to a PushSubscription object containing details of an existing subscription. If no existing subscription exists, this resolves to a null value.
[...]
PushManager.subscribe()
Subscribes to a push service. It returns a Promise that resolves to a PushSubscription object containing details of a push subscription. A new push subscription is created if the current service worker does not have an existing subscription.
According to MDN's pushManager documentation. There methods are pretty much the same, except the point that in case of getSubcription() it may resolved with a null value.
I am basically understand that I can simply use subscribe() and Service Worker will try to get the subscription in case it available, and also create new one in case it not available.
=> But I was trying to do something else. I want to try to get subscription first, if it resolved with null I will try to subscribe it.
navigator.serviceWorker.register('./worker.js')
.then(function(reg) {
// Subscribe push manager
reg.pushManager.getSubscription()
.then(function(subscription) {
if(subscription){
// TODO... get the enpoint here
} else {
reg.pushManager.subscribe()
.then(function(sub){
// TODO... get the endpoint here
});
}
}, function(error) {
console.error(error);
})
});
But then I am ended up with the error:
Uncaught (in promise) DOMException: Subscription failed - no active Service Worker
It is confusing, and I am doubting this is a limitation of Chrome on Push API of Service Worker or can possibly a bug. Does any one has any information about this strange behavior?
The problem is that your service worker is registered, but it isn't active yet.
You can use navigator.serviceWorker.ready instead of subscribing right after registering the service worker.
If you want to make the service worker active as soon as possible, you can use skipWaiting and Clients.claim, as described in this ServiceWorker Cookbook recipe.

Issue with Google-API-PHP Client, getting error when running the quick start script

I am facing an issue with quickstart php script here: https://developers.google.com/drive/v2/web/quickstart/php
When I run the script first time, it executes perfectly and the access token is stored in a file called: drive-php-quickstart.json
When I run the script second time, it gives me the error:
Error start:
Notice: Undefined index: expires_in in \google-api-php-client\src\Google\Client.php on line 485
Fatal error: Uncaught exception 'LogicException' with message 'refresh token must be passed in or set as part of setAccessToken' in
Error end:
My assumption is that access token been saved in the file is not in the right format.
Current format:
ya29.CODE-oN_Bearer36001/_ANOTHER-CODE-ANOTHER_ANOTHER_CODE
As you can see, it does not contain the variable "expires_in"
Any suggestions where I am going wrong ? I am running the script as it is, with no modifications.
I've debugged it.... The person who wrote it made a mistake by not calling json_encode before writing the auth result to the token.json file.
You can fix it by adding json_encode on line 45.
So...
file_put_contents($credentialsPath, $accessToken);
...should be:
file_put_contents($credentialsPath, json_encode($accessToken));
I've submitted feedback so hopefully it'll be fixed.
edit: same issue happens for the token refresh call in that same method
edit2: Here's my related comment in a Github discussion and an answer from Google: https://github.com/google/google-api-php-client/issues/263#issuecomment-186557360
I suggested something along the following lines:
if ($client->isAccessTokenExpired()) {
$refreshToken = $client->getRefreshToken();
$client->refreshToken($refreshToken);
$newAccessToken = $client->getAccessToken();
$newAccessToken['refresh_token'] = $refreshToken;
file_put_contents($credentialsPath, json_encode($newAccessToken));
}
Instead of:
// Refresh the token if it's expired.
if ($client->isAccessTokenExpired()) {
$client->refreshToken($client->getRefreshToken());
file_put_contents($credentialsPath, $client->getAccessToken());
}
Google has updated their PHP Quickstart, with an improved method to handle this:
// Exchange authorization code for an access token.
$accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
$client->setAccessToken($accessToken);
// Refresh the token if it's expired.
if ($client->isAccessTokenExpired()) {
$client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
file_put_contents($credentialsPath, json_encode($client->getAccessToken()));
}

What does "error_description:access_denied" mean in BoxServerException

I ma trying to refresh my access token using the refresh token I have but I get following exception:
com.box.boxjavalibv2.exceptions.BoxServerException:
{"error":"access_denied","error_description":"Access denied"}
Please tell me what could be wrong with my request and why I am getting access_denied
If I send invalid refresh token, then I get
Caused by: com.box.boxjavalibv2.exceptions.BoxServerException:
{"error":"invalid_grant","error_description":"Invalid refresh token"}
I want to know the reasons for access_denied.
------------------- relevant code ------------------
BoxOAuthRequestObject requestObject = BoxOAuthRequestObject.refreshOAuthRequestObject(refreshToken, clientId,
clientSecret);
try {
// Authenticate with the new token
BoxOAuthToken boxOAuthToken = client.getOAuthManager().refreshOAuth(requestObject);
Not really sure what's going on without more information of your code.
One thing is that the sdk does auto-refresh the OAuth token. So basically you don't need to refresh it yourself. Please check https://github.com/box/box-java-sdk-v2#authenticate
I've received that error when attempting to call API methods that accessed the "Manage an enterprise" methods, while my application was defined as "Read and write all files and folders".
Make sure you set the appropriate checkbox at the application level.