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

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
主站蜘蛛池模板: 萍乡市| 盐城市| 仁怀市| 黔江区| 甘德县| 壶关县| 上高县| 大港区| 柯坪县| 荃湾区| 永济市| 青田县| 诏安县| 炎陵县| 漳浦县| 牙克石市| 界首市| 新乡县| 贵定县| 吉木乃县| 突泉县| 萨嘎县| 衡东县| 孝义市| 盱眙县| 定兴县| 都匀市| 阳泉市| 筠连县| 额济纳旗| 资阳市| 高阳县| 淮南市| 隆安县| 潞西市| 南丰县| 平南县| 棋牌| 南城县| 昔阳县| 玛多县|