Discord.js unable to login after using Client#destroy() - node.js

switch (command[0])
{
case 'restart':
if(msg.author.id == config["owner"]){
msg.channel.send(preEmbed('clientRestart'));
client.destroy();
client.login(config["token"]);
}
break;
}
this causes the error DiscordjsError: Request to use token, but token was unavailable to the client.
anyone know the cause / fix?

According to discord.js' github repo, you get that message when you don't provide a token, so make sure you are providing the token correctly.

Related

Send Direct Message using Twitter API does not work

I am trying to send Direct Message to a user who I follow and who follows me.
When I first tried to make a POSTMAN request as per the document here I was getting a HTTP 415 response, media type not supported. I looked up the Error code in their document and understood that this was happening because the callback_url needed to be whitelisted.
So I followed this guide to whitelist the callback_url and generate the access_request token , i.e oauth_token and oauth_secret here
So, was :
1. Get successfully oauth/request_token and got the Response: &oauth_callback_confirmed=true for the callback_url configured my app details. As far as I could tell, that's all I thought, I needed to do to whitelist the callback_url
2. Got oauth_verifier and final oauth_token and oauth_token_secret
But, after generating the outh_token and oauth_token_secret and using it to make the DM API call, Now I am getting
{
"errors": [
{
"code": 32,
"message": "Could not authenticate you."
}
] }
When I try to make a GET auth/authenticate call as documented here, I get a HTTP 403 with a message
Whoa there!
The request token for this page is invalid. It may have already been
used, or expired because it is too old. Please go back to the site or
application that sent you here and try again; it was probably just a
mistake.
I can see in the Documentation that https://api.twitter.com/1.1/direct_messages/events/new.json
Requires authentication? Yes (user context only)
I think I am missing something. Can anyone please help me point in the right direction as to what I need to be able to send DM to users successfully ?
I was also getting this error just now, I regenerated my API Key & Secret for the account and the Access Token & Secret for the application and then my POST request worked correctly.

How do I manually refresh-token while creating apps using Zapier CLI

I want to perform refresh token but my gateway gives HTTP response 403 instead of 401 so I cannot use 'autoRefresh' feature of Zapier.
I tried throwing 'RefreshTokenException' when the response status is 403 as given below:
return responsePromise
.then((response) => {
if (response.status == 403) {
throw new RefreshTokenException();
}
...
});
But upon doing this I get an Error from Zapier (while creating zaps) stating:
RefreshTokenException is not defined
Can anyone help me with manually refreshing token using Zapier CLI platform for app creation?
David here, from the Zapier Platform team. Sorry for the slow reply, we're just now seeing some of these.
It's not defined because that's not an error we define. You've got the right idea, you just need to use RefreshAuthError instead. See these docs.
​Let me know if you've got any other questions!

Keycloak - Grant validation failed. Reason: invalid token (wrong ISS)

