Using LinqToTwitter in Console App and getting AggregateException Error - linq-to-twitter

I'm trying to do a basic SingleUserAuthorizer call to twitter. I am getting this Exception when I try the User Linq request. Any ideas?
Exception thrown: 'System.AggregateException' in mscorlib.dll
var auth = new SingleUserAuthorizer
{
CredentialStore = new SingleUserInMemoryCredentialStore
{
ConsumerKey = twitterConsumerKey,
ConsumerSecret = twitterConsumerSecret,
OAuthToken = twitterAccessTokenSecret,
AccessToken = twitterAccessToken
}
};
//await auth.AuthorizeAsync();
var twitterCtx = new TwitterContext(auth);
User user =
(from tweet in twitterCtx.User
where tweet.Type == UserType.Show &&
tweet.ScreenName == member.screenName
select tweet)
.SingleOrDefault();

We resolved the issue via this discussion on GitHub:
https://github.com/JoeMayo/LinqToTwitter/issues/45

Related

SAML2 with Owin - unable to authenticate

I have sample WebForms application with Owin. Tried to do SAML2 authentication with Azure AD IdP. It works fine, user is registered in application and authenticated.
Now I need to use other IdP. So I changed my application and nothing.
Saml response contains success, so IdP authenticated me. But calling Context.GetOwinContext().Authentication.GetExternalLoginInfo() returns null.
I found some posts about "external cookie", but I don't think this is my problem, because Azure sample works fine. Switching to other IdP failed.
Only difference seems to be in SAML Xml format.
Azure returns as
<samlp:Response Destination="https://localhost:44390/Saml2/Acs"
ID="_5eaccd77-fa78-4f59-86d9-67049ef074ce" InResponseTo="id73419322f1cc440184f456548cee7d09"
IssueInstant="2018-12-21T15:00:58.248Z" Version="2.0"
xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol">
</samlp:Response>
but other IdP returns as
<saml2p:Response Destination="https://localhost:44390/Saml2/Acs"
ID="_9547020d571863ef02c1f6d3dc8d94d7" InResponseTo="id46574a117a254f06a272ec02769b1a3c"
IssueInstant="2018-12-21T14:31:54.505Z" Version="2.0"
xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol">
</saml2p:Response>
But namespaces should be ok.
So it must be something in SAML response? How can I find problem?
private static Saml2AuthenticationOptions CreateSaml2Options()
{
var spOptions = CreateSpOptions();
var saml2Options = new Saml2AuthenticationOptions(false)
{
SPOptions = spOptions
};
var idp = new IdentityProvider(new EntityId("XXX"), spOptions)
{
AllowUnsolicitedAuthnResponse = true,
Binding = Saml2BindingType.HttpPost,
SingleSignOnServiceUrl = new Uri("XXX")
};
saml2Options.IdentityProviders.Add(idp);
return saml2Options;
}
private static SPOptions CreateSpOptions()
{
const string language = "cs-cz";
var spOptions = new SPOptions
{
EntityId = new EntityId("app:vwg.skoda.nia"),
AuthenticateRequestSigningBehavior = SigningBehavior.Always,
ReturnUrl = new Uri("https://localhost:44390/Saml2/Acs")
};
var attributeConsumingService = new AttributeConsumingService
{
IsDefault = true,
ServiceNames = { new LocalizedName("Saml 2 Authentication", "en") }
};
attributeConsumingService.RequestedAttributes.Add(new RequestedAttribute("Minimal"));
spOptions.AttributeConsumingServices.Add(attributeConsumingService);
var certPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "/App_Data/XXX.pfx";
var cert = new X509Certificate2(certPath, "XXX");
spOptions.ServiceCertificates.Add(cert);
return spOptions;
}
Sustainsys.Saml2.Exceptions.InvalidSignatureException: The signature verified correctly with the key contained in the signature, but that key is not trusted.
This means that the signature is correct, but that you have not configured the signing key as trusted.
You need to add a certificate with the idp's public key to the IdentityProvider.SigningKeys collection.

