JavaScript runtime error: [Messenger] Required property 'target' was not provided occurred - javascript

I am using the Developers API with an App I created in LinkedIn.
When I call this method to sign in.....
IN.UI.Authorize().params({ "scope": ["r_liteprofile", "r_emailaddress"] }).place()
a Window begins to open and I get this error message:
Unhandled exception at line 7, column 56783 in
http://platform.linkedin.com/in.js 0x800a139e - JavaScript runtime
error: [Messenger] Required property 'target' was not provided
occurred
I have completed LinkedIn's App Setup, but can't figure what could be causing this. My JavaScript code is below:
[script type="text/javascript" src="//platform.linkedin.com/in.js"]
api_key: 'xxxxx......xxxxx'
authorize: true
[/script]
function LinkedInSignIn() {
IN.UI.Authorize().params({ "scope": ["r_liteprofile", "r_emailaddress"] }).place();
IN.Event.on(IN, 'auth', getProfileData);
}
function getProfileData() { // Use the API call wrapper to request the member's basic profile data
IN.API.Profile("me").fields("id,firstName,lastName,email-address,picture-urls::(original),public-profile-url,location:(name)").result(function (me) {
var profile = me.values[0];
var id = profile.id;
alert(profile.firstName);
});
}

As it turned out, the reason this is not working is becuase LinkedIn discontinued it at the end of 2018. Contacting LinkIn's support wasn't much help either. They only said they do no support thier code library and referred my back here to StackOverflow.
For anyone having the same problem, the solutions is to use Oauth2, which is documented at:
https://learn.microsoft.com/en-us/linkedin/shared/authentication/authorization-code-flow?context=linkedin/context
Happy Coding!
Graham

Related

Using GIS (Google Identity Services) and API Subpackage (picker) without client package

I am currently replacing the gapi.oauth2 package, by using the TokenClient according to the guide and everything works fine.
global.google.accounts.oauth2
.initTokenClient({
client_id: CONFIG.google.clientId,
scope: 'https://www.googleapis.com/auth/drive.readonly',
ux_mode: 'popup',
callback(tokenResponse) {
if (tokenResponse && !tokenResponse.error) {
onSuccess(tokenResponse.access_token);
return;
}
onError(tokenResponse.error || 'google authentication failed');
},
})
.requestAccessToken({});
The only issue is that we are not using the gapi.client and would prefer avoiding loading that package as we are only using the token to show a picker by using google.picker.PickerBuilder.
Now after the initialization the GSI package tries to use gapi.client.setToken() which obviously fails as the package is not loaded.
[GSI_LOGGER-TOKEN_CLIENT]: Set token failed. Gapi.client.setToken undefined.
So now i could not find anything in the reference on how to prevent that call to happen, nor how to at least suppress the warning by not e.g hacking in a noop as a placeholder.
Does anyone know if there is any official way to deal with that ?
In my tests the access token is successfully returned to the callback handler.
It looks to be an incorrectly generated warning, annoying yes, but functionally you're okay. A later, official release should remove the warning with no action on your part required.
The new API of GIS (Google Identity Services) maybe remove the setToken of the gapi.
I had to fix it by the code.
gapi = {client: {setToken: function(){ return; }}};

Use Javascript to list all Twilio Messages

