How do I set API keys for Twitter in Meteor without using the GUI - twitter

How do I get rid of the configure button on the frontend from the {{>loginbuttons}} tag?
So far I have tried:
if (Meteor.isServer) {
Meteor.startup(function(){
Accounts.loginServiceConfiguration.remove({
service: 'twitter'
});
Accounts.loginServiceConfiguration.insert({
service: 'twitter',
consumerKey: 'KEY',
secret: 'SECRET'
});
});
}
I can't find documentation for accounts-twitter, I can't seem to understand where Meteor packages code can be looked at.

From the docs http://docs.meteor.com/#/full/meteor_loginwithexternalservice
First, add the service configuration package:
meteor add service-configuration
Then, in your app:
// first, remove configuration entry in case service is already configured
ServiceConfiguration.configurations.remove({
service: "weibo"
});
ServiceConfiguration.configurations.insert({
service: "weibo",
clientId: "1292962797",
loginStyle: "popup",
secret: "75a730b58f5691de5522789070c319bc"
});
try
// first, remove configuration entry in case service is already configured
ServiceConfiguration.configurations.remove({
service: "twitter"
});
ServiceConfiguration.configurations.insert({
service: "twitter",
consumerKey: "1292962797",
loginStyle: "popup",
secret: "keyyyyy"
});

This Github repo, shows the use for Facebook, Twitter, Google and Github.
They behave the same, although args may be different.

Related

Created a user pool client using Cognito Identity Provider Client SDK for JavaScript v3, but can't fetch token using (client_credentials) grant type

Created a user pool client using Cognito Identity Provider Client SDK for JavaScript v3
npm install #aws-sdk/client-cognito-identity-provider.
The following code shows how I created the resources server and the user pool client, using the mentioned👆 SDK...
let poolName = 'UserPool';
const client =new CognitoIdentityProviderClient({
region: process.env.COGNITO_AWS_REGION
});
// create resource server
const createResourceServerCommand = new CreateResourceServerCommand({
Name: poolName,
UserPoolId: UserPool.Id,
Identifier: 'https://localhost:8080/api/v2',
Scopes: [
{
ScopeName: 'access',
ScopeDescription: 'General access to API'
}
]
});
const { ResourceServer } = await client.send(createResourceServerCommand);
// create the user pool client
const createUserPoolClientCommand = new CreateUserPoolClientCommand({
ClientName: 'Default',
UserPoolId: UserPool.Id,
ExplicitAuthFlows: ['USER_PASSWORD_AUTH'],
GenerateSecret: true,
AllowedOAuthFlows: ['client_credentials'],
SupportedIdentityProviders: ['COGNITO'],
AllowedOAuthScopes: [ 'https://localhost:8080/api/v2/access' ]
});
const { UserPoolClient } = await client.send(createUserPoolClientCommand);
...but, I can't fetch tokens using the grant type client_credentials. Therefore getting the following error.
{
"error": "invalid_grant"
}
However, if I use AWS console to navigate to the user pool > Client > Edit the hosted UI and click on the save button without making any changes...
... I am able to fetch a token using the client_credentials grant type.
Is there any setting that I might be missing in the above code that AWS console is setting? I need the following code to automate the creation of user pools.
When I switched to the old I noticed this notification
Apparently, Oauth flows are not enabled by default. Hence adding the following attribute to the CreateUserPoolClientCommandInput object AllowedOAuthFlowsUserPoolClient: true enables it. Hope this helps some newbie like me out there.

TypeError: OAuthStrategy requires a consumerKey option