Facebook Graph API private_replies returning error 10903 This user cant reply to this activity

I am attempting to write an App that sends a message with private_replies, but it always returns the following error:
{
message: '(#10903) This user cant reply to this activity',
type: 'OAuthException',
code: 10903,
fbtrace_id: 'HUzYz7nKBPV'
}
I have read a number of solutions, but none seem to be working for me, so I'm not sure if I've missed something or if the something on the Facebook API side has changed.
The App I am creating (currently based on a number of tutorials) waits for a user to mention a specific word in a comment on my page and will then send a message to the user via private_replies.
When I debug my Apps Page Access Token, I get this info:
Access Token Info
App ID 18**********164 : MTestChatBot
Type Page
Page ID 25**********999 : MTestPage
App-Scoped User ID
Learn More
10**********048 : <MY NAME>
User last installed this app via API N/A
Issued 1520423580 (on Wednesday)
Expires Never
Valid True
Origin Web
Scopes manage_pages, pages_show_list, read_page_mailboxes, pages_messaging, pages_messaging_phone_number, pages_messaging_subscriptions, public_profile
One of the 'solutions' I have read states that I need to have to App reviewed by Facebook first to get the read_page_mailboxes subscription, but as shown above, I should already have that permission. It also seems odd to get an App reviewed before I can test it.
I have tried giving a friend developer access to the App and Admin rights to the page. When they post comments I get the same error.
I have tried Publishing the page and all comments still get the same result.
In case it's of any use, here is a rough version of the App code:
'use strict';
const FB_PAGE_ACCESS_TOKEN = process.env.FB_PAGE_ACCESS_TOKEN;
const FB_VERIFY_TOKEN = process.env.FB_VERIFY_TOKEN;
const request = require('request');
const express = require('express');
const body_parser = require('body-parser');
const app = express().use(body_parser.json());
app.listen(process.env.PORT);
app.get('/webhook', (req, res) => {
// Parse params from the webhook verification request
let mode = req.query['hub.mode'];
let token = req.query['hub.verify_token'];
let challenge = req.query['hub.challenge'];
// Check if a token and mode were sent
if (mode && token) {
// Check the mode and token sent are correct
if (mode === 'subscribe' && token === FB_VERIFY_TOKEN) {
// Respond with 200 OK and challenge token from the request
console.log('WEBHOOK_VERIFIED');
res.status(200).send(challenge);
} else {
// Responds with '403 Forbidden' if verify tokens do not match
res.sendStatus(403);
}
}
});
app.post('/webhook', (req, res) => {
// Parse the request body from the POST
let data = req.body;
if (data.object === 'page') {
data.entry.forEach(function(pageEntry) {
var pageID = pageEntry.id;
var timeOfEvent = pageEntry.time;
if (pageEntry.hasOwnProperty('changes')) {
pageEntry.changes.forEach(function(changes){
if(changes.field === 'feed' && changes.value.item === 'comment' && changes.value.verb === 'add'){
var messageData = {
message: 'Hello'
};
privateReply(messageData, changes.value.comment_id);
}
});
}
});
}
})
function privateReply(messageData, comment_id) {
request({
uri: 'https://graph.facebook.com/v2.12/' + comment_id + '/private_replies',
qs: { access_token: FB_PAGE_ACCESS_TOKEN },
method: 'POST',
json: messageData
}, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
} else {
console.error('Private Replies Failed: ', response.statusCode, response.statusMessage, body.error);
}
});
}
All advice gratefully received.

Firebase signInwithRedirect() always goes to localhost instead of my App

