waterlock fb auth - registering with authcode - node.js

I have an ember-cli app that authenticates against fb using ember-simple-auth and torii. When the process is finished I end up with an authcode.
I also have an API built with Node / Sails / Waterlock
I thought I would be able to use Waterlock facebook auth to push this code to
http://my-node-app.com:1337/auth/facebook_oauth2?code={{some-code}}
which would then allow it to do the handshake with FB, fetch my profile info, create my user and log me in.
This works I think if I have already registered though the API, and it does log me in on the API except that there is no user data, no fb id nothing.
The response from calling the URL above with a valid code is:
{
auth: {
facebookId: null,
name: null,
createdAt: "2015-01-10T15:05:44.417Z",
updatedAt: "2015-01-10T15:05:44.459Z",
id: 10,
user: 10
},
createdAt: "2015-01-10T15:05:44.447Z",
updatedAt: "2015-01-10T15:05:44.447Z",
id: 10
}
And here is the result of /users
{
users: [
{
attempts: [
12
],
jsonWebTokens: [ ],
auth: 10,
createdAt: "2015-01-10T15:05:44.447Z",
updatedAt: "2015-01-10T15:05:44.447Z",
id: 10
}
]
}
Should I be able to do this? Or do I need to explicitly register users on the api/auth/login?type=facebook url?
[UPDATE]
Looking at the code here https://github.com/waterlock/waterlock-facebook-auth/blob/master/lib/controllers/actions/oauth2.js it looks like I am correct...
The 1st call in the action is:
fb.confirmIdentity(req.query.code, accessTokenResponse);
Inside accessTokenResponse it calls into fb.getMe(userInfoResponse); where in userInfoResponse it calls into the main waterlock framework engine.js to store the user...
So from my digging this should work... I have no idea where it is falling down.

This was working as expected it's just waterlock wasn't returning the fb error passed to it (). I created a pull request so it's easier to debug these sorts of issues.
https://github.com/waterlock/waterlock-facebook-auth/pull/3

Related

How to convert my Wordpress website to flutter application?

