Trying to complete the Zoom API OAuth Server to Server Flow. Following this guide: https://marketplace.zoom.us/docs/guides/build/server-to-server-oauth-app/#enable-permissions
But I am getting the following response:
data: { reason: 'The application is disabled', error: 'invalid_client' }
Appears active to me:
Authentication request
let zoomAccessTokenConfig = {
headers: {
Authorization: `Basic ${Buffer.from('yXXXXXXXX:UXXXXXXXXX').toString('base64')}`,
}
}
let zoomAccessTokenResponse = await axios.post('https://zoom.us/oauth/token?grant_type=account_credentials&account_id=oXXXXXXXX', null, zoomAccessTokenConfig)
.then(response => {
console.log('response');
console.log(response);
return response?.Access_token;
})
Related
I'm trying to send e-mails with MS Graph 1.0 and I have not any get any result or response. E-Mails haven't been sent and sendMail method don't return any error o message... it only says "null".
My code is based on this example https://github.com/microsoftgraph/msgraph-sdk-javascript#post-and-patch and looks like this:
// Initialize Graph client
const client = graph.Client.init({
authProvider: (done) => {
done(null, accessToken);
}
});
try {
// construct the email object
var mail = {
subject: "Microsoft Graph JavaScript Sample",
toRecipients: [{
emailAddress: {
address: "mail#domain.com"
}
}],
body: {
content: "<h1>MicrosoftGraph JavaScript Sample</h1>Check out https://github.com/microsoftgraph/msgraph-sdk-javascript",
contentType: "html"
}
};
client
.api('/me/sendMail')
.post({message: mail}, (err, res) => {
console.log("---> " + res);
});
console.log("Try ends");
} catch (err) {
parms.message = 'Error retrieving messages';
parms.error = { status: `${err.code}: ${err.message}` };
parms.debug = JSON.stringify(err.body, null, 2);
res.render('error', parms);
}
I guess mail var needs a header, but anyway, API should return me something, right? And, obviously, which is the problem with the email sending?
I finally added rawResponse to .post call and look at err log...
client
.api('/me/sendMail')
.header("Content-type", "application/json")
.post({message: mail}, (err, res, rawResponse) => {
console.log(rawResponse);
console.log(err);
});
... and I could see that I had problem with my authentication token. So, I was using the api correctly and code from the question is ok.
I can obtain the OAuth2 token, but can't revoke it.
Reproducing the error:
let token_url = "https://api.twitter.com/oauth2/token";
let revoke_url = "https://api.twitter.com/oauth2/invalidate_token"
let auth = {
username: CLIENT_API_KEY,
password: CLIENT_API_SECRET_KEY
}
axios.post(token_url, "grant_type=client_credentials", { auth })
.then( response => {
let access_token = response.data["access_token"]
axios.post(revoke_url, `access_token=${access_token}`, { auth })
.then( response => {
console.log("REVOKE SUCCESS")
console.log(response)
})
.catch( e=> {
console.log("Failed to revoke")
console.log(e.response.data)
})
})
then I get
Failed to revoke
{ errors:
[ { code: 348,
message:
'Client application is not permitted to to invalidate this token.' } ] }
Tried googling but nothing came out of the code 348 and the message. The http error code is 401 (unauthorized).
I will never be able to revoke my OAuth2 token. Help.
I'm trying to set up authentication using the Auth0 lock along with a React single page app and a Ruby on Rails API.
import React from 'react';
import Auth0Lock from 'auth0-lock';
var Login = React.createClass({
componentWillMount: function() {
this.lock = new Auth0Lock('*************', '****.eu.auth0.com', {
allowedConnections: ['facebook']
});
this.lock.on('authenticated', this._doAuthentication.bind(this));
},
showLock: function() {
this.lock.show();
},
_doAuthentication(authResult) {
console.log('Bearer '+authResult.idToken);
var request = require("request");
var options = { method: 'POST',
url: 'http://localhost:3000/authenticate',
headers: { authorization: 'Bearer '+authResult.idToken } };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
console.log(authResult);
this.setToken(authResult.idToken)
},
login() {
this.lock.show()
},
loggedIn() {
return !!this.getToken()
},
setToken(idToken) {
localStorage.setItem('id_token', idToken)
},
getToken() {
return localStorage.getItem('id_token')
},
logout() {
localStorage.removeItem('id_token');
},
render: function() {
return (
<div className="login-box">
<button className="btn btn-success" onClick={this.showLock}>Sign In</button>
</div>);
}
});
export default Login;
This code comes from the Auth0 documentation. I also configured knock on the Rails API. Still, whenever I click on the "Connect via Facebook" button, I get the following:
- my token is generated (It's a valid token)
- Request is sent, with the correct authorization header
- Rails returns a 401
I made sure Rails receives the header as "Bearer [MY TOKEN]", still getting a 401.
Did I miss something ? Is anything else required ?
Ok, finally found out: my secret was not 64base encoded, which means the JWT.base64url_decode in my knock.rb was not necessary. I removed it, and voila.
I have a node express application that I am attempting to add nodemail support. I have created a gmail account for this purpose (NOTE: the gmail account has "Less Secure App" enabled). My code is as follows:
var mailOptions = {
from: "XXXX#gmail.com",
to: YYYY#gmail.com,
subject: "Test",
generateTextFromHTML: true,
text: 'This is a test'
};
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
xoauth2: xoauth2.createXOAuth2Generator({
user: 'XXXX#gmail.com', // Your gmail address.
clientId: '123456789abcd-123456789abcdef.apps.googleusercontent.com',
clientSecret: 'XXXX-123456789',
refreshToken: '1/abcdefg',
accessToken: '123.abcdef'
})
}
});
transporter.sendMail(mailOptions, function(error, response) {
if (error) {
console.log('BAD' + error);
} else {
console.log('GOOD' + response);
}
transporter.close();
});
I am able to send e-mail some of the time. After a few successful attempts, I get the following error:
Error: connect ETIMEDOUT
I will continue to get these timeout errors and then it will work again for a few attempts.
I'm trying to use the petfinder APi for an app I'm creating and following the API documentation which can be found here : https://www.petfinder.com/developers/v2/docs/#developer-resources.
It gives the command : curl -d "grant_type=client_credentials&client_id={CLIENT-ID}&client_secret={CLIENT-SECRET}" https://api.petfinder.com/v2/oauth2/token
Im trying to translate this for react native and used the following code:
getAdopt1 = async() => {
fetch('https://api.petfinder.com/v2/oauth2/token', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
firstParam: "grant_type=client_credentials&client_id={CLIENT-ID}&client_secret={CLIENT-SECRET}"
}),
}).then((response) => response.json())
.then((responseJson) => {
let res = JSON.stringify(responseJson)
console.log("Response: "+res)
return responseJson;
})
.catch((error) => {
console.error(error);
})
}
However I get the following error:
Response: {"type":"https://httpstatus.es/400","status":400,"title":"unsupported_grant_type","detail":"The authorization grant type is not supported by the authorization server.","errors":[{"code":"unsupported_grant_type","title":"Unauthorized","message":"The authorization grant type is not supported by the authorization server. - Check that all required parameters have been provided","details":"The authorization grant type is not supported by the authorization server. - Check that all required parameters have been provided","href":"http://developer.petfinder.com/v2/errors.html#unsupported_grant_type"}],"hint":"Check that all required parameters have been provided"}
What am I doing wrong here ?
You are sending a JSON request but what the API expects is a Form-Data request.
Try with something like this:
var form = new FormData();
form.append('grant_type', 'client_credentials');
form.append('client_id', '{CLIENT-ID}');
form.append('client_secret', '{CLIENT-SECRET}');
fetch('https://api.petfinder.com/v2/oauth2/token', {
method: 'POST',
body: form,
}).then(response => {
console.log(response)
}).catch(error => {
console.error(error);
})