So I'm having some issues with getting my Keycloak-Connect sample to work.
Basically I have a simple check with Keycloak on an express route On my VM
(10.10.10.54:8081) as follows.
app.get('/api*', keycloak.protect(), (req, res) => res.status(200).send({
message: 'Hit API Backend!',
}));
My Keycloak Server is on a separate VM (for this example http://keycloak.myexternaldomain.ca/auth/)
the calls I've been making to test this out are.
RESULT=`curl --data "grant_type=password&client_secret=mysecret&client_id=account&username=myusername&password=mypassword" http://keycloak.myexternaldomain.ca/auth/realms/TEST/protocol/openid-connect/token`
This returns the proper access token everytime,
TOKEN=`echo $RESULT | sed 's/.*access_token":"//g' | sed 's/".*//g'`
To parse token into a variable.
curl http://10.10.10.54:8081/api -H "Authorization: bearer $TOKEN"
Which still constantly returns Access Denied, I tried this in a similar example with the Keycloak-Quickstart Node Service to see if there was a more verbose error in that. What i'd receive back was
Validate grant failed
Grant validation failed. Reason: invalid token (wrong ISS)
Though if I waited a little bit it'd give me an Expired Token error so I feel like i'm on the right track.
so obviously there is something wrong from where i'm issuing the token from not matching where it's expecting? I can make a call to get the Users credentials from the keycloak server itself by cURLing to
curl --data "grant_type=password&token=$TOKEN&client_secret=secret&client_id=account&username=myaccount&password=mypassword" http://keycloak.myexternaldomain.ca/auth/realms/TEST/protocol/openid-connect/token/introspect
am I misinterpreting how I am supposed to be using Keycloak, or is this a settings issue?
Thanks in advance
My Issue was in my keycloak.json ... I had a different realm vs the one I was authenticating for.
If you're ever having this issue I suggest modifying keycloak-auth-utils to give you more verbose error logging on the grant-manager.
Specifically changing
else if (token.content.iss !== this.realmUrl) {
reject(new Error('invalid token (wrong ISS)'));
}
to
else if (token.content.iss !== this.realmUrl) {
reject(new Error('invalid token (wrong ISS) Expecting: '+this.realmUrl+' Got: '+token.content.iss);
}
helped me track down this issue myself.
If you are working in localhost and getting the same problem, my issue was that I was using https in localhost, i.e realmUrl: "https://localhost:8080/auth/realms/master" instead of realmUrl: "http://localhost:8080/auth/realms/master"
I have also faced with same issue . i used following checks to solve this
1.check the configuration in your project
is serverurl exact (127.0.0.1 , localhost, 0.0.0.0 are different urls ..mention
same as keycloak url)
is realm in small case
is client id and secret is correct
if still you are facing a problem try to use single quote instead of double quote
ex-
realm_name:"demo-realm" --> realm_name:'demo-realm'
it is working for me

Servicestack - Call AuthProvider automatically

I would like to build my own AuthProvider. It should
Check if ss-id cookie is set and check for a valid session (this is
done automatically in servicestack)
If no valid session was found check a custom http-header (e.g. X-Api-Token)
If found a valid token create a new session
If not found a valid token send 401 Unauthorized
Basically this is the behaviour of the CredentialsAuthProvider except that I need to check for the X-Api-Token without making an explicit call to /auth/credentials. However the AuthProvider is never called automatically.
Any ideas how to get this done?
Edit: One idea was to use a request filter but there is still something missing:
this.GlobalRequestFilters.Add((request, response, arg3) =>
{
//If there is a valid ss-id cookie the it should have precedence and the request should be authenticated accordingly
if (!ValidatedViaSsIdCookie())
{
if (HeaderHasCorrectApiKey()) {
//Authenticate the current request by creating a new Session
AuthenticateRequest();
}
}
}
);
How to implement ValidatedViaSsIdCookie() and AuthenticateRequest()???
Edit: I don't think GlobalRequestFilters are the way to go because they will be executed after authentication... So if there is no valid session the filter is not executed at all and my Api key is never checked... Still searching for a better solution...
Regards
Dirk

Facebook iOS SDK won't open login UI after user changes password (iOS 6)

Some context: the user had previously installed the app, authorized FB, everything worked great, then they changed their FB password (through facebook.com), deleted the app, and have now reinstalled it and are running it for the first time again after reinstall.
I am calling [FBSession openActiveSessionWithReadPermissions:allowLoginUI:completionHandler] with allowLoginUI: YES and the read permissions being "email, user_about_me, user_birthday, user_interests, user_location."
The FBSessionState I am getting in the completionHandler is FBSessionStateClosedLoginFailed. The NSLog of the error is this:
Error Domain=com.facebook.sdk Code=2 "The operation couldn’t be completed. (com.facebook.sdk error 2.)" UserInfo=0x1cd68c00 {com.facebook.sdk:ErrorLoginFailedReason=com.facebook.sdk:ErrorLoginFailedReason, com.facebook.sdk:ErrorInnerErrorKey=Error Domain=com.apple.accounts Code=7 "The Facebook server could not fulfill this access request: Error validating access token: The session has been invalidated because the user has changed the password." UserInfo=0x1cd5b970 {NSLocalizedDescription=The Facebook server could not fulfill this access request: Error validating access token: The session has been invalidated because the user has changed the password.}}
That internal error domain is ACErrorDomain and error code ACErrorPermissionDenied. So, how do I let the user re-authorize the app?
I have tried calling openActiveSessionWithReadPermissions again but that just keeps outputting the same error. I have also tried [FBSession.activeSession closeAndClearTokenInformation] but that doesn't seem to do anything (presumably because there is no activeSession).
Hitting a very similar sort of bug with 3.2.1 Facebook SDK. In my case, I get into FBSessionStateOpen but have been given an invalid access token. As the question states, the normal closeAndClearTokenInformation and even deleting the app doesn't fix it. The only way I have been able to get-back-in under this scenario is to have the user change their password in the setting app. So this is what I do.
// In my completion handler FBSessionStateOpen is called BUT an
// invalid accessToken was detected.
[session closeAndClearTokenInformation];
[FBSession renewSystemCredentials:^(ACAccountCredentialRenewResult result,
NSError *error)
{
if (result == ACAccountCredentialRenewResultFailed ||
result == ACAccountCredentialRenewResultRejected)
{
[self showErrorMessage:NSLocalizedString(#"You may need to re-enter your Facebook password in the iPhone Settings App.\n", nil)];
}
else
{
// attempt opening a session again (after they have updated their account
// settings I end up here)
[self facebookLogin]; // Performs openActiveSessionWithReadPermissions,
// but this time around the token issued should be good.
}
}];
This is the only pragmatic solution I have been able to come up with.
I think you need to get a new access token with code like this...
[FBSession.activeSession closeAndClearTokenInformation];
[[FBSession class] performSelector:#selector(renewSystemAuthorization)];
[FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
}

Resources