wso2 5.6 identity server SCIM user creation with email and while find the users email is not returning from JSON - json

While creating a user using SCIM1.1 endpoint with email.
curl -v -k --user admin:admin --data '{"schemas":[],"name":{"familyName":"gunasinghe","givenName":"hasinitg"},"userName":"hasinitg_sample","password":"hasinitg","emails":[{"primary":true,"value":"hasini_home.com"}]}' --header "Content-Type:application/json" https://localhost:9443/wso2/scim/Users
Created User response:
{"emails":[{"value":"hasini_home.com"}],"meta":{"created":"2018-09-18T15:43:17","location":"https://localhost:9443/wso2/scim/Users/37f051b2-770c-4915-9a3f-623a7404b2a4","lastModified":"2018-09-18T15:43:17"},"schemas":["urn:scim:schemas:core:1.0"],"name":{"familyName":"gunasinghe","givenName":"hasinitg"},"id":"37f051b2-770c-4915-9a3f-623a7404b2a4","userName":"hasinitg_sample"}
Retrieve the USER from SCIM endpoint:
curl -v -k --user admin:admin https://localhost:9443/wso2/scim/Users/37f051b2-770c-4915-9a3f-623a7404b2a4
The response is:
{"meta":{"created":"2018-09-18T15:43:17","location":"https://localhost:9443/wso2/scim/Users/37f051b2-770c-4915-9a3f-623a7404b2a4","lastModified":"2018-09-18T15:43:17"},"schemas":["urn:scim:schemas:core:1.0"],"roles":["Internal/everyone"],"name":{"familyName":"gunasinghe","givenName":"hasinitg"},"id":"37f051b2-770c-4915-9a3f-623a7404b2a4","userName":"hasinitg_sample"}
The email is missing here in the response and My-Sql DB as well. Any idea?

The issue seems to be that if you are sending the email as a JSON object, you have to set the type as well. Following debug log is written when we send an email object without the type attribute.
TID: [-1234] [] [2018-09-19] DEBUG
{org.wso2.carbon.identity.scim.common.utils.AttributeMapper} - Type
attribute cannot be null for sub attribute:
org.wso2.charon.core.attributes.ComplexAttribute#71ebf24c of Complex
MultiValuedAttribute: emails. Skip adding as a claim
Please see the given sample request in the documentation
{"primary":true,"value":"hasini_home.com","type":"home"}
You can use the following request to simply solve your problem.
curl -v -k --user admin:admin --data '{"schemas":[],"name":{"familyName":"gunasinghe","givenName":"hasinitg"},"userName":"hasinitg_sample","password":"hasinitg","emails":"hasini_home.com"}' --header "Content-Type:application/json" https://localhost:9443/wso2/scim/Users

Related

How to extract bearer token from curl json response and pass it as authorization header a different api call?

