Unable to create Power Bi Datasource using API - azure-active-directory

I'm trying to create Power Bi data source following Microsoft provided documentation. But getting Bad Request DMTS_InvalidConnectionDetailsError error. Here is my post data sample.
{
"dataSourceType": "SQL",
"connectionDetails": "{\"Server\":\"MySqlServer\",\"Database\":\"MySqlDatabase\"}",
"datasourceName": "New Datasource",
"credentialDetails": {
"credentialType": "Basic",
"credentials": "{\"credentialData\":[{\"name\":\"username\", \"value\":\"MyUsername\"},{\"name\":\"password\", \"value\":\"MyPassword\"}]}",
"encryptedConnection": "Encrypted",
"encryptionAlgorithm": "RSA-OAEP",
"privacyLevel": "None"
}
}
And here is the response json.
{
"error":
{
"code": "DMTS_InvalidConnectionDetailsError",
"pbi.error": {
"code": "DMTS_InvalidConnectionDetailsError",
"parameters": {},
"details": [],
"exceptionCulprit": 1
}
}
}
Anybody can help please?

The credentials from credential details need to be encrypted using the RSA algorithm before passing it to the API. You can use the algorithm from https://learn.microsoft.com/en-us/power-bi/developer/encrypt-credentials. Also, the name of the server needs to have double the amount of "\" characters if it has any.

Related

Firebase Cloud Firestore - Fail to write via REST API

This is not an authentication error, write is enabled on the database rules.
My cloud Firestore database looks like the picture below.
There is a COLLECTION called colA, inside it there is a DOCUMENT called docA, and inside it there are some fields (strings) stored.
On Postman, if I do GET https://firestore.googleapis.com/v1/projects/eletronica-ab6b1/databases/(default)/documents/colA/docA, I do receive the following answer, and it is correct:
{
"name": "projects/eletronica-ab6b1/databases/(default)/documents/colA/docA",
"fields": {
"fieldB": {
"stringValue": "ABCD"
},
"fieldA": {
"stringValue": "888"
}
},
"createTime": "2020-01-31T16:48:26.859181Z",
"updateTime": "2020-02-05T19:21:49.654340Z"
}
Now, when I try to write a new field (fieldC) via POST https://firestore.googleapis.com/v1/projects/eletronica-ab6b1/databases/(default)/documents/colA/docA, with JSON content:
{
"name": "projects/eletronica-ab6b1/databases/(default)/documents/colA/docA",
"fields": {
"fieldC": {
"stringValue": "1000"
}
}
}
After SEND, I receive this:
{
"error": {
"code": 400,
"message": "Document parent name \"projects/eletronica-ab6b1/databases/(default)/documents/colA\" lacks \"/\" at index 60.",
"status": "INVALID_ARGUMENT"
}
}
What I'm doing wrong? I really would like to write strings there via REST API.
Regards.
Updating a document is done with a PATCH request, according to the [reference documentation).
A POST request is used to create a new document in a collection, which probably explains the error you get: you're pointing to a document, but POST expects a collection path.

How to get access token programatically for GCP Compute API

I need some help for access tokens in GCP. I am using Java as program language and I tried different approaches like:
https://cloud.google.com/iap/docs/authentication-howto
and https://developers.google.com/identity/protocols/OAuth2ServiceAccount#jwt-auth
I am using the second approach. Code snippet:
String privateKeyId = "my-private-key";
long now = System.currentTimeMillis();
String signedJwt = null;
try {
Algorithm algorithm = Algorithm.RSA256(null, privateKey);
signedJwt = JWT.create()
.withKeyId(privateKeyId)
.withIssuer("my-issuer")
.withSubject("my-subject")
.withAudience("https://www.googleapis.com/compute/v1/compute.machineTypes.list")
.withIssuedAt(new Date(now))
.withExpiresAt(new Date(now + 3600 * 1000L))
.sign(algorithm);
} catch (Exception e){
e.printStackTrace();
}
return signedJwt;
Then I perform get instances setting the returned token as Bearer authorization header but response is:
com.google.api.client.http.HttpResponseException: 401 Unauthorized
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
With same credentials I am able to access the SDK.
Thanks!
As per #DalmTo, you should be using the client library for Java. This is the link to get you started.

JS Report Server Console error: Authorization server has no "username" field in its response, token assumed as invalid