I keep getting this error when I added the twitter OAuth to my application. I currently have google OAuth which works fine, but adding twitter is causing the error. I don't see viable solution in all the previous posts on this error; can anyone help please? here is the code snippet for the twitter- it is the same as the google one.
passport.use(
new TwitterStrategy({
twitterclientID: keys.twitterclientID,
twitterclientSecret: keys.twitterclientSecret,
callbackURL: '/auth/twitter/callback',
proxy: true
}
Replace twitterclientID with consumerKey
&
Replace twitterclientSecret with consumerSecret
Recently google also does the same thing so you need to update for google as well since you are using google oauth
passport.use(
new TwitterStrategy({
consumerKey: theClientID,
consumerSecret: theClientSecret,
callbackURL: '/auth/twitter/callback',
proxy: true
}
passport.use(
new TwitterStrategy({
consumerKey: keys.twitterclientID,
consumerSecret: keys.twitterclientSecret,
callbackURL: '/auth/twitter/callback',
proxy: true
}
I had already declared consumerKey and consumerSecret. The issue for me was, that the environment variables used as the values for both keys, were not defined.
If you use netlify the issue may be solved after running netlify link.

#feathersjs/authentication-oauth2 not creating JWT and user

I cannot authenticate to a FeathersJS server using OAuth2 Facebook strategy because after Facebook grants access to user profile, the feathers-authentication-oauth2 plugin doesn't create the user into the DB and it also doesn't create the required JWT token to be authenticated when calling feathersclient.authenticate() in the client app.
I've tried to follow all documents I've found that explain how to do it, but as a good example I could select this one (https://blog.feathersjs.com/how-to-setup-oauth-flow-with-featherjs-522bdecb10a8) that is very well explained.
As a starting point I've taken the Feathers chat application explained at the documentation (https://docs.feathersjs.com/guides/chat/readme.html) after having it working properly, I've added tha OAuth2 part as explained in the Medium document. In the default.json file I've added the "facebook" authentication strategy:
"facebook": {
"clientID": "MY_CLIENT_ID",
"clientSecret": "MY_CLIENT_SECRET"
}
In the authentication.js fileI've added the configuration of the Facebook OAuth2 authentication:
const authentication = require('#feathersjs/authentication');
const jwt = require('#feathersjs/authentication-jwt');
const oauth2 = require('#feathersjs/authentication-oauth2');
const FacebookStrategy = require('passport-facebook').Strategy;
module.exports = function (app) {
const config = app.get('authentication');
// Set up authentication with the secret
app.configure(authentication(config));
app.configure(jwt());
app.configure(oauth2({
name: 'facebook',
Strategy: FacebookStrategy,
callbackURL: '/',
scope: ['public_profile', 'email'],
}));
...
And finally, in src/app.js file I've added a new "Facebook login" button that just changes window.location to '/auth/facebook' so that the OAuth2 Facebook process can begin.
After pressing the "Facebook login", I'd expect the user to be created in the NeDB DB and a valid JWT to be stored so that the feathersclient.authenticate() call would not fail.
But instead of that, the Facebook login page is properly called, and after that the browser is returned to the main page ('/'), but after that, when the main page is reloaded and the feathersclient.authenticate() is called, the server complains that there isn't any valid JWT token, so authentication fails. Also I cannot see the user created in the NeDB DB, so the supposed user and JWT creation that should be done by the feathers-authentication-oauth2 plugin is not...
I've finally made it work... I was wrongly configuring the Facebook authentication strategy, I've changed it to:
app.configure(oauth2({
name: 'facebook',
successRedirect: '/',
failureRedirect: '/',
Strategy: FacebookStrategy
}));
and now it is working.

jwt authentication in iOS client nodejs server via third party authenticator

I am trying to wrap my head around using json webtoken (jwt) based authentication on a server coupled to using a third party (say google) to authenticate the user. Originally I've managed to build my own login and jwt handling scheme with jsonwebtoken on my nodejs server, but we need a client running on an iOS system to interact with it and started looking around for a solution where we don't have to code so much client code (requesting new token when expired etc.) and thought that we would use a third party library to do this for us.
The thing is I did not find anything that would do this for us. I found libraries that could handle connecting the client to a google api for the client, I found user identification handled by google, but didn't find anything that would handle actually getting a jwt that the server would except as a genuine user.
My question is essentially this: we have an iOS client and a nodejs server and would like to use google to authenticate our users and have the client call api-s on our nodejs server, with as much of the authentication process handled by some third party library (google's?), how should we get around to this?
As a note, I've seen passport but that seems to operate with sessions only, and I would have to solve the jwt handling by myself were I to use that.
The iOS part is not ready, but I managed to use google to authenticate and authorize without a session in the browser. The idea is, that the client logs in to google (see here for web app) and google graciously also gives you a token with the login, which will be good for the server. On the nodejs side I used passport and the google-id-token strategy (see on github). There are quite a few strategies for google out there, but this one works. Although, this has a shortcoming, it can't accept the token in the header, but I fixed that in a pull request (see here).
Since I had a bit of a problem of how to use the User.findOrCreate part of all the passport examples, I'll put in my code here that covers a full working example:
var passport = require('passport');
var GoogleTokenStrategy = require(passport-google-id-token)
passport.use(new GoogleTokenStrategy({
clientID: config.googleAuth.clientID,
clientSecret: config.googleAuth.clientSecret,
},
function(parsedToken, googleId, done) {
console.log(parsedToken);
console.log(googleId);
User.findOne({ 'google.id': googleId }, function (err, user) {
if (!user) {
var testuser = new User({
name: parsedToken.payload.name,
givenName : parsedToken.payload.givenName,
familyName : parsedToken.payload.familyName,
nameunderscore : parsedToken.payload.name.split(' ').join("_"),
admin: false,
email: parsedToken.payload.email,
settings: {save_folder:"default"},
'google.id' : googleId,
'google.email' : parsedToken.payload.email,
});
testuser.save(function(err) {})
}
return done(err, user);
});
}
));
User comes from mongodb in a separate js:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
module.exports = mongoose.model('User', new Schema({
name: String,
nameunderscore : String,
givenName: String,
familyName: String,
admin: Boolean,
settings: {
save_folder: String
},
email: String,
google: {
id: String,
email: String
}
}));
And this is how I added the passport strategy to a router (note that session is set to false):
var apiRoutes = express.Router();
apiRoutes.use(passport.authenticate('google-id-token',{ session: false }));
Now every call to any route in apiRoutes must send on id_token with a valid google token to get access.

How do I setup hello.js to access Twitter?

I'm trying to write a simple Javascript page for sending a tweet with a picture using Hello.js. I've used this demo as a starting point but a lot isn't really explained. My init looks like this:
hello.init({
'twitter' : '****'
});
It says here that I need to "Register your client_id + client_secret at the OAuth Proxy service". But how do I do this? The Twitter page for my app shows:
Consumer Key.
Consumer Secret.
Access Token.
Access Token Secret.
The registration at https://auth-server.herokuapp.com/ asks for:
reference.
domain.
client_id.
client_secret.
What do I set these to? Do the reference and domain have to match something in my code? Are the client_id and client_secret the Consumer or Access Token parameters?
The reference is the network name, like "twitter", "dropbox", etc.
The domain is the domain your calling from. It can work with something like "http://localhost:8080".
For Twitter, the client_id is the Consumer Key (API Key) and the client_secret is the Consumer Secret (API Secret).
Once this is done, in your JS code you just have to add something like this:
hello.init({
twitter: '<your Consumer Key>'
}, {});
And then a button with the following code should work:
<button onclick="hello( 'twitter' ).login()">Login with Twitter</button>
I had a lot of problems with hello.js and Twitter, until I finally found out:
If you don't have a working domain yet (you are developing), you ought to write 127.0.0.1 in the callback URL within the settings of your twitter app.
-Within the same settings, make sure you select "Allow the app to sign up with twitter".
-Your init function should look like this:
hello.init({
twitter : 'xxxxxx'
},{redirect_uri : 'localhost',
oauth_proxy : 'https://auth-server.herokuapp.com',
oauth_version: 'xx' // probably 1.0a with hello.js
});

Resources