LinkedIn API 401 Unauthorised when using Field Selectors - c#

I am attempting to get specific information from the user's profile via the LinkedIn API.
The URL I am using for the GET call is the following:
http://api.linkedin.com/v1/people/~:(id,first-name,last-name,industry,headline,public-profile-url)
When attempting this I get a "401 Unauthorized" response from the server. However, when I do a GET to http://api.linkedin.com/v1/people/~ within the same function with the same auth keys, etc. it works just fine.
The error presented in the response is as follows:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<error>
<status>401</status>
<timestamp>1316082986700</timestamp>
<request-id>SVWTG5ARQM</request-id>
<error-code>0</error-code>
<message>[unauthorized].</message>
</error>
Any ideas of why this might be happening? Anything would be greatly appreciated.

It is likely your OAuth library is buggy. Can you view the full request and response?
I would make sure your Authorization / OAuth header has the same signature as the one generated from this tool:
https://developer.linkedin.com/oauth-test-console
If not, you'll need to get a new library, update/fix your library, etc.
If yes, then that is weird. Come back and we'll go from there :)

Related

OcppV1.5 over Soap Error: Action does not exist

i am currently building a Client to communicate with a Gateway of a Charge Point.
The communication is build with OcppV1.5 over Soap & Http.
The Server doesn't accept my request. I get a Http Response 500 with the Error Reason:
"XML Request is not well formed, Action does not exist."
I looked into the wsdl files but I just don't understand why it doesn't accept my action.
My Request looks something like this:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:wsa="https://www.w3.org/2005/08/addressing" xmlns:cs="urn://Ocpp/Cp/2012/06/">
<SOAP-ENV:Header>
<cs:chargeBoxIdentity>0000.0000</cs:chargeBoxIdentity>
<wsa:From>
<wsa:Address>http://000.000.000.000:0000</wsa:Address>
</wsa:From>
<wsa:To>http://000.000.000.001:0001</wsa:To>
<wsa:Action>/ChangeConfiguration</wsa:Action>
<wsa:MessageID>00000.000000000000</wsa:MessageID>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<cs:changeConfigurationRequest>
<cs:key>MeterValueSampleInterval</cs:key>
<cs:value>60</cs:value>
</cs:changeConfigurationRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Update:
As Bogdan suggested I tried to send the same message using SoapUi and it worked. The generated Request from SoapUi looks like this:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ns="urn://Ocpp/Cp/2012/06/">
<soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<ns:chargeBoxIdentity>000000.00000</ns:chargeBoxIdentity>
<wsa:Action>/ChangeConfiguration</wsa:Action>
<wsa:ReplyTo>
<wsa:Address>http://000.000.000.000:0000</wsa:Address>
</wsa:ReplyTo>
<wsa:MessageID>uuid:00000000-0000-0000-0000-000000000000</wsa:MessageID>
<wsa:To>http://000.000.000.000:00000/</wsa:To>
</soap:Header>
<soap:Body>
<ns:changeConfigurationRequest>
<ns:key>MeterValueSampleInterval</ns:key>
<ns:value>300</ns:value>
</ns:changeConfigurationRequest>
</soap:Body>
</soap:Envelope>
It's hard to tell from what you posted why you are getting an error, so I can only add some information that can hopefully allow you to troubleshoot the issue.
Your message has WS-Addressing headers, <wsa:Action> being one of them. The value of this field should be specified in the WSDL if your WSDL also includes WS-Addressing Metadata information, or should be specified in the documentation of the web service you are invoking. Your error message "XML Request is not well formed, Action does not exist" seems to indicate that there might be an issue with this field, but there is another action that SOAP services have which is a SOAP action. I asked about it in the comment above to make sure it's eliminated as a source of problems. In SOAP 1.1 it's called SOAPAction and is a separate HTTP header, while in SOAP 1.2 it's an action parameter on the HTTP Content-Type header. Based on the http://www.w3.org/2003/05/soap-envelope namespace, you have a SOAP 1.2 message.
With these explanations layed out, I suggest you take the WSDL and feed it to SoapUI who can generate sample requests that you can use to invoke the web service. If the WSDL also contains WS-Addressing Metadata, SoapUI should be able to pick it up and help you fill in the values you need. If not, look again through the WSDL for Action elements (make sure you differentiate between the SOAP Action and the WS-Addressing Action using their XML namespaces) or through the service documentation.
Once you get a succesfull call using SoapUI, then try to duplicate it with your code. At that point you can again use SoapUI to troubleshoot things and inspect your code built message to see it resembles the one you can successfully send with SoapUI.
Hope this helps get you closer to a resolution.

The OAuth2 authentication request process of Office 365 forwards the link to https://login.microsoftonline.com/login.srf

