Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google + Authentication without Passport.js

I cant understand the standard flow of authentication and authorization of Google + without using Passport

Requirement:

  1. No passport.js (i know it is simple to use it, but I dont want to use it)
  2. No sessions (will not be using any session, i want to maintain statelessness)

Current architecture:

  • I had a REST API server, with JWT (JSON Web token),
  • user will get a access token from my server, when they do a POST /login
  • my server, will check the username and password and return with access token
  • this token is needed for future API query in my server

Question:

i) how can I replace my current authentication with Google + ?

ii) when i login using Google + button, I got a access token in my client side, do i send the token back to my server?

iii) but, my server has no information of this user?, do i need first create this user in my server, and when it sends an access token to my server, i will check if this user is valid and return it with my server access token? (so for this user, will not have password information on my server database?, and this access token from google will be stored in my server?)

iv) I read about their doc they are using sessions, when the user first visit the page, I dont want to use sessiosn

I want to know the general flow, the code I could implement it myself, I just want to know the common architecture to solve this problem!

It would be great, if you could show me the general concept to deal with this! :)

like image 546
Tim Avatar asked Sep 01 '14 05:09

Tim


People also ask

Why do I need passport for Javascript?

Passport is a popular, modular authentication middleware for Node. js applications. With it, authentication can be easily integrated into any Node- and Express-based app. The Passport library provides more than 500 authentication mechanisms, including OAuth, JWT, and simple username and password based authentication.

Is Passport JS oauth2?

This module lets you authenticate using OAuth 2.0 in your Node. js applications. By plugging into Passport, OAuth 2.0 authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.

How to do Google authentication using OAuth in Node JS?

We can do Google authentication using OAuth API which is provided by Google on their developer portal. Step 1: Creating Node project using the following command. Keep pressing enter and enter “yes/no” accordingly at the terminus line.

What is the difference between OAuth and Google authentication?

Authentication is basically the verification of users before granting them access to the website or services. Authentication which is done using a Google account is called Google Authentication. We can do Google authentication using OAuth API which is provided by Google on their developer portal.

What is express passport JS?

Passport JS is a middleware for express.js. (I will explain about middlewares below). Passport JS supports various login types, Token, Local (username, password), OAuth, OAuth2, etc. We can combine these to authenticate by signing in with Google, FB, or whatever service with a very minimal amount of code.

How does passport authenticate work in Laravel?

When a request to this route is processed, the strategy will authenticate the fact that the user signed in with Google and obtain that user's profile information. If authentication succeeds, passport.authenticate () middleware calls the next function in the stack. In this example, the function is redirecting the authenticated user to the home page.


1 Answers

This is the most recommended way to implement Google+ sign in

Google Hybrid server side signin procedure

To sum it up, there is 2 part;

  1. Retrieve the auth token from Google
  2. Send the Google auth token to exchange for another token from your server

1) To retrieve the auth token from Google, you could use their available SDKs

2) Once you got the auth token from Google, send it back from your client to your server again

3) In your server, exchange the auth token from Google for their access token to allow you to use the Google API on behalf of the user. You could retrieve user information, post Google+ post

4) Generate your own server access token and send it back to the client

5) In your client, save your server generated access token to be used for CRUD from your server

like image 87
Tim Avatar answered Sep 23 '22 04:09

Tim