My js report server with client ui applications was working with username filed by adding one claim e.g. Claim('username', 'user name value') in identityserver.
4 version 1.1. B ut recently client has upgraded the identityserver 4 version to 2.2.0 and netcoreapp2.1 .
Now the client ui applications get "Unauthorized" error. When I run the application locally I see one error in jsreport server console:
error: Authorization server has no "username" field in its response, token assumed as invalid.
I have tried to find solution in the sample:
https://github.com/bjrmatos/jsreport-with-authorization-server-sample but they have not upgraded the sample for latest .net core and identity server yet, I see the node js sample link "https://github.com/IdentityServer/IdentityServer4.Samples/tree/release/NodeJsApi" does not exists. so I am unable to solve the issue. Can anyone help me please on this?
Thanks in advance.
I have found solution to solve this error by adding a claim type with user name and declare that in api resource scope:
new ApiResource
{
Name="jsreportscope",
DisplayName = "JavaScript based reporting platform",
Scopes=
{
new Scope()
{
Name="jsreportscope",
UserClaims = new List<string>(){"username" }
}
},
UserClaims = new List<string>(){"username"},
ApiSecrets = { new Secret("yoursecret".Sha256()) },
}
But now it goes to the previous problem that I fixed by adding a claim type matching the value of username field value with identity server 1.1 version but now we have upgraded the identity server version to 2.1 and again getting the error. The it was able to authorize any user of identity server for report access. Here is the jsreport.config.js code I am using:
{
"store": { "provider": "fs" },
"httpPort": 5004,
"allowLocalFilesAccess": true,
"extensions": {
"authentication": {
"cookieSession": {
"secret": "<your strong secret>"
},
"admin": {
"username": "IdentityServer4User#domain.com",
"password": "Password"
},
"authorizationServer": {
"tokenValidation": {
"endpoint": "http://localhost:5000/connect/introspect",
"usernameField": "username",
"activeField": "active",
"scope": {
"valid": ["jsreportscope"]
},
"auth": {
"type": "basic",
"basic": {
"clientId": "jsreport",
"clientSecret": "yoursecret"
}
}
}
},
"enabled": true
},
"authorization": {
"enabled": true
},
"sample-template": {
"createSamples": true
}
}
}
But now I can login and access reports from report server if login by only the user IdentityServer4User#domain.com any other users is getting unauthorized error. In the report server console the error is shown like:
error: username "OtherIdentityServer4User#domain.com" returned from authorization server is not a jsreport user. I don not want to add all the identity server users to js report server.

Best practice Backand regarding JSON transformation and related objects

I am currently trying to figure out how to setup my Backand app and its REST API. This question is related to question: Backand deep querying. However, I was hoping that I could get some best practice code examples on how to perform server side code to perform a loop and create a JSON responds with the following criteria:
I want to be able to make a REST request to Backand and get one data object back that has manipulated/merged two data objects from my database.
I have an object called "media" and another named "users". Obviously, users contain user information and media contains information on a picture that the user has uploaded. The two objects are related by the userId and by collection set in Backand. I want to make a GET request that responds with a JSON object with all pictures and a nested user object on each picture object that contains the related user information. I know that I get back "relatedObjects", and I could then make some manipulation on the client side, but I am hoping that there is another easier way to do this from the Backand administration system either on server side code or as a query.
So, my question is, what's the best way to produce a REST call that responds a database object with nested related data object through Backand?
Here's the object models (shorten for clarity):
User object model as set up in Backand
{
"name": "users",
"fields": {
"media": {
"collection": "media",
"via": "user"
},
"email": {
"type": "string"
},
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
}
} }
Media object model as set up in Backand
{
"name": "media",
"fields": {
"description": {
"type": "string"
},
"thumbnail": {
"type": "string"
},
"fullImage": {
"type": "string"
},
"user": {
"object": "users"
}
}}
Final JSON response that I am looking for:
{
description: 'Blah',
thumbnail: 'someImageUrl.jpg',
fullImage: 'someImageUrl.jpg',
user: {
firstName: 'John'
lastName: 'Smith'
email: 'john#smith.com'
}
}
Just in case anybody else comes across this, I chose to do it with server-side javascript code, since my backend, SQL and NoSQL query skills are very weak. I'm guessing a noSQL query would probably be better in terms of performance. And I would still like to see how it could be done in noSQL. Anyway my server-side javascript code in a Backand action does the job. Here it is:
/* globals
$http - Service for AJAX calls
CONSTS - CONSTS.apiUrl for Backands API URL
Config - Global Configuration
socket - Send realtime database communication
files - file handler, performs upload and delete of files
request - the current http request
*/
'use strict';
function backandCallback(userInput, dbRow, parameters, userProfile) {
var response = [];
var request =
$http({
method: "GET",
url: CONSTS.apiUrl + "/1/objects/media",
headers: {"Authorization": userProfile.token},
params: {
exclude: 'metadata',
deep: true
}
});
var object = request.data;
var related = request.relatedObjects.users;
for (media in object) {
if (object.hasOwnProperty(media)) {
for (user in related) {
if (object[media].user == related[user].id) {
response.push({
id: object[media].id,
thumbnailUrl: object[media].thumbnail,
description: object[media].description,
fullName: related[user].firstName + ' ' + related[user].lastName,
email: related[user].email
});
}
}
}
}
return response;
}

