Using ADAL libs for java I managed to get Access,Refresh and ID Tokens using my office365 credentials.
Now my intention is using REST Web APIs, my intention is to create an entity, as a proof of concept. Based on my experience with other venders and REST APIs, once you have a valid token, you just add it as a Authorization header like:
Authorization=Bearer 709709JHKLJHKJLhHKHKJHKH...etc
Is something similar to this in Dynamic CRM 2016?
Here here is nice info about composing a POST http request, but I am missing the Authorization part... Any idea guys?
Here is a valid GET request to pull back accounts.
GET https://<CRM DOMAIN>.com/api/data/v8.1/accounts HTTP/1.1
Authorization: Bearer:<TOKEN GOES HERE>
Host: <CRM DOMAIN>.com
And here is a valid POST
POST https://<CRM DOMAIN>.com/api/data/v8.1/accounts HTTP/1.1
Content-Type: application/json; charset=utf-8
Accept: application/json
Authorization: Bearer:<TOKEN GOES HERE>
Host: <CRM DOMAIN>.com
Content-Length: 224
{
"name": "Sample Account",
"creditonhold": false,
"address1_latitude": 47.639583,
"description": "This is the description of the sample account",
"revenue": 5000000,
"accountcategorycode": 1
}
Related
I'm building a JAX-RS 2.0 API and I am trying to add Link headers.
links.add(Link.fromUri(firstUri.build()).rel("first").build());
Link.Builder last = Link.fromUri(lastUri.build()).rel("last");
links.add(last.build());
return Response
.ok(content)
.header("X-Total-Count", totalCount)
.links(links.toArray(new Link[] {}))
.build();
So what I get is this:
HTTP/1.1 200 OK
X-Total-Count: 224
Link: <entities?limit=15&offset=70>;rel="next"
Link: <entities?limit=15&offset=40>;rel="prev"
Link: <entities?limit=15&offset=0>;rel="first"
Link: <entities?limit=15&offset=210>;rel="last"
Content-Type: application/json
But what I want is this:
HTTP/1.1 200 OK
X-Total-Count: 224
Link: <entities?limit=15&offset=70>;rel="next",<entities?limit=15&offset=40>;rel="prev",<entities?limit=15&offset=0>;rel="first",<entities?limit=15&offset=210>;rel="last"
Content-Type: application/json
So, am I doing something wrong or is JAX-RS just not sane?
I am able to set content type using cxf library but I don't know how to set Authorization header. Whenever I set user name and password then it set Authorization header and encode whole value and add Basic. I don't want to do this. I want to add Authorization header with plain string which ever I provide. Please help me to solve out this problem.
AMPServices services = new AMPServices();
CoreXmlPort coreXmlPort = services.getAMPSoapService();
Client client = ClientProxy.getClient(coreXmlPort);
HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy=httpConduit.getClient();
String contentType=httpClientPolicy.getContentType();
contentType="application/soap+xml; type=vnd.iShip.AMP.SOAP; charset=UTF-8";
httpClientPolicy.setContentType(contentType);
AuthorizationPolicy authorizationPolicy = new AuthorizationPolicy();
authorizationPolicy.setUserName("username");
authorizationPolicy.setPassword("password");
httpConduit.setAuthorization(authorizationPolicy);
It generates following request xml.
POST https://api.iship.com/Root/Enterprises/Pitney%20Bowes/Progistics; HTTP/1.1
Content-Type: application/soap+xml; type=vnd.iShip.AMP.SOAP; charset=UTF-8
Accept: */*
Authorization: Basic aXNoaXAgcGIvd3NkZXZlbDowNzZhNjFjYTM5MDcxODAxODVjNWRkMjM2YTdkMzZhNGQ1ODg5OWFj
User-Agent: Apache CXF 3.1.0
Cache-Control: no-cache
Pragma: no-cache
Host: api.iship.com
Connection: keep-alive
Content-Length: 246
But I want this type of request
POST https://api.iship.com/Root/Enterprises/Pitney%20Bowes/Progistics; HTTP/1.1
Content-Type: application/soap+xml; type=vnd.iShip.AMP.SOAP; charset=UTF-8
Accept: */*
Authorization: username;password
User-Agent: Apache CXF 3.1.0
Cache-Control: no-cache
Pragma: no-cache
Host: api.iship.com
Connection: keep-alive
Content-Length: 246
But I was not able to do it. Please help me to solve out this problem.
Thanks,
Awadhendra
I think you are trying to call is a RestFul Service, so that's why the server side always response with a different content type than you expected (json instead of soap/xml). Is your url endpoint based on http protocol? If yes, do you need send additional parameters to this url?
The issue here is that the client you are using to interact with Webservice expecting XML based Soap Messages , while the service is serving JSON as a return media.
Either convert your client to use the JSON format and communicate using that, or alternatively use the XML based endpoint , consult with webservice provider for that.
I am doing this request:
POST request to
https://accounts.google.com/o/oauth2/token?
client_secret=xxxxx-x8U-tDOJbCPN3&
grant_type=authorization_code&
redirect_uri=[url]
client_id=xxxxxx-e4u1224f7uqjafv7m1lu2ek5ac01isi4.apps.googleusercontent.com&
code=xxxxxxlpdiZfd_LhYu167gK.QvJZYyoaoQAQ3oEBd8DOtNC9kGrnjwI
So, as doc says, i make that request with these headers:
"Accept-Encoding": "gzip"
"Content-Type": "application/x-www-form-urlencoded"
But when i do it i am getting a 400:
{"error":"invalid_request","error_description":"Required parameter is missing: grant_type"}
I have already solved this. The problem was that i was sending params in query string, and the correct way was sending them as x-www-form-urlencoded. So the correct request had to be like this:
POST /o/oauth2/token? HTTP/1.1
Host: accounts.google.com
Cache-Control: no-cache
Postman-Token: b38df5b3-b64f-338a-1374-220647ee05a0
Content-Type: application/x-www-form-urlencoded
client_secret=xxxxx-x8U-tDOJbCPN3%26&grant_type=authorization_code&redirect_uri=myredirecturi&client_id=xxxxxx-e4u1224f7uqjafv7m1lu2ek5ac01isi4.apps.googleusercontent.com&code=xxxxxxlpdiZfd_LhYu167gK.QvJZYyoaoQAQ3oEBd8DOtNC9kGrnjwI
Hope this helps
had a similar problem, but in my case it was postman leaving a stupid Content-Type:application/json in the header!
Hope this might avoid my struggling for someone having the same issue!
im using a generated axis client to consume a service that requires headers
when using SOAPUI, i add the headers and the request looks like this
POST https://fttoo/service/v3.2/SOAP HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: ""
Authorization: Bearer 123
Content-Length: 270
Host: my host
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
when trying to set the headers with code i'm doing the following
proxy = (SessionServiceImplServiceSoapBindingStub)locator.getSessionService();
proxy._setProperty("Authorization", "Bearer 123");
this is not working well and i get Error 401, when inspecting the proxy object i see that a property called cachedProperties has the value of {Authorization=Bearer 123}
I've also tried proxy._setProperty(HTTPConstants.HEADER_AUTHORIZATION, "Bearer 123");
and also inside the stub, in the _call object....
given the fact that axis 1 is very old i generated a new web client using CXF instead of Axis, this way i was able to use cxf api to place the headers
I need to get username and password from HttpServletRequest to process the basic authentication. What I have is CXF endpoint and the basic auth interceptor. The HttpServletRequest I get like this:
public void handleMessage(Message message)
throws Fault {
HttpServletRequest request = (HttpServletRequest) message.get(AbstractHTTPDestination.HTTP_REQUEST);
}
When I tried to debug the code and I see that:
request.getAuthType() is null
request.getRemoteUser() is null
The username and password I am sending with the request from Soap UI. So the question is how am I able to get the username and password from the request?
EDIT
Header looks like this:
POST http://localhost:8011/GradIrelandUserRegistration HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: ""
Authorization: Basic UGF1bGl1czpQYXVsaXVzMTIz
Content-Length: 3170
Host: localhost:8011
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
They say that Authorization is basic, but then why call request.getAuthType() is returning null?
I was able to figure it out my self. In Soap UI I needed to change the Authentication type to:
Preemptive
and then use:
AuthorizationPolicy policy = (AuthorizationPolicy) message.get(AuthorizationPolicy.class.getName());
From the policy object now I am able to get the username and password.
This may be helpful to you
.
I'm bit new in SOAP data parsing so, if not working then let me know brief problem.
.
Also Check this J-Query Plugin for parsing SOAP services with the database. check this Stack Overflow