Currently, I am developing my web app to use Rest API of Office365. In order to do that, for the OAuth2 authentication and authorization, I follow the step in this article:
https://blogs.msdn.microsoft.com/exchangedev/2014/03/25/using-oauth2-to-access-calendar-contact-and-mail-api-in-office-365-exchange-online/
However, I am stuck on the second step, which the first sign in attempt on windows page. Here is the full link that I use for the OAuth2 process:
"https://login.windows.net/common/oauth2/authorize?client_id=[ClientId]&redirect_uri=http://localhost/MicrosoftAuthDemo/MicrosoftCallBack.ashx&response_type=code&resource=https://outlook.office365.com/&state=c9833f87-892a-4f94-9234-2de9832d1f49"
After I have done the login, instead of showing the consent page and redirecting the URL back to my web: http://localhost/MicrosoftAuthDemo/MicrosoftCallBack.ashx, it forwards the URL to https://login.microsoftonline.com/login.srf, which I have no idea what it is.
That login.srf link shows this page:
Out of the blue, it asks for login again. However, when I try to login again, it forwards me to the same link again: https://login.microsoftonline.com/login.srf.
Does anyone know what's the source of the problem?
In case anyone wants to know my app registration setting in Azure portal:
Register settings
Properties
Secret key
Replay URLs
To do authorization of O365 and use REST API, here is a solution for your reference:
First: get security Token
Access [https://login.microsoftonline.com/extSTS.srf] via Http Post method. The content of the http request is as follows.
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:a="http://www.w3.org/2005/08/addressing"
xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue</a:Action>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<a:To s:mustUnderstand="1">https://login.microsoftonline.com/extSTS.srf</a:To>
<o:Security s:mustUnderstand="1"
xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<o:UsernameToken>
<o:Username>[username]</o:Username>
<o:Password>[password]</o:Password>
</o:UsernameToken>
</o:Security>
</s:Header>
<s:Body>
<t:RequestSecurityToken xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust">
<wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
<a:EndpointReference>
<a:Address>[endpoint]</a:Address>
</a:EndpointReference>
</wsp:AppliesTo>
<t:KeyType>http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKey</t:KeyType>
<t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType>
<t:TokenType>urn:oasis:names:tc:SAML:1.0:assertion</t:TokenType>
</t:RequestSecurityToken>
</s:Body>
</s:Envelope>
The demonstration screenshot in Postman:
And the response content will include a security token as below, we can use this security token and related REST API to get Access Token of your O365 application, like SharePoint, Outlook, etc.
Second: get Access Token
Here i show you how to get access token of SharePoint online using the security token and SharePoint Rest API.
As long as you use the corresponding REST API, it is also used in other O365 applications.
Access [https://yourdomain.sharepoint.com/_forms/default.aspx?wa=wsignin1.0] via http Post method. The content of the request is the security token that we have got above as below.
And the response as below:
We can see that there are two cookie, rtFa and FedAuth in response header, and these two cookie need to be added to the request in subsequent request.
Third: get Request Digest
Access [https://yourdomain.sharepoint.com/_api/contextinfo] via http Post method with that two cookies which we have got above.
And the response as below:
This is the final Token we want!
Then we can use REST API of SharePoint, we only need to add this token and the previous two cookie, as shown in the following figure.
It seems like the article where I followed is already old (posted in 2014) and doesn't work anymore.
Finally, I have fixed the problem by following the steps in this article: https://developer.microsoft.com/en-us/graph/docs/concepts/auth_v2_user
Here I would explain briefly what I have changed:
First, for registering the app, instead of using https://portal.azure.com, I registered my app via https://apps.dev.microsoft.com/. Somehow, they are different.
Second, I change the full link that I use for the OAuth2 process into:
https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize?
client_id=[Client ID]
&response_type=code
&redirect_uri=[your web app link after finishing login]
&response_mode=query
&scope=[scope of your app]
Parameters explanation:

How to get the soap request going out with the call using wsdl c#?

Very new to this. I am using a wsdl. Generating the web reference and .net builds the classes in references.cs. Now is there any way I can get the soap request going out though any c# methods in my code?
Getting at System.Xml.Serialization.XmlSerializer.Serialize error in prod but absolutely working fine in UAT. No body has no clue on why? Can someone pls provide insights on getting the soap request going out ?
You can use tool fiddler to track the request and responce

Getting error :(The remote server returned an error: (401) Unauthorized) when trying to call http://twitter.com/account/verify_credentials.xml

I'm following this Url to authenticate user to my website using twitter login. I'm able to get the access token but when im calling below code
url = "http://twitter.com/account/verify_credentials.json";
xml = oAuth.oAuthWebRequest(oAuthTwitter.Method.GET, url, String.Empty);
im getting 401 unauthorized error. Can anyone guide me what can be the problem
I am not an expert on the Twitter API's but here is a post in the dev.twitter forums that seem to be very similar to what you are experiencing.
https://dev.twitter.com/discussions/1750
Your URL is wrong. It is https://api.twitter.com/1.1/account/verify_credentials.json (or https://api.twitter.com/1/account/verify_credentials.json depending of the version of the Twitter API (1 or 1.1) you use). Twitter recently removed endpoints whose domain name is not api.twitter.com and endpoints without the version of the API : https://dev.twitter.com/discussions/10803
If it is still wrong, ensure that you authorize your requests correctly : https://dev.twitter.com/docs/auth/authorizing-request
NB : Twitter will send you back JSON datas, not XML. You should write "json = oAuth.oAuthWebRequest(oAuthTwitter.Method.GET, url, String.Empty);" instead of "xml = oAuth.oAuthWebRequest(oAuthTwitter.Method.GET, url, String.Empty);" in your code. If you want XML datas, use this URL : https://api.twitter.com/1/account/verify_credentials.xml. But this last will not work after March 2013.

LinkedIn API "Company Follow" how to Start follow a company

Everyone,
I am implementing Linkedin API now. Most API request works fine. But I had met a problem for "Start Follow a company":
POST
http://api.linkedin.com/v1/people/~/following/companies
This is the request sample LinkedIn give, but there is no place to put id parameter, how to tell LinkedIn that which company I want to follow ?
I tried to use the similar one with Stop following, but it didnt work...
DELETE
http://api.linkedin.com/v1/people/~/following/companies/id={id}
Is any one know how to use it ?
Thank you.
From the docs, to get a list of companies the current user is following, you do:
GET
http://api.linkedin.com/v1/people/~/following/companies
To start following a company, you do:
POST
http://api.linkedin.com/v1/people/~/following/companies
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<company>
<id>{id}</id>
</company>
To stop following you have it correct:
DELETE
http://api.linkedin.com/v1/people/~/following/companies/id={id}
You can play around with these on the REST Console to get familiar with them.

Categories