CONTEXT
I'm working on Xcode (ios app) on an angularJS/ionic app, trying to use Firebase auth functions to login using Facebook.
To do that i'm using signInWithRedirect() and getRedirectResult(), it seems working until my code gets to getRedirectResult(), no errors shown but after access acceptance facebook is redirecting me on Safari to : localhost:8080/var/containers/Bundle/Application/******/testApp.app/www/index.html#/login instead of my app login page.
I setup the facebook app on the Developper Facebook website and set https://testApp-32338.firebaseapp.com/__/auth/handler into OAuth URI field.
QUESTION
Is there a file in Xcode or somewhere (.XML or something), where i must write something about this redirect ? How to use Facebook to sign in my ionic/ios app ?
Here is my code :
//********** EDIT 1 CODE **********//
function loginFacebook ()
{
var provider = new firebase.auth.FacebookAuthProvider();
provider.addScope('user_birthday, email, public_profile');
firebase.auth().signInWithRedirect(provider);
// The only console.log() i can see in the console
console.log("0");
firebase.auth().getRedirectResult().then(function(result) {
console.log("1");
if (result.credential) {
console.log("2");
var user = result.user;
// This gives you a Facebook Access Token. You can use it to access the Facebook API.
var token = result.credential.accessToken;
console.log("3");
}
// The signed-in user info.
var user = result.user;
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
});
}
Edit 1 : (02/11/2018)
According to Firebase it seems to be a known problem, probably wkwebview is the main cause of this issue on an IOS/ionic app. In this link : https://ionicframework.com/docs/wkwebview/ ionic is speaking about "Cross-Origin Resource Sharing" (CORS), I'm really not familiar with this how could i "trap" the signInWithRedirect() result to change it to the required url ? Is this will fix my problem ? Is someone was already able to cope with this issue ?
Edit 2 : (02/12/2018)
Trying a new method, using the cordova-facebook4-plugin, everything seems working, even the redirect part to my app and collecting datas (name, birthday, token...etc). The unknown part is how to link my results to the firebase auth provider ? In Firebase doc (https://firebase.google.com/docs/auth/web/facebook-login) the method is to use signInWithRedirect() (see my first edit) or signInWithPopUp() (which is not working on phone app), there is a signInWithCustomToken(), but it doesn't work when i'm putting inside the Facebook given token. I also tried the universal-links method with unfortunately, same results. How do you guys would do this ? Is someone achieved the connexion between cordova-facebook4-plugin and Firebase ?
//********** EDIT 2 CODE **********//
function loginFacebook()
{
var fbLoginSuccess = function (userData) {
console.log("UserInfo: " + JSON.stringify(userData));
facebookConnectPlugin.getAccessToken(function(token) {
console.log("Token: " + token);
// What to do with this Token to link to Firebase ???
});
}
facebookConnectPlugin.login(["public_profile", "user_birthday"], fbLoginSuccess,
function (error) {
console.error(error)
}
);
}
Edit 3 : (02/14/2018) It's Working !!!
Finally is it working, thanks a lot to #mootrichard ! Here is my final working code :
//********** EDIT 3 CODE FINAL **********//
// SIGNIN WITH FACEBOOK4
function loginFacebook()
{
var provider = new firebase.auth.FacebookAuthProvider();
var fbLoginSuccess = function (userData) {
console.log("UserInfo: " + JSON.stringify(userData));
facebookConnectPlugin.getAccessToken(function(token) {
console.log("Token: " + token);
connectProvider(token);
});
}
facebookConnectPlugin.login(["public_profile", "user_birthday"], fbLoginSuccess,
function (error) {
console.error(error)
}
);
//CONNECT FACEBOOK TO THE FIREBASE PROVIDER
function connectProvider(access_token)
{
// Build Firebase credential with the Facebook access token.
var credential = firebase.auth.FacebookAuthProvider.credential(access_token);
// Sign in with credential from the Google user.
firebase.auth().signInWithCredential(credential).then(function(result) {
var firstName = result.displayName.split(' ').slice(0, -1).join(' ');
var lastName = result.displayName.split(' ').slice(-1).join(' ');
console.log("The firstName is : ", JSON.stringify(firstName));
console.log("The lastName is : ", JSON.stringify(lastName));
$state.go("anOtherPage");
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
});
}
I think you want to look at one of Firebase's advanced guides. Since you already have your token, you can simply create the Facebook Credentials using:
// Build Firebase credential with the Facebook access token.
var credential = firebase.auth.FacebookAuthProvider.credential(access_token);
// Sign in with credential from the Google user.
firebase.auth().signInWithCredential(credential).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
// ...
});
You can see their example at https://firebase.google.com/docs/auth/web/facebook-login#advanced-authenticate-with-firebase-in-nodejs.

