From fe1c6b24abda7d2d98bcd26b29f4fbda4fd0ef31 Mon Sep 17 00:00:00 2001 From: Rohit Ambre Date: Fri, 3 Jan 2020 06:06:15 +0530 Subject: [PATCH] Added href to empty tag in social auth implementation II (#38002) * Added href to empty tag in social auth implementation II * corrected typos in authentication with socketIO challenge * corrected typo as suggested Co-Authored-By: Eric Leung Co-authored-by: Eric Leung --- .../authentication-with-socket.io.english.md | 4 ++-- .../implementation-of-social-authentication-ii.english.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/curriculum/challenges/english/06-information-security-and-quality-assurance/advanced-node-and-express/authentication-with-socket.io.english.md b/curriculum/challenges/english/06-information-security-and-quality-assurance/advanced-node-and-express/authentication-with-socket.io.english.md index 6f1f949a1e..04e4476ba7 100644 --- a/curriculum/challenges/english/06-information-security-and-quality-assurance/advanced-node-and-express/authentication-with-socket.io.english.md +++ b/curriculum/challenges/english/06-information-security-and-quality-assurance/advanced-node-and-express/authentication-with-socket.io.english.md @@ -8,7 +8,7 @@ forumTopicId: 301548 ## Description
As a reminder, this project is being built upon the following starter project on Glitch, or cloned from GitHub. -Currently, you cannot determine who is connected to your web socket. While 'req.user' containers the user object, thats only when your user interacts with the web server and with web sockets you have no req (request) and therefore no user data. One way to solve the problem of knowing who is connected to your web socket is by parsing and decoding the cookie that contains the passport session then deserializing it to obtain the user object. Luckily, there is a package on NPM just for this that turns a once complex task into something simple! +Currently, you cannot determine who is connected to your web socket. While 'req.user' contains the user object, that's only when your user interacts with the web server and with web sockets you have no req (request) and therefore no user data. One way to solve the problem of knowing who is connected to your web socket is by parsing and decoding the cookie that contains the passport session then deserializing it to obtain the user object. Luckily, there is a package on NPM just for this that turns a once complex task into something simple!
Add 'passport.socketio' as a dependency and require it as 'passportSocketIo'. Now we just have to tell Socket.IO to use it and set the options. Be sure this is added before the existing socket code and not in the existing connection listener. For your server it should look as follows: @@ -21,7 +21,7 @@ io.use(passportSocketIo.authorize({ })); ``` -You can also optionally pass 'success' and 'fail' with a function that will be called after the authentication process completes when a client trys to connect. +You can also optionally pass 'success' and 'fail' with a function that will be called after the authentication process completes when a client tries to connect. The user object is now accessible on your socket object as socket.request.user. For example, now you can add the following: console.log('user ' + socket.request.user.name + ' connected'); and it will log to the server console who has connected! Submit your page when you think you've got it right. If you're running into errors, you can check out the project up to this point here.
diff --git a/curriculum/challenges/english/06-information-security-and-quality-assurance/advanced-node-and-express/implementation-of-social-authentication-ii.english.md b/curriculum/challenges/english/06-information-security-and-quality-assurance/advanced-node-and-express/implementation-of-social-authentication-ii.english.md index 273da4f545..8f6d21893a 100644 --- a/curriculum/challenges/english/06-information-security-and-quality-assurance/advanced-node-and-express/implementation-of-social-authentication-ii.english.md +++ b/curriculum/challenges/english/06-information-security-and-quality-assurance/advanced-node-and-express/implementation-of-social-authentication-ii.english.md @@ -9,7 +9,7 @@ forumTopicId: 301557
As a reminder, this project is being built upon the following starter project on Glitch, or cloned from GitHub. The last part of setting up your GitHub authentication is to create the strategy itself. For this, you will need to add the dependency of 'passport-github' to your project and require it as GithubStrategy like const GitHubStrategy = require('passport-github').Strategy;. -To set up the GitHub strategy, you have to tell passport to use an instantiated GitHubStrategy, which accepts 2 arguments: An object (containing clientID, clientSecret, and callbackURL) and a function to be called when a user is successfully authenticated which we will determine if the user is new and what fields to save initially in the user's database object. This is common across many strategies but some may require more information as outlined in that specific strategy's github README; for example, Google requires a scope as well which determines what kind of information your request is asking returned and asks the user to approve such access. The current strategy we are implementing has its usage outlined here, but we're going through it all right here on freeCodeCamp! +To set up the GitHub strategy, you have to tell passport to use an instantiated GitHubStrategy, which accepts 2 arguments: An object (containing clientID, clientSecret, and callbackURL) and a function to be called when a user is successfully authenticated which we will determine if the user is new and what fields to save initially in the user's database object. This is common across many strategies but some may require more information as outlined in that specific strategy's github README; for example, Google requires a scope as well which determines what kind of information your request is asking returned and asks the user to approve such access. The current strategy we are implementing has its usage outlined here, but we're going through it all right here on freeCodeCamp! Here's how your new strategy should look at this point: ```js