Fetching Facebook Timeline posts using Facebook API

I'm facing following issues while fetching facebook user/pages/group timeline posts:
I'm not getting all information (photos urls, link, created_time, etc) in posts objects retrieved using this. Following is a sample response of this api:
[
{
"message": "this is going to be real fun https://localhost.com/N1AyEvZp",
"story": "Rajveer Singh added photos to XYZ Photos in My-group.",
"updated_time": "2015-09-03T16:27:34+0000",
"id": "405944472923733_413853035466210"
},
{
"message": "this is going to be fun https://localhost.com/EJo1WvZp",
"story": "Rajveer Singh added photos to XYZ Photos in My-group.",
"updated_time": "2015-09-03T16:14:41+0000",
"id": "405944472923733_413848848799962"
},
{
"message": "this is going to be some real funhttps://localhost.com/VyVKdWga",
"story": "Rajveer Singh added photos to XYZ Photos in My-group.",
"updated_time": "2015-09-02T15:45:08+0000",
"id": "405944472923733_413582785493235"
}
]
This response is missing the photo urls, links, captions, etc from the posts. Is there any different api for fetching those informations ? Also, if I directly hit the one of the post object /405944472923733_413582785493235 then I get following response:
{
"created_time": "2015-09-02T15:45:07+0000",
"message": "this is going to be some real funhttps://localhost.com/VyVKdWga",
"story": "Rajveer Singh added photos to XYZ Photos in My-group.",
"id": "405944472923733_413582785493235"
}
Though I get created_time in this response but pictures, urls, are still missing. I found this api deprecated. Is there any different api which can give me all the info ?
The above response is also missing comments and replies. On google search I found that we can get comments using /405944472923733_413582785493235/comments api but again that api doesn't mention the exact comments count. Also, the api doesn't give all the comments in a single api call. They have a pagination kind of thing. Can anyone tell me how can I get exact count of comments, replies to comments, and retrieve all the comments in a single api call. If we can't retrieve all the comments in a single go, then how can we use pagination ? I need to send all the comments related to a post to my front-end. with pagination, how can I achieve that ? Do I need to store the previous/next urls somewhere in front-end ? Following is a sample response of this:
{
"data": [
{
"id": "[post_id]",
"from": {
"name": "[name]",
"id": "[id]"
},
"message": "[message]",
"created_time": "2011-01-23T02:36:23+0000"
},
{
"id": "[id]",
"from": {
"name": "[name]",
"id": "[id]"
},
"message": "[message]",
"created_time": "2011-01-23T05:16:56+0000"
}
],
"paging": {
"cursors": {
"after": "WTI5dGJXVnVkRjlqZFhKemIzSTZOREUzTVRJeE5qWTRORGN5Tmpnd09qRTBOREl3T0RRd09URT0=",
"before": "WTI5dGJXVnVkRjlqZFhKemIzSTZOREUzTVRFNU16RTRORGN5T1RFMU9qRTBOREl3T0RRd05qZz0="
},
"previous": "previousUrl",
"next": "nextUrl"
}
How to get count of all the likes and shares of a post ? I simply want the count and doesn't want who actually likes/shared the post. How can I get that ? I found that using /likes gives a list of all those who liked the post but it doesn't give the count. Following is a sampple response of that:
{
"data": [
{
"id": "824565440992306"
}
],
"paging": {
"cursors": {
"after": "ODI0NTY1NDQwOTkyMzA2",
"before": "ODI0NTY1NDQwOTkyMzA2"
}
}
}
General Information:
I'm using Node.js Javascript SDK for hitting FB APIs.
I'm using correct access token, so that's not an issue for sure.
I have gone through this and this but didn't get any help from them.
I need all the information related to wall posts on my back-end so that I can send all data to my front-end for proper rendering. This is a screenshot of my front-end and all the information which I need in front-end.
Can anyone please try to clear my doubts ?
Also, if there is any optimized way of fetching all this information, then please do suggest. Your suggestions are welcome.

Resources