How to use MapJsonSubKey with json array - asp.net-mvc

I'm using the oauth2 flow in an MVC application. I can be redirected to the provider to challenge the user and password and I can get access token to be used for the API call
once I made the API call I can retrieve the info but the response is a JSON that contains an array
how can I use the MapJsonSubKey to map the email from the below JSON?
{
"ErrorList": null,
"Status": 1,
"UserDetailList": [
{
"Email": "pippo.pluto#xxx.com",
"FirstName": "pippo",
"LastName": "pluto",
"PersonId": "pippo.pluto#xxx.com",
"ProfilePhoto": 1,
"ProfilePhotoPath": null,
"Status": 100,
"Title": null,
"UpdatedDate": "/Date(1561120073327+0000)/",
"UserGUID": "8f643f10-0559-4e34-972d-52f41a4b9fcc",
"UserId": 20,
"UserName": "ca9ba551-9347-45b3-a926-c9bf361252e0"
}
]
}
if I use this code
options.ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier,"Id");
options.ClaimActions.MapJsonKey(ClaimTypes.Name, "Name");
options.ClaimActions.MapJsonKey("urn:infor:status", "Status");
options.ClaimActions.MapJsonSubKey("urn:infor:uname", "UserDetailList[]", "Email");
and in the cshtml, i use this
#User.FindFirst(c => c.Type == "urn:infor:uname")?.Value
i cannot see any value in the page

Related

Twitter OAuth 1.0 "215 Bad Authentication Data" error when requesting token

My use case is 3-legged auth for my current business to get some impression data from Twitter. This stuff was a breeze on LinkedIn but I'm falling at the first hurdle with Twitter, having followed docs & videos I'm still running into a "Bad Authentication Data" error when getting an access token.
I've snipped the callback, consumer key and token, but the consumer key is the API key from my Twitter app and the token is the Access Token from the same. Below is the json. none, signature and timestamp I got auto generated by postman. Any pointers?
{
"name": "get_access_token",
"properties": {
"activities": [
{
"name": "Web1",
"type": "WebActivity",
"dependsOn": [],
"policy": {
"timeout": "7.00:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"url": "https://api.twitter.com/oauth/request_token",
"method": "GET",
"headers": {
"OAuth": "oauth_nonce=\"wErUbiAbmCi\", oauth_callback=\"https%3A%2F%2F<snipped>\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"1613748394\", oauth_consumer_key=\"<snipped>", oauth_signature=\"hMnZtN5hT5KHRcyrxz8xis33C1c=\", oauth_version=\"1.0\", oauth_token = \"<snipped>\""
}
}
}
],
"annotations": []
}
}
The OAuth headers need to be sorted alphabetically. The documentation is here.

Titanium- Post request is not working when I using JSONArray in body content

Hi I am sending POST request using HTTPClient. Here I am passing some JSON data which have some arrays.
{
"pccpId": "11111",
"courseId": "XXXXX",
"employeeId": "XXXXXX",
"userId": "X!##$",
"assignments": [
{
"Id": "XXXX",
"targetDate": "05/30/2018",
"targetNewDate": "04/30/2018"
},
{
"Id": "YYYYY",
"targetDate": "04/22/2018",
"targetNewDate": "04/26/2018"
}
]
}
When I am using this data, I am getting 400 error code. When I am checking with backend is not at all hitting to the server. Same data giving expected result when I run on Postman.
Anyone have any suggestion!!
Thanks
I have this pb with titanium nodeJS api, workaround is to stringify your data and parse it on server
Try to but your keys without double quotation like this
{
pccpId: "11111",
courseId: "XXXXX",
employeeId: "XXXXXX",
userId: "X!##$",
assignments: [{
"Id": "XXXX",
"targetDate": "05/30/2018",
"targetNewDate": "04/30/2018"
},
{
"Id": "YYYYY",
"targetDate": "04/22/2018",
"targetNewDate": "04/26/2018"
}
]
}

Expand and Filter OData

I am trying to build a GET request to only pull specific data but I am having problems with utilizing OData.
Objects pulled from the API looks like this:
{
"PostalCode": "48103",
"FranchiseId": 397,
"Franchise": {
"ConceptId": 1,
"CreatedDateTime": "2015-10-20T18:36:46.353",
"ModifiedDateTime": "2018-01-26T14:35:33.447",
"DeletedDateTime": null,
"DoingBusinessAs": "Appliance.inc",
"Status": "Active",
"IsOwned": true,
"FranchiseeName": "Appliance Inc - Ann Arbor, MI - MLY 1001",
"LicenseNumber": "ML89023",
"City": "Ann Arbor",
"StateAbbr": "MI",
"PostalCode": "48104",
"ContactFirstName": "Doug",
"ContactLastName": "Smith",
"Country": "United States"
}
},
I am doing this GET request to get that data:
#url#&$expand=Franchise&$select=FranchiseId, PostalCode
I am using &$expand=Franchise just because I need the "FranchiseeName" from Franchise object but I don't want to pull the rest of the data of that object.
How can I write the request so I only pull three fields: PostalCode, FranchiseId, FranchiseeName. The object should look something like this:
{
"PostalCode": "48103",
"FranchiseId": 397,
"FranchiseeName": "Appliance.inc"
}
I assume #url# is a placeholder for the OData URI to your entity, e.g. http://server/odata/entityName.
The following URL should get the data you need:
http://server/odata/entityName?$select=PostalCode,FranchiseId&$expand=Franchise($select=FranchiseeName)
That should return only the required data, but still having the same structure as the full data, e.g:
{
"PostalCode": "48103",
"FranchiseId": 397,
"Franchise": {
"FranchiseeName": "Appliance.inc"
}
}

