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

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
主站蜘蛛池模板: 英山县| 吴堡县| 上栗县| 枣阳市| 内黄县| 哈尔滨市| 蒙山县| 乐陵市| 郎溪县| 三台县| 浠水县| 保亭| 揭西县| 睢宁县| 阳江市| 当雄县| 宁津县| 砚山县| 西青区| 太湖县| 湄潭县| 长治市| 宁乡县| 西宁市| 秀山| 阿城市| 资兴市| 镇远县| 高州市| 兰坪| 西吉县| 青河县| 保德县| 德庆县| 进贤县| 洛隆县| 鄱阳县| 云安县| 桐庐县| 安吉县| 九龙城区|