I am making a call to OAuth API using curl command by passing username,password and getting the bearer token response as JSON which is in the below format.
curl -X POST https://api.mysite.com/oauth/token -u "login:password"
Response
{
"token_type:"Bearer",
"access_token:" "cfdadfa3234sfsdfxx......",
"issued_at":15234234234,
"expires_in":953343434,
"scope": "asdfasd234234234asfasdfasdfaflalsdfkasjfa;sdfassdflj"
}
I need to get only the access_token value which is the bearer token from this curl JSON response and I need to pass as Authorization header to a different apigee gateway hosted api call.
curl -X GET https://apigee.mysite.com/getorderstatus -H "Authroization Bearer ???need to pass bearer token here ???"
How do I parse the JSON and get the bearer token as variable and pass it to the next API call?
I need to do this on the windows server. My environment is only limited to Windows. I can't install packages like jq due to security reason.
The recommended way to extract something from JSON is jq.
However, if you're really sure that the output is always like this, you might
at=$(curl -X POST https://api.mysite.com/oauth/token -u "login:password" | sed -n 's/[ ,"]//g;s/"access_token://p')
curl -X GET https://apigee.mysite.com/getorderstatus -H "$at"
A bash-only solution would be:
curl -X POST https://api.mysite.com/oauth/token -u "login:password" |
while read line ; do
if [[ "$line" == *access_token* ]] ; then
at=${line%\"*}
at=${at##*\"}
curl -X GET https://apigee.mysite.com/getorderstatus -H "$at"
fi
done
Note that, due to the subshell, at is not available outside the loop.

Sending POST Request from bash script

I want to execute a bash script after i make a POST request.So far i am using Postman for sending the request , but i was wondering if i can somehow do it from a bash script as well with a json file as parameter.
I have looked into curl so far but it does not work:
bash file
curl -X POST -d req.json http://localhost:9500
Json file (req.json)
{
"id":5,
"name":"Dan",
"age":33,
"cnp":33,
"children":100,
"isMarried":0
}
I just get the error :
HTTP/1.0 503 Service Unavailable
with the trailing HTML
curl should do the job. This will send a normal POST request using the data in req.json as the body:
curl -X POST -H "Content-Type: application/json" -d #req.json http://localhost:9500
The elements you were missing are -H "Content-Type: application/json" and the # in the data flag. Without the -H flag as above curl will send a content type of application/x-www-form-urlencoded, which most applications won't accept if they expect JSON. The # in the -d flag informs curl that you are passing a file name; otherwise it uses the text itself (i.e. "req.json") as the data.

Watson API - Retrieve and Rank - Error uploading JSON

I'm following the tutorial at Retrieve and Rank - Get Started, and I'm at the following step:
Issue the following command to upload the cranfield_data.json data to the example_collection collection. Replace {username}, {password}, {solr_cluster_id}, and {/path_to_file} with your information:
$ curl -X POST -H "Content-Type: application/json" -u "{username}":"{password}" "https://gateway.watsonplatform.net/retrieve-and-rank/api/v1/solr_clusters/{solr_cluster_id}/solr/example_collection/update" --data-binary #{/path_to_file}/cranfield_data.json
I'm lobbing the request with the correct username and password, and correct cluster_id and path to the json, but I get the following error:
$ curl -X POST -H "Content-Type: application/json" -u "username":"password" "https://gateway.watsonplatform.net/retrieve-and-rank/api/v1/solr_clusters/cluster_id/solr/example_collection/update" --data-binary #forum_data/parsed_answers.json
Error: WRRCSH006: Error forwarding request [/solr/example_collection/update] for Solr cluster [sc5b47c5e3_bab3_4aff_a818_f0d786d6dece].
Turns out there were characters in the JSON causing it be malformed.
Just verify the JSON "parsed_answers.json", to check for all the punctuations i.e. ";","," to be correctly placed and as per the defined schema, and try to re-upload

Github returns "Problems parsing JSON" when trying to create repo using curl

I'm attempting to create a repo on github using curl. No matter how I attempt to format my JSON it always returns "Problems parsing JSON". Is there something I'm missing? Here is my statement:
curl --data '{"name":"newRepoName"}' -XPOST -u username:password http://giturl
Strange since it works for me. Are you using the correct GitHub API endpoint (/user/repos)?
curl --data '{"name":"testrepo"}' -X POST -u username https://api.github.com/user/repos
Try including your token or password like this
curl --data '{"name":"testrepo"}' \
-X POST -u username:$TOKEN \
https://api.github.com/user/repos

Create new gist with Github API v3 using curl

After fighting for quite some time for posting a private gist to Github using their API V3 I almost gave up. Almost. May be some one have also faced similar problem or know what might be the reasoning of the following behavior:
Right now the curl command looks like following:
curl -H "Authorization: bearer MY_AUTHORIZATION_TOKE" -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"public":false,"files":{"test.txt":{"content":"String file contents"}}}' https://api.github.com/gists
I also tried
curl -H "Authorization: bearer MY_AUTHORIZATION_TOKE" -X POST -d '{"public":false,"files":{"test.txt":{"content":"String file contents"}}}' https://api.github.com/gists
I am able to create gist without authorization token using exactly same data:
curl -X POST -d '{"public":true,"files":{"test.txt":{"content":"String file contents"}}}' https://api.github.com/gists
But in that case it will be anonymous
Same results if I am truing to post it as public
In any case Github returns me
HTTP/1.1 404 Not Found
{
"message": "Not Found"
}
I am pretty sure I am authorized, as curl -H "Authorization: bearer MY_AUTHORIZATION_TOKE" https://api.github.com/user returns me my user details.
Application scope is as:
https://github.com/login/oauth/authorize?client_id=...&scope=gist
So, it should have both read and write permission.
Your OAuth2 token doesn't appear to have the required gist scope.
If you run the curl commands with the -v argument you can see the scope sent to request (X-OAuth-Scopes header) and the scope required for the request (X-Accepted-OAuth-Scopes header) to successfully be performed using the token sent.
If you don't see gist listed in the X-OAuth-Scopes header value then that is your problem.