Node js Login API with Passport js - node.js

I'm building an project witch having lots of API but I have login API too in this case I'm using passport local stratagy for it I followed this video Node.js With Passport Authentication | Full Project But now while making API I haven't rendering page I want to send json respose that will says that password wrong or user not found but in local stratagy has only success redirect and failure redirect don't ay option to send json reponse Please suggest me a secure technique to do that also I'm verifing email is verified or not and user banned or not.

Read this article https://medium.com/swlh/set-up-an-express-js-app-with-passport-js-and-mongodb-for-password-authentication-6ea05d95335c
It will cover from start to end of using passport.js login using local strategy.
Here is the repo of above code implementation
https://github.com/FBosler/fb-tutorial-social-login/tree/steps/3_backend_1

Related

Is there a way to make an authentication form (login popup) when user accessing open API route in expressjs

I have create a route that showing openAPI documentation in expressjs using the #wesleytodd/openapi package. The route successfully showing my documentation but I want to set a form that if user wants to see my documentation they must have to log in first (I set for them).
May be it looks like in this question: HTTP authentication cpanel
Welcome to StackOverflow 👋
you can make use of a button, it will depend on your SecuritySchemes authentication as well the generator you are using
and when pressing the button, you will get
images above are from SwaggerHub platform

Facebook auth using passport.js is not working

I am working with node.js in the backend. I am using a passport-facebook and cookie-session for authentication. But the error is showing every time (please check the added pic). I have rechecked my code various times, with no error or problems with the development side. Is it the problem of Facebook itself? Or I have to do any update on the developer.facebook.com console?
This the passport.js file

Redirect user to angular app after login with nodejs/express

I am trying to build an application in nodejs and angular 6, where the login is done with node and after successful authentication the user is redirected to an angular application. I have looked at many resources online but only seem to find examples of either angular apps with login screens (that call nodejs API endpoints to pass user credentials), or with nodejs using express and Passport. If anyone can point me in the right direction for an example of this I would be extremely greatful.
I had created a repo similar with what you're looking for.
Here's the link to the project: ngx-express-passport-setup
You can clone it & try testing it on your environment. Setup instruction is provided.
Provided with all the instructions on ReadMe.Md for someone who wants to use Passport via local, google+, facebook and twitter Step by Step.
This project uses Angular5, NodeJS and ExpressJS
Hope this will help/guide you with your problem if ever you'll decide on using PassportJS as your Authentication as it is quite actually a popular tool for NodeJS.

How can I verify android app's GPGS token on my node.js server using passport

I've developed a game client(Android) and server using Unity and node.js.
The log-in function of the server is implemented using passport.js. It was simple, so I didn't worry about anything. I was supposed to implement log-in feature in my game by popping up the in app browser.
But it turns out android games need to use "Google Play Game Service" to log in to Google. I confused how to use passport.js in this case.
The sequence of the Google OAuth2.0 login I know is roughly as follows.
Game client request "authenticate" to GPGS using "google-games-plugin-for-unity"
If login success, game client can get "Authorization Code" using "GetIdToken()" api.
Game client send this token to my game server.
Game server verify the token(from step3) through Google api service.
If verifying success, my server can get user infos and access token.
Fully login complete.
I am wondering how to implement step3 and onwards using passport.js.
Can I use passport.js to implement this with only "GoogleStrategy" configuration? How?
I found a solution myself. There was something wrong what I knew. The sequence of the Google OAuth2.0 is right as above except one thing.
I thought I could get the "Authorization Code" by using "GetIdToken()" api of "google-games-plugin-for-unity". But, if I wanna get the "Authorization Code", I had to use "GetServerAuthCode()", not to use "GetIdToken()". This description was in ReadME of "google-games-plugin-for-unity" github. It was my fault that I didn't read it in detail.
IdToken and AuthCode are not same, it is the part what I didn't know correctly. (See "Retrieving server authentication codes" of https://github.com/playgameservices/play-games-plugin-for-unity#retrieving-server-authentication-codes )
Now, game client can get "Authorization Code" well using "GetServerAuthCode()", and game client make url to send this token to game server as bellow.(using get, but google recommend using post)
var _url = "YOUR://WEBAPP/REDIRECTION/URL?code="+ PlayGamesPlatform.Instance.GetServerAuthCode();
Game server will get this url and the server can use "passport.authenticate" which is the same way when it get redirection url from web browser.
If your both user auth info(android app and web app) are registered in same Google API console project, they will share auth info and the login procedure will perform same like using browser case.

Node post to Facebook with Image

I have an application I am making that I want to MAKE AUTOMATIC POSTS to Facebook. This means that want an Image+text sent to facebook. The image will be an image from cloudinary (where I am hosting my App)
1)User makes post
2)Statistical Algorithm determines whether or not to post...
3) Post Sent to the Facebook Page...
How would I do this. Is there already a module?
Try facebook-node-sdk, this is module for work with facebook over nodejs.
npm install fb
Here is good documentation:
https://github.com/Thuzi/facebook-node-sdk

Resources