I'm trying to use the Google Cloud Print library to get a list of the cloud printers available to the users, but when I do a request I get an error: "User credentials required"
This is how I send the request:
var request = require('request');
var options = {
url: 'https://www.google.com/cloudprint/search',
headers: {
'X-CloudPrint-Proxy': 'APP_NAME',
'Authorization': 'GoogleLogin auth=ACCESS_TOKEN_HERE'
}
};
function callback(err, response, body) {
console.log(err);
console.log(response);
console.log(body);
}
request(options, callback);
In order to make this work (as there is no exact documentation).
Add https://www.googleapis.com/auth/cloudprint to the scope of the login procedure.
If you look here: https://github.com/dpsm/android-print/blob/master/src/main/java/com/github/dpsm/android/print/GoogleCloudPrint.java
They want the Authorization to be
Bearer ACCESS_TOKEN_HERE
instead of
GoogleLogin auth=ACCESS_TOKEN_HERE
Related
I have a Node.js back which currently is running on Firebase in the form of cloud functions. Except for that, I also have an Azure Active Directory with some users that I have invited
So, I want to be able to access them from the Node.js get a list of their emails and names. From what I understood, I can achieve that by making a reference to Microsoft's Graph API and more specifically to their Users API. As every request to Azure AD needs to be OAuth2 authenticated, I was wondering what is the best way of achieving that in my situation. What client flow do I need to implement? I am currently focused on the one which is based on client credentials.
Thanks in advance and whatever general suggestion are more than welcome!
This issue gets Access token and calls Microsoft Graph API using node.js.
The user API of Azure Active Directory Graph API is no longer updating. This MS graph API is newer.
Get access token using client credentials flow:
const request = require("request");
const endpoint = "https://login.microsoftonline.com/[Tenant]/oauth2/v2.0/token";
const requestParams = {
grant_type: "client_credentials",
client_id: "[ApplicationID]",
client_secret: "[Key]",
scope: "https://graph.microsoft.com/.default"
};
request.post({ url:endpoint, form: requestParams }, function (err, response, body) {
if (err) {
console.log("error");
}
else {
console.log("Body=" + body);
let parsedBody = JSON.parse(body);
if (parsedBody.error_description) {
console.log("Error=" + parsedBody.error_description);
}
else {
console.log("Access Token=" + parsedBody.access_token);
}
}
});
Call MS Graph API:
function testListGroupGraphAPI(accessToken) {
request.get({
url:"https://graph.microsoft.com/v1.0/users",
headers: {
"Authorization": "Bearer " + accessToken
}
}, function(err, response, body) {
console.log(body);
});
}
I am building a NodeJS application from where I want to get project/issues from JIRA using REST APIs provided by JIRA. My jira is running on some server ('http://example.com:8080/secure/Dashboard.jspa') and I am able to use REST APIs from POSTMAN using BASIC AUTH to get all kind of data but when I tried to log in to JIRA using REST APIs and NodeJS, I am getting some response but I am not able to understand it how I am going to use that information to call other APIs.
What I am doing is, I am passing username and password as a command-line args then I am sending those creds to login to JIRA. Then I am going to use the 'node-fetch' package to get information from REST APIs.
Below is my code:
const fetch = require("node-fetch");
const yargs = require("yargs");
var JiraClient = require("jira-connector");
var request = require("request");
const jiraBaseUrl = "http://example.com:8080/secure/Dashboard.jspa";
const loginUrl = "auth/1/session";
const username = yargs.argv.u;
const password = yargs.argv.p;
const projectName = yargs.argv.n;
var headers = {
"Content-Type": "application/json"
};
var options = {
url: "http://example.com:8080/rest/api/2/issue/createmeta",
headers: headers,
auth: {
user: username,
pass: password
}
};
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
request(options, callback);
Can somebody please tell me what I am doing wrong or what do I need to do with the data I am getting in order to use other APIs like ('http://example.com:8080/rest/api/2/issue/10008')? Or am I doing something wrong to login?
I have read the documentation on the JIRA website but was not able to understand correctly.
If you look at the Jira Rest API documentation, rest/api/2/issue/createmeta is the end point for Get create issue metadata. It "returns details of projects, issue types within projects, and, when requested, the create screen fields for each issue type for the user. " This data is supposed to be huge since it returns the details of all projects, and all issue types within projects.
If you want to use other API just change the url to the appropriate url with the correct endpoints (documentation) and follow the documentation on what to send as the body data.
Here is one example of getting the details of one issue:
Put the issueIdOrKey you want to get in the brackets
var options = {
method: 'GET',
url: 'http://example.com:8080/rest/api/latest/issue/{issueIdOrKey}',
auth: { username: username, password: password },
headers: {
'Accept': 'application/json'
}
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(
'Response: ' + response.statusCode + ' ' + response.statusMessage
);
console.log(body); //this would log all the info (in json) of the issue
// you can use a online json parser to look at this information in a formatted way
});
in my Express app I have to get access token for Auth0. In the documentation, they have an example for pure Node JS with a request:
var request = require("request");
var options = { method: 'POST',
url: 'https://XXX.eu.auth0.com/oauth/token',
headers: { 'content-type': 'application/json' },
body: '{"client_id":"XXX","client_secret":"XXX","audience":"http://localhost:3001/","grant_type":"client_credentials"}' };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
But when I'm trying to do the same in a next way:
app.post('/token', function(options, res) {
return res.json()
});
I'm getting "UnauthorizedError: No authorization token was found".
How can I do it properly?
Are you sure that you have enabled client_credentials grant type in your app?
Go to application / advanced / grant types and enable client_credentials
See picture here
I'm using sendgrid (javascript) to add a new contact to my list.
Within marketing.
var request = require("request");
var options = { method: 'PUT',
url: 'https://api.sendgrid.com/v3/contactdb/lists/193029b7-0b8b-4c0c-948d-47d09a157542/recipients',
headers: { authorization: 'Bearer myapi' },
body: '{"contacts":[{"email": "myemail#gmail.com","unique_name":"hello"}]}' };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
But then I get the message 'acces forbidden'.
Am I using the wrong url?
(The API token is set to administrator all access.)
Thanks!
It looks like there's a few things going on here.
According to the docs, there are not endpoints in the Contact API that accept the method PUT.
After checking our own implementation, it also looks like there's an issue with what you're intending to do.
See the docs for adding multiple recipients to a list:
POST https://api.sendgrid.com/v3/contactdb/lists/{list_id}/recipients HTTP/1.1
Request body:
[
"recipient_id1",
"recipient_id2"
]
In order to use that method, you need to first create the users and retrieve their recipient ID's.
POST https://api.sendgrid.com/v3/contactdb/recipients HTTP/1.1
[
{
"email": "myemail#gmail.com",
"unique_name":"hello"
}
]
Check out the links posted for more information on their usage and response.
I'm working with Facebook Graph API and can't figure out why I can't accept the following route : /{page-id}/conversations
When I do I receive the following error : (#283) Requires extended permission: manage_pages
Here is the way I get my token :
First I get an acces_token for the user using the usual login, I ask for ['read_page_mailboxes', 'manage_pages']as permissions.
With this access token I call /me/accounts to get the list of pages for this user. In my case the user only have a single page, from this page I take the ID and access_token.
Being able to retrieve an access_token for the page means thaht the manage_pages permission is indeed granted.
Then I try to call /{page-id}/conversations with the page access_token and I face the error mentioned earlier.
Here is a snippet for node.js which is basically what I do in my app in a single function :
var options = {
url: getFbUrl('/me/accounts'),
qs: { // Query string parameters
access_token: userAccessToken,
},
method: 'GET'
};
request(options, function (err, response, body) {
if (err)
return done(err);
body = JSON.parse(body);
var pageAccessToken = body.data[0].access_token,
pageId = body.data[0].id;
var pageOptions = {
url: getFbUrl('/' + pageId + '/conversations'),
qs: {
access_token: pageAccessToken
},
method: 'GET'
};
request(pageOptions, function (err, response, body) {
if (err)
return done(err);
console.log(response.statusCode);
console.log('PAGE BODY', body);
done();
});
});
I've been stuck on this for way longer than I'd like, any help or tips appreciated.
Have a nice day.
It's a reported bug and here is the link: https://developers.facebook.com/bugs/380833342117530/