I am a college student and during my intern my client gave me this project to convert his wordpress website into a mobile application while including existing features as well as some new features. The website is news website. I am also provided with wordpress admin panel credentials.
However, I am having hardtime fetching all data of website in json form. I tried using the wordpress api url: "https://example.com/wp-json/wp/v2/posts" as well as
"https://example.com/wp-json/wp/v2/posts?perpage=100" and
"https://example.com/wp-json/wp/v2/posts/?filter[limit]=100"
but none of them provided with whole data, it only rendered 10 latest news posts.
I am looking to get whole access to the website data myself. Is there any possible way for that? I want comments from the users on that news post, number of shares, likes, the related news section below post, everything.
Do I have to ask for the organization's main api or is there any other way? I am fluent in flutter and node js.
Flutter WordPress
Flutter WordPress is a library that allows for easy communication between a Flutter app and the WordPress backend. It uses WordPress REST API v2 for this interaction.
If your app is going to make use of authentication or other admin level APIs then the developer recommends you use these two authenthentication wordpress plugins:
Application Passwords
JWT Authentication for WP REST API (recommended)
How to use Flutter WordPress
1.Go to your pubspec.yaml then add the following as a dependency:
flutter_wordpress: ^0.1.4
You can check for the latest version here.
2.Import it in your code:
import 'package:flutter_wordpress/flutter_wordpress.dart' as wp;
3.You instantiate WordPress:
wp.WordPress wordPress;
// adminName and adminKey is needed only for admin level APIs
wordPress = wp.WordPress(
baseUrl: 'http://localhost',
authenticator: wp.WordPressAuthenticator.JWT,
adminName: '',
adminKey: '',
);
4.You then authenticate the user:
Future<wp.User> response = wordPress.authenticateUser(
username: 'ChiefEditor',
password: 'chiefeditor#123',
);
response.then((user) {
createPost(user);
}).catchError((err) {
print('Failed to fetch user: $err');
});
5.Here's how you can fetch wordpress posts and show them in your flutter app:
Future<List<wp.Post>> posts = wordPress.fetchPosts(
params: wp.ParamsPostList(
context: wp.WordPressContext.view,
pageNum: 1,
perPage: 20,
order: wp.Order.desc,
orderBy: wp.PostsOrderBy.date,
),
fetchAuthor: true,
fetchFeaturedMedia: true,
fetchComments: true,
);
6.And here's how you can fetch users:
Future<List<wp.User>> users = wordPress.fetchUsers(
params: wp.ParamsUserList(
context: wp.WordPressContext.view,
pageNum: 1,
perPage: 30,
order: wp.Order.asc,
orderBy: wp.UsersOrderBy.name,
role: wp.UserRole.subscriber,
),
);
7.And here's how to fetch comments:
Future<List<wp.Comment>> comments = wordPress.fetchComments(
params: wp.ParamsCommentList(
context: wp.WordPressContext.view,
pageNum: 1,
perPage: 30,
includePostIDs: [1],
),
);
8.Then creating a wordpress post via flutter is easy:
void createPost(wp.User user) {
final post = wordPress.createPost(
post: new wp.Post(
title: 'First post as a Chief Editor',
content: 'Blah! blah! blah!',
excerpt: 'Discussion about blah!',
author: user.id,
commentStatus: wp.PostCommentStatus.open,
pingStatus: wp.PostPingStatus.closed,
status: wp.PostPageStatus.publish,
format: wp.PostFormat.standard,
sticky: true,
),
);
post.then((p) {
print('Post created successfully with ID: ${p.id}');
postComment(user, p);
}).catchError((err) {
print('Failed to create post: $err');
});
}
Then to post a comment:
void postComment(wp.User user, wp.Post post) {
final comment = wordPress.createComment(
comment: new wp.Comment(
author: user.id,
post: post.id,
content: "First!",
parent: 0,
),
);
comment.then((c) {
print('Comment successfully posted with ID: ${c.id}');
}).catchError((err) {
print('Failed to comment: $err');
});
}
Download full example here.

Stripe warning - Unrecognized token creation parameter

I'm just starting with stripe, and I noticed I get a warning in chrome saying:
Unrecognized token creation parameter parameter: company is not a
recognized parameter. This may cause issues with your integration in
the future.
This is the code.
stripe.createToken("account", {
company: {
name: "bbb",
address: {
line1: "77",
city: "abc",
state: "aa",
postal_code: "e2e"
}
},
tos_shown_and_accepted: true
}).then(function(result) {
debugger;
console.log(result);
});
I'm pretty much following the docs here (step 2)
https://stripe.com/docs/connect/account-tokens
It creates a token OK though.
The docs in the API reference suggest company is an object it should know:
https://stripe.com/docs/api/tokens/create_account
It basically tells you what is wrong.
It says that company is not a parameter that is recognized by that stripe endpoint. It creates the token, but ignores your passed parameter

I'm trying to make sense of session, but cannot get any data out of it