Firebase facebook signInWithRedirect not redirecting to specified page on login success

I am using Firebase's facebook signInWithRedirect but can't figure out why my application won't navigate to the specific page on redirect and instead it just returns back to the home page. I followed the steps on https://firebase.google.com/docs/auth/web/facebook-login and believe I have setup everything correctly. Below is my login code:
$("#login").click(function() {
firebase.auth().signInWithRedirect(provider);
}
});
firebase.auth().getRedirectResult().then(function(result) {
if (result.credential) {
var token = result.credential.accessToken;
var user_data = result.user.providerData[0];
currentUid = user_data.uid;
var usersRef = firebase.database().ref().child('users');
usersRef.child(currentUid).once('value', function(snapshot) {
if (snapshot.val() !== null && snapshot.val().Phone !== undefined) {
localStorage.setItem("UID", currentUid);
localStorage.setItem("Name", user_data.displayName);
window.location = "/zones"; //Navigate to this route
} else {
var userDataJson = {
"Name": user_data.displayName,
"Email": user_data.email,
"Phone": user_data.phoneNumber
};
var childRef = usersRef.child(currentUid)
childRef.set(userDataJson).then(snap => {
localStorage.setItem("UID", currentUid);
localStorage.setItem("Name", user_data.displayName);
window.location = "/profile" ; //or Navigate to this route
});
}
});
}
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
console.log(errorMessage);
var email = error.email;
var credential = error.credential;;
});
In Firebase console I have the following domains listed in Authorized Domains:
1. localhost
2. my firebase oauth domain
3. my site domain that I'll be hosting the app on
In the Facebook dev console I have listed the following in Valid OAuth redirect URIs:
1.https://myblahblah.firebaseapp.com/__/auth/handler
2.https://mydomain/profile
3.https://mydomain/zones
What am I doing wrong here, been trying to figure this out for hours!!

After removing autopublish, how do I read Meter.user().services?

Before I removed the autopublish package from my project meteor remove autopublish,
I was able to read in the oAuth services that the logged in user was using, e.g. var facebookSignIn = Meteor.user().services.facebook; or
var googleSignIn = Meteor.user().services.google;
The reason this is important, is because I would use this googleSignIn or facebookSignIn information to determine how to save the logged-in users personal details, such as their: name, email, and profile picture. In code:
var facebookSignIn = Meteor.user().services.facebook;
var googleSignIn = Meteor.user().services.google;
var ownderId = Meteor.user()._id;
if (facebookSignIn) {
console.log("Its a Facebook Account Sign in!");
var userName = Meteor.user().services.facebook.name;
var emailAdress = Meteor.user().services.facebook.email;
var facebookProfilePic = "http://graph.facebook.com/" + user.services.facebook.id + "/picture/?type=large";
}
else if (googleSignIn) {
console.log("Its a Google Account Sign in!");
var userName = Meteor.user().services.google.name;
var emailAdress = Meteor.user().services.google.email;
var googleProfilePic = Meteor.user().services.google.picture;
}
else {
console.log("Your not Signed in!");
}
How do I retrieve Meteor.user().services.facebook and Meteor.user().services.google now that I have removed the autopublish package?
In the browser console (main.js:1140), this error message appears:
Uncaught TypeError: Cannot read property 'facebook' of undefined
The code in on main.js: 1140 is:
var facebookSignIn = Meteor.user().services.facebook;
You'll have to first publish the collection from the server, in order for the collection to be made available in the client (which in turn must subscribe to the published collection)
Meteor.publish("userPublication", function publishFunction(){
return Meteor.users.find(); })

Resources