Accessing Values in Deeply Nested Array - Ruby on Rails

I am using an API call which returns a JSON response. I want to access the data inside the response so I can create some nice display cards showing the info and pictures. Here is a snippet from the response, the response property is populated with about 20 objects I'll include just two for brevity:
{
"success": true,
"message": "",
"result": [
{
"MarketCurrency": "LTC",
"BaseCurrency": "BTC",
"MarketCurrencyLong": "Litecoin",
"BaseCurrencyLong": "Bitcoin",
"MinTradeSize": 1e-8,
"MarketName": "BTC-LTC",
"IsActive": true,
"Created": "2014-02-13T00:00:00",
"Notice": null,
"IsSponsored": null,
"LogoUrl": "https://i.imgur.com/R29q3dD.png"
},
{
"MarketCurrency": "DOGE",
"BaseCurrency": "BTC",
"MarketCurrencyLong": "Dogecoin",
"BaseCurrencyLong": "Bitcoin",
"MinTradeSize": 1e-8,
"MarketName": "BTC-DOGE",
"IsActive": true,
"Created": "2014-02-13T00:00:00",
"Notice": null,
"IsSponsored": null,
"LogoUrl": "https://i.imgur.com/e1RS4Hn.png"
},
In my Rails controller I'm using JSON.parse and I'm trying to turn it into an object with the Open struct option:
#markets = JSON.parse(markets.to_json, object_class: OpenStruct)
In my view I'll do this <%=#markets.class%> and it shows Array and not object. So I try this <%=#markets.size%> and it shows 1. If I do <%=#markets[0]['success']%> I would expect it to return true but it returns 'success'. So, I'm not understanding why the ostruct library isn't working like I would expect or how I can get to the objects stored in the result array. Any help is greatly appreciated!
You already have a JSON response, isn't needed to use to_json again, try just parsing that object, and then use the dot . to access its fields, as an OpenStruct object now then you can access them as methods:
require 'json'
a = '{
"success": true,
"message": "",
"result": [{
"MarketCurrency": "LTC",
"BaseCurrency": "BTC",
"MarketCurrencyLong": "Litecoin",
"BaseCurrencyLong": "Bitcoin",
"MinTradeSize": 1e-8,
"MarketName": "BTC-LTC",
"IsActive": true,
"Created": "2014-02-13T00:00:00",
"Notice": null,
"IsSponsored": null,
"LogoUrl": "https://i.imgur.com/R29q3dD.png"
}, {
"MarketCurrency": "DOGE",
"BaseCurrency": "BTC",
"MarketCurrencyLong": "Dogecoin",
"BaseCurrencyLong": "Bitcoin",
"MinTradeSize": 1e-8,
"MarketName": "BTC-DOGE",
"IsActive": true,
"Created": "2014-02-13T00:00:00",
"Notice": null,
"IsSponsored": null,
"LogoUrl": "https://i.imgur.com/e1RS4Hn.png"
}]
}'
b = JSON.parse(a, object_class: OpenStruct)
p b.success
# => true
After much debugging and some assistance, I was able to get it to work. The response from the API call was an array with one item. The item was a long string of the entire dataset.
In order to get the expected behavior of "true" when calling #markets.success, I first had to
raw_markets = JSON.parse(markets.to_json)
followed by
#markets = raw_markets.map do |market|
JSON.parse(market, object_class: OpenStruct)
Note: the variable markets holds the original api call:
markets = open('url-to-api')
After this I would get #markets.success = "true" and #markets.result[0] held the first result, #markets.result[1] held the second result, and so on.

how to get callback value from cameratag in controller rails

How to get callback value from cameratag in controller rails?
How to use below code in controller rails in tutorial server callback?
data = JSON.parse(request.raw_post)
video_uuid = data["uuid"]
Make a HTTPpost request with the required parameters as given in the link https://cameratag.com/docs/setup#callback . Then from the response you need to execute the data line. EX :
data_map = {
"uuid": "6611a310-72c4-0130-04c5-123139045d73",
"camera_uuid": "63f9c870-72c4-0130-04c5-123139045d73",
"created_at": "2013-03-19T13:11:13Z",
"percent_complete": 0,
"short_code": null,
"metadata": {
},
"state": "published",
"recorded_from": "https://cameratag.com/",
"publish_type": null,
"formats": [
{
"name": "360p",
"width": 480,
"height": 360,
"video_url": "http://cameratag.com/videos/6611a310-72c4-0130-04c5-123139045d73/360p/mp4",
"mp4_url": "http://cameratag.com/videos/6611a310-72c4-0130-04c5-123139045d73/360p/mp4",
"webm_url": "http://cameratag.com/videos/6611a310-72c4-0130-04c5-123139045d73/360p/webm",
"thumbnail_url": "http://cameratag.com/videos/6611a310-72c4-0130-04c5- 123139045d73/360p/thumb",
"small_thumbnail_url": "http://cameratag.com/videos/6611a310-72c4-0130-04c5- 123139045d73/360p/small_thumb",
"state": "COMPLETED",
"completed_at": null
}
]
}
path = -- give the path for the post request.
http = Net::HTTP.new('site-name.com')
resp = http.post(path,data_map)
data = JSON.parse(resp)
video_uuid = data["uuid"]
There are many other ways to make a post request. The point is you need to use JSON.parse() on the response of the post request and then get the uuid.

Resources