官术网_书友最值得收藏!

Chapter 2.  Adding User Accounts

The chat application we built in the previous chapter focused on high performance transmission of messages from the clients to the server and back again. However, the way things stand, our users have no way of knowing who they would be talking to. One solution to this problem is building some kind of sign-up and login functionality and letting our users create accounts and authenticate themselves before they can open the chat page.

Whenever we are about to build something from scratch, we must ask ourselves how others have solved this problem before (it is extremely rare to encounter genuinely original problems) and whether any open solutions or standards already exist that we can make use of. Authorization and authentication can hardly be considered new problems, especially in the world of the Web, with many different protocols out there to choose from. So how do we decide the best option to pursue? As always, we must look at this question from the point of view of the user.

A lot of websites these days allow you to sign in using your accounts that exist elsewhere on a variety of social media or community websites. This saves users the tedious job of entering all of their account information over and over again as they decide to try out different products and services. It also has a positive effect on the conversion rates for new sites.

In this chapter, we will enhance our chat codebase to add authorization, which will allow our users to sign in using Google, Facebook, or GitHub, and you'll see how easy it is to add other sign-in portals too. In order to join the chat, users must first sign in. Following this, we will use the authorized data to augment our user experience so everyone knows who is in the room and who said what.

In this chapter, you will learn to:

  • Use the decorator pattern to wrap http.Handler types in order to add additional functionality to handlers
  • Serve HTTP endpoints with dynamic paths
  • Use the gomniauth open source project to access authentication services
  • Get and set cookies using the http package
  • Encode objects as Base64 and back to normal again
  • Send and receive JSON data over a web socket
  • Give different types of data to templates
  • Work with the channels of your own types
主站蜘蛛池模板: 宽甸| 保德县| 镇安县| 兰西县| 宜兰县| 五家渠市| 如东县| 上犹县| 曲靖市| 任丘市| 无锡市| 曲阜市| 崇左市| 潞西市| 安龙县| 两当县| 江门市| 南郑县| 普洱| 巴林右旗| 曲水县| 桦川县| 柳江县| 容城县| 宜兰县| 文水县| 西青区| 两当县| 莱州市| 北宁市| 霸州市| 九龙城区| 绿春县| 柘城县| 安庆市| 宁乡县| 顺平县| 白山市| 浦江县| 白水县| 石楼县|