Currently using LUIS in a bot that connects to Slack. Right now I'm using interactive messages and trying to respond to user input correctly. When I click an item from the drop down LUIS receives it as a message. I can get the text with session.message.text, however I need to get the callback_id of the attachment as well as the channel it was sent from.
I've used console.log(session) to get an idea of what session looks like. From there I've seen that session.message.sourceEvent contains the data I need, however I can't use indexOf() or contains() to actual extrapolate the data. I've also tried session.message.sourceEvent.Payload but end up getting "[object [Object]]". I've tried searching for documentation on session formatting but to no avail.
Below is a snippet of what is returned when I run console.log(session.message.sourceEvent).
{ Payload:
action_ts: '1513199773.200354',
is_app_unfurl: false,
subtype: 'bot_message',
team: { id: 'T03QR2PHH', domain: 'americanairlines' },
user: { id: 'U6DT58F2T', name: 'john.cerreta' },
message_ts: '1513199760.000073',
attachment_id: '1',
ts: '1513199760.000073' },
actions: [ [Object] ],
callback_id: 'map_selection1',
original_message:
username: 'Rallybot',
response_url: 'https://hooks.slack.com/actions/T03QR2PHH/287444348935/Y6Yye3ijlC6xfmn8qjMK4ttB',
type: 'message',
{ type: 'interactive_message',
channel: { id: 'G6NN0DT88', name: 'privategroup' },
token: 'removed for security',
{ text: 'Please choose the Rally and Slack team you would like to map below.',
bot_id: 'B7WDX03UM',
attachments: [Array],
trigger_id: '285857445393.3841091595.085028141d2b8190b38f1bf0ca47dd88' },
ApiToken: 'removed for security' }
session.message.sourceEvent is a javascript Object, however indexOf or contains are functions of String or Array types.
Any info you required in the object, you should direct use the code <object>.<key> to invoke that value. You can try session.message.sourceEvent.Payload.action_ts for example.
Also, you can use Object.keys(session.message.sourceEvent) to get all the keys in this object.

Loopback: Cannot call Notification.create(). The create method has not been setup. The PersistedModel has not been correctly attached to a DataSource

I am using Loopback and the push component. When calling Notification.create() I get the error:
Cannot call Notification.create(). The create method has not been setup.
The PersistedModel has not been correctly attached to a DataSource!
I'm just running the basic example server 2.0. In code I am trying to create a Notification. What's the problem?
I too got the same problem when trying to use login function of User model.
Got it fixed after an hour of hit and trial.
Answer: I extended User model to MyUser model (No coding inside this model, just used it as a wrapper) and inside Hotel.js (in my case a business class where i use to authenticate user before accessing hotel details) created a remoteMethod for login
code:
Hotel.auth=function(uname,pwd, cb)
{
Hotel.app.models.MyUser.login({username: uname, password: pwd}, function (err, token) {
if(err)
cb(null,err);
else
cb(null,token);
});
}
Hotel.remoteMethod(
'auth',
{
accepts:
[
{arg: 'uname', type: 'string',required: true},
{arg: 'pwd', type: 'string',required: true}
],
returns: {arg: 'Response Message', type: 'string'}
}
);
This works!
This one is pretty old, but just to put something up here. Without seeing your setup my guess is that the model you are using is not connected to any data source, or one that is not written properly. The default connector is in-memory and does implement this method correctly. Check your server/model-config.json file and find the entry for Notification and check what you have for the data source.

Asana API POST to Tasks leads to Server Error

I'm using node.js and the api key for auth. All my get actions work, and I've been able to post a new project, but new tasks always return 'server error'. Here's the object I'm sending to the /tasks endpoint:
data: {
name: 'Figure this out',
notes: '',
assignee: null,
completed: false,
assignee_status: 'later',
completed_at: null,
due_on: null,
tags: [],
parent: null,
followers: [ { id: 5622986387066 }, { id: 5622895459066 } ],
projects: [ 6156399090409 ],
workspace: 1707039411020
}
Any ideas? I've tried passing those ID values a variety of ways, and I've tried creating a more simple task, always fails with a 'server error' response.
Seems like it's the "parent": null that's causing the unhelpful Server Error, which definitely seems like a bug on our side - I've filed it and will hopefully get time to look into it soon. Trim that out, and it gives you actual error messages.
Just to save you some time: you can't set completed_at or tags, and followers should be just an array of integers ("followers": [ 5622986387066, 5622895459066 ]).
You can set completed: [true/false], and the completed_at will be set to the time at which it was marked complete. Not being able to attach tags to a task is a known issue, and one we're hoping to rectify.
Additionally, it's just a little annoying that the format of a response doesn't map 1-1 to the format for posting/updating. We're hoping to do a pass on the overall design of the API to unify those parts a bit more.

Resources