I am using the Twilio Node.js documentation here:
https://www.twilio.com/docs/api/rest/message#list-get-filters
I am simply trying to list all of the messages in the message log for an account. Following the example here:
var accountSid = 'your_sid';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);
client.messages.list(function(err, data) {
data.messages.forEach(function(message) {
console.log(message.body);
});
});
Instead I get an error back:
/home/ubuntu/workspace/twilio/app.js:9
data.messages.forEach(function(message) {
^
TypeError: Cannot read property 'forEach' of undefined
at /home/ubuntu/workspace/twilio/app.js:9:18
at /home/ubuntu/workspace/twilio/node_modules/q/q.js:1547:13
at Promise_done_fulfilled (/home/ubuntu/workspace/twilio/node_modules/q/q.js:835:31)
at Fulfilled_dispatch [as dispatch] (/home/ubuntu/workspace/twilio/node_modules/q/q.js:1229:9)
at Pending_become_eachMessage_task (/home/ubuntu/workspace/twilio/node_modules/q/q.js:1369:30)
at RawTask.call (/home/ubuntu/workspace/twilio/node_modules/asap/asap.js:40:19)
at flush (/home/ubuntu/workspace/twilio/node_modules/asap/raw.js:50:29)
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)
Note sure why it is not finding anything. I would simply like to print all messages in the message logs or from a specific phone number.
Twilio's documentation is no longer accurate for NodeJS, the correct way to pull up list of all messages is through the following:
client.messages.list(function(err, data) {
//notice we have removed 'messages'
data.forEach(function(message){
console.log(message.body);
});
});
Twilio developer evangelist here.
We recently released version 3 of our Node library. I believe you are still looking at the documentation for version 2. You can change this in the Twilio documentation by checking the top right of the code samples and selecting 3.x instead of 2.x.
The up to date documentation for version 3 suggests you use code like this:
client.messages.each((message) => console.log(message.body));
Let me know if that helps at all.

Google Sign In for Websites causing "Signature verification failed" with JWT PHP library

Google web sign in has driven me positively crazy...
I'm building a simple web application, and I'm trying to integrate Google's sign in feature into the website (https://developers.google.com/identity/sign-in/web/).
The JavaScript seemed to go fairly well, and the next step was to verify the id_token I was receiving with my backend server (again, against Google's recommendation: https://developers.google.com/identity/sign-in/web/backend-auth).
It's a PHP-based web application, and I've successfully installed the Google Client API library using composer: composer require google/apiclient, but when posting my id_token value to my PHP backend system I'm consistently receiving the following error:
Firebase\JWT\SignatureInvalidException
File: .\vendor\firebase\php-jwt\src\JWT.php:112
Message: Signature verification failed
Stack trace:
#0 .\vendor\google\apiclient\src\Google\AccessToken\Verify.php(103): Firebase\JWT\JWT::decode('eyJhbGciOiJSUzI...', '-----BEGIN PUBL...', Array)
#1 .\vendor\google\apiclient\src\Google\Client.php(712): Google_AccessToken_Verify->verifyIdToken('eyJhbGciOiJSUzI...', '10...')
I've also used the id_token value on Google's "tokeninfo" endpoint (https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=ABC123), and the id_token validates perfectly, so I'm sure it's not the id_token value that's wrong. It's also passing it perfectly via the POST variable to the PHP script, so I'm at a bit of a loss.
Here's my code:
Javascript:
<script src="https://apis.google.com/js/platform.js?onload=googleAppStart" async defer></script>
<script>
var googleAppStart = function(){gapi.load('auth2', initGoogleSignIn);};
var auth = false;
function initGoogleSignIn(){
auth = gapi.auth2.init({
client_id : 'client-id-is-here',
scope : 'profile'
});
auth.attachClickHandler(document.getElementById('my-button'));
auth.isSignedIn.listen(googleSignInChanged);
auth.currentUser.listen(googleCurrentUserChanged);
if (auth.isSignedIn.get() == true)
auth.signIn();
}
function googleSignInChanged(signed_in){}
function googleCurrentUserChanged(user){
var auth_response = user.getAuthResponse();
var id_token = auth_response.id_token;
if (id_token != undefined){
var url = '/verify-google-signin';
var params = {id_token: id_token};
jQuery.post(url, params, function(data){}, 'json');
}
}
</script>
...and my PHP catching the POST:
<?php
require_once '/vendor/autoload.php';
$credentials = array("client_id" => "client-id-is-here");
$client = new \Google_Client($credentials);
$data = $_POST;
if (isset($data['id_token'])) {
$id_token = trim($data['id_token']);
// Exception generated here...
$payload = $client->verifyIdToken($id_token);
}
?>
Thank you so much for taking the time to read this, and for any assistance! It's greatly appreciated!
I had the same issue today.
Easier if you just execute:
composer require firebase/php-jwt:4.0
Fortunately you can verify id_token without google library as described here https://developers.google.com/identity/sign-in/web/backend-auth#calling-the-tokeninfo-endpoint
if (isset($data['id_token'])) {
$id_token = trim($data['id_token']);
try {
$res = (new \GuzzleHttp\Client())->request('GET',
'https://www.googleapis.com/oauth2/v3/tokeninfo', [
'query' => ['id_token' => $id_token],
]);
$payload = json_decode($res->getBody()->getContents(), true);
//you still need to check that the aud claim contains one of your app's client IDs
if ($payload['aud'] != "client-id-is-here") {
throw new \Exception("App Isn't valid", 422);
}
} catch (RequestException $e) {
//IF token isn't valid you will be here
if ($e->hasResponse()) {
/** #var \GuzzleHttp\Psr7\Response $resp */
$resp = $e->getResponse();
$error = json_decode($resp->getBody()->getContents(), true)['error_description'];
throw new \Exception($error, $resp->getStatusCode());
}
}
}
If you have no exceptions then your token is valid
It is a problem with php-jwt. Latest version is not working with Google Api Client.
Try to use php-jwt version 4.
I put "firebase/php-jwt": "<5.0" in my composer.json file.
Worked as a charm!
This has been fixed in v2.2.1 of google/apiclient so make sure you are running this version or later if anyone else encounters this issue.
Related discussions here and here.
I've got problems with Google Sign-In backend authentication yesterday, using both google/apiclient 2.2.0 and 2.1.3.
tl;dr it was most likely malfunctions on the Google side or some obscure limits I'm unaware of (nothing in the Developer Console about that).
First, the "idToken" Google was giving me client-side was not a valid JWT: openssl_verify() was rejecting it in Firebase\JWT\JWT, throwing a Firebase\JWT\SignatureInvalidException. I followed your advice, installed google/apiclient 2.1.3 and this exception was not being throwed anymore but the resulting payload was null (so the idToken was still invalid).
A few hours later, I had experienced intermittent results with the apiclient 2.3.0: sometimes the token was invalidated by signature verification (and throwing the signature exception) and sometimes the token was cryptographically valid but the returned payload was null. Once in a while, the token was valid (!).
In the end, the backend authenticaton process was succeeding every time.
As I began experiencing these problems, I tried to fix it generating new OAuth2 keys, revert to a previous verions of my codebase (both server-side and client-side) that I knew was working, removed all browser data and tried to get the token on Cordova with the Sign In for Android. Nothing worked. Also no message in the Developer Console, no visible limits, no security e-mail.
If it's not a bug but a feature, the error handling is quite harsh :)
If you are not using Firebase (taken from https://github.com/googleapis/google-api-php-client)
rm -r vendor/google/apiclient-services
Add this to composer.json
"scripts": {
"post-update-cmd": "Google\\Task\\Composer::cleanup"
},
"extra": {
"google/apiclient-services": [
"Drive" ,
"... any other services here ...",
]
}
Finally
composer install
This will resolve the error message with the added benefit of drastically reducing installed packages. As noted, there are at least 200 API services for GAPI

Error when creating charge with Parse.com Stripe API

I'm trying to create a charge with a test account on stripe.
Here is my parse cloud function:
Parse.Cloud.define("charge", function(request, response) {
var Stripe = require('stripe');
Stripe.initialize('...');
Stripe.Charges.create({
amount: 1000,
currency: "usd",
customer: "..."
},{
success: function(httpResponse) {
response.success("Purchase made!");
},
error: function(httpResponse) {
response.error("Uh oh, something went wrong");
}
});
});
I've hard coded the customerID into the function just for testing.
When I call the function from my app, I get the following error:
TypeError: Object [object Object] has no method '_each'
at request (stripe.js:58:11)
at post (stripe.js:117:12)
at Object.module.exports.Charges.create (stripe.js:157:16)
at main.js:19:18 (Code: 141, Version: 1.6.2)
Can anyone help?
#user3707419 I get the same error when trying to add a customer. Comment out that line and instead add the following:
card: stripeToken //this is the token you generated
Also, if that doesn't work, you need to revert you parse cloud code version to 1.5.0 (you are probably running the latest version 1.6.0 which does not work. The way you do this is type the following into your console:
parse jssdk 1.5.0
All of my working code on version 1.5.0 is located at this post:
Complete working Stripe + Parse.com working code on version 1.5.0
We may have to revert back even further to get customer: customer.id working I'm not sure. Let me know if you figure a different solution out. Hope this helps.
For what it's worth, your code looks very similar to my cloud code that works. However, I do not have a semicolon after the first }). Just after the final one.
If that's not the error, then i'm not very sure how to interpret your errors because i cannot see the code at the mentioned lines. Best of luck
Just so you know the real reason: Parse removed underscore lib , stripe.js thats built into parse cloud code relied on it. Hence failure like this.
Parse 1.6.X no longer supports modules, they removed them from API doc as well.

Chromium error with SPDY when using Facebook JavaScript SDK

I develop a mobile application with HTML5 + Cordova (Phonegap) using Facebook Javascript SDK for iOs and Android.
I implement it like this :
FB.api(
{
method: 'fql.query',
query: 'SELECT uid, name, birthday_date FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())'
},
function(response) {
console.log(response);
// some code
});
It worked for several months on Android & iOs, until yesterday, on Android.
An error occurs when the call to the api is doing and the callback function is not called.
Here is the error from LogCat in eclipse :
02-26 12:27:10.526: W/chromium(22379):
external/chromium/net/spdy/spdy_session.cc:1246:
[0226/122710:WARNING:spdy_session.cc(1246)] Could not parse Spdy
Control Frame Header. 02-26 12:27:10.526: D/chromium(22379): Unknown
chromium error: -337 02-26 12:27:10.526: W/chromium(22379):
external/chromium/net/spdy/spdy_session.cc:1058:
[0226/122710:WARNING:spdy_session.cc(1058)] Received data frame for
invalid stream 1 02-26 12:27:10.526: W/chromium(22379):
external/chromium/net/spdy/spdy_session.cc:1058:
[0226/122710:WARNING:spdy_session.cc(1058)] Received data frame for
invalid stream 1
It seems to be an error of the android browser Chromium when calling query Facebook (which using the protocol spdy)
Anyone has an idea ?
Thank you !
Seeing the same thing!
/chromium( 1942): external/chromium/net/spdy/spdy_session.cc:1246: [0307/015242:WARNING:spdy_session.cc(1246)] Could not parse Spdy Control Frame Header.
W/chromium( 1942): external/chromium/net/spdy/spdy_session.cc:1058: [0307/015242:WARNING:spdy_session.cc(1058)] Received data frame for invalid stream 21
W/chromium( 1942): external/chromium/net/spdy/spdy_session.cc:1058: [0307/015242:WARNING:spdy_session.cc(1058)] Received data frame for invalid stream 21
D/chromium( 1942): Unknown chromium error: -337
Found news about FB implementing SPDY without much news:
http://zoompf.com/2013/03/facebook-adds-spdy-support
Surprised we're not seeing more issues around.
I have the same problem with the similar code under identical
circumstances, PhoneGap, Android
The solution is to switch to Graph
API. Using Graphi API the same call will be
FB.api('/me/friends', { fields: 'id, name, gender, username' }, function (response) { ... });
There are a number of caveats that might
not be applicable to you but were applicable to me
The fields named differently. “sex” is now “gender”, for example Graph API does not
have direct analog of is_app_user field. If you add it to the list
of fields, you’ll get an error. There is a workaround asking
specifically for the users who installed the app
There is paging
implemented in response. So the response is structured a bit
differently. If you used to pass the data for processing to
functions you shall pass not “response” but “response.data”, and
watch for “response.paging”, to see if there are more friends to add
by additional calls.

Categories