Congratulations, you made it all the way through this book! We hope you have enjoyed reading it as much as we did writing it. We covered quite a lot of material on our trip, as OAuth isn’t a simplistic protocol and there are many moving pieces and a variety of ways to put them together. This seems daunting at first, but we hope that now that you’re armed with the knowledge of how everything works, you can see that it’s as simple as possible but no simpler. We hope that what you’ve learned while building all the moving pieces of OAuth with us will guide you in your future expeditions. In this final chapter, we’re going to take a few pages to talk about the bigger picture.

16.1. The right tool

OAuth is a powerful delegation protocol, but we know that you’re not using OAuth for its own sake. The “auth” in OAuth stands for “authorization,” and nobody uses an authorization protocol unless they’re trying to authorize some kind of action. We know that you likely first had to use OAuth to do something else : something useful, something beautiful, something wonderful. OAuth is merely one of many tools at your disposal for solving a certain set of problems, whether protecting an API, building a client to access an API, or developing an overarching security architecture to tie a system together. As with all tools, it’s useful and important to understand how those tools work and what they’re good for. After all, although it’s possible to drive a screw into a wall using a hammer, you’ll have much better luck with a screwdriver. We want you to be able to know when OAuth is a good fit for your problem and, just as important, when it’s not a good fit.

It’s our hope that this book has given you the kind of in-depth knowledge you’ll need to recognize when to reach for OAuth in the toolbox and how to apply it to your particular set of problems. We didn’t want this book to be merely a guide for the OAuth implementation at the leading internet providers, or even how to use a particular OAuth library. We believe there already exists plenty of documentation online for those kinds of focused queries. Instead, we wanted you to be so thoroughly familiar with OAuth by the end that you’ll be able to use it no matter what platform or application you’re using it on.

We know that almost no one reading this book will implement an OAuth ecosystem from scratch, end to end. So why did we go through all the trouble? The text and exercises in this book should leave you with a deep understanding and appreciation for the OAuth protocol and all of its attendant pieces, allowing you to see the data as it flows through the system. By building out an entire ecosystem from scratch, we hope you’ll have a better idea of what’s going on when your client sends out a request and gets back a peculiar response, or why clients are sending things to your resource server in ways that you didn’t quite expect. By working on the implementation from the other side, we hope you’ll be more tolerant and understanding of how things are built, but not so tolerant that you open up an inadvertent security hole. After all, by now it should be clear that the parts of the OAuth process are put there for good reason.

If instead of reading this entire book cover to cover you jumped into only the part that seemed most relevant to your immediate problem, we won’t judge you. In fact, that’s how we tend to treat big technical books like this one. However, now would be a great time to go back and look at other parts of the system. Are you building a client? Then go try to build out the authorization server. Are you working on an in-browser application? Check out the native application section. Are you working on an authentication protocol like OpenID Connect? Go back and check out the guts of the OAuth protocol itself and get a feel for how that authentication information is carried across the network in OIDC.

16.2. Making key decisions

As we’ve seen throughout the book, OAuth is a framework that’s full of options. Navigating these options is a little tricky, but we hope that by now you’ve got a good idea of what to do in this space. It’s our hope that you can also see the value in each of the different options provided by the OAuth framework and why those options were added. Instead of having a single protocol that doesn’t quite fit well to any of its major uses, OAuth 2.0 gives us a bunch of pieces that we can use to do different things. We hope this book provides you with a means of deciding which pieces to apply and when to apply them.

We realize that it’s tempting to take shortcuts in this process, going with something that feels simpler instead of the options that are the best fit for your use case. After all, the implicit flow is simple, why not use that for everything and skip the authorization code nonsense? Or why bother the user at all when we can add a parameter to our API and have the client tell us which user it’s acting on behalf of? However, as we saw in the vulnerabilities section of this book, these kinds of shortcuts inevitably lead to pain and compromises. As enticing as it may seem, there really are no good shortcuts to good security.

One of the most important decisions to make is whether to use OAuth 2.0 at all. The flexibility and ease of implementation that make OAuth the go-to protocol for protecting APIs also make it tempting to treat OAuth as the appropriate solution to many different problems. The good news here is that the structure and philosophy of OAuth can be ported, as has been shown with recent efforts to deploy the process on non-HTTP protocols. Corollary to this is whether OAuth is a sufficient solution for a problem: as we’ve seen, many times OAuth in the real world is augmented with other technologies to solve a larger problem than simple rights delegation. We contend that this is a good thing, and leads to a rich ecosystem.

Once you’ve decided to build out an OAuth system, there’s one question that you should be asking first: Which authorization grant type should you be using? The authorization code grant type that we went into great detail in chapter 2 and built over the course of chapters 3 through 5 should be the default choice for most situations. Only if what you’re building fits into one of several specific optimizations should you be considering a different grant type. A large part of that optimization space depends on what kind of client you’re building (or expecting to be built) to access an API. For instance, if your client is running entirely within a browser, then the implicit flow makes sense. But if you’re building a native application, the authorization code flow remains much better. If you’re not acting on behalf of a particular user, then the client credentials flow will work well for you. But if you are acting on behalf of a specific user, then you’re much better off involving that user in the process using one of the interactive grant types. This is true even if the user doesn’t make the authorization decision, as in an enterprise deployment, because the presence of an authenticated user can be used as one major pillar in the overall security architecture.

Of course, even if you make every core decision correctly, things can still go wrong in deployment or use. That’s the nature of security, and it doesn’t come for free. OAuth goes a long way in helping people get things right by pushing the complexity away from the clients and on to the authorization servers, but even then it’s important to use these components in the right way. This includes making sure all of the surrounding and underlying systems, such as TLS, are up and running as intended. OAuth helps here, too, by basing its security model on many years of deployment experience across a wide variety of systems. By following a few best practices and using the right parts of OAuth in the right way, a small one-off API provider can give access to the same kind of security and delegation capabilities available on the largest APIs of the internet today.

16.3. The wider ecosystem

As we’ve shown throughout this book, OAuth was designed to do a job—security delegation—and do that job well. OAuth doesn’t handle some things well, or at all, but as we’ve seen in the latter parts of this book, that’s not a bad thing. OAuth has provided a solid base upon which a wide and rich ecosystem has been erected over time. Much in the same way that the OAuth framework provides a set of choices to solve different problems, the surrounding ecosystem provides a set of choices of things that can be used along with OAuth to solve a wide variety of requirements.

The OAuth working group explicitly left out several items key to a real security architecture, such as the format of the access token itself. After all, if you need to create the tokens anyway, why not tell everybody exactly how to make the tokens? This conscious omission has allowed for the development of complementary technologies such as JOSE and JWT that work well with, but aren’t dependent upon, OAuth. JOSE combines the simplicity of JSON with advanced cryptographic functionality in a way that’s still easy for developers to get right. Alternatively, for situations in which the tokens need to be compact, or don’t need to be self-contained at all, token introspection provides a viable alternative. Importantly, these two can be swapped out or even combined without the client being any the wiser, all thanks to OAuth’s commitment to do one job and one job alone.

Other extensions are added to OAuth to deal with specific situations. For instance, the PKCE extension we described in chapter 10 is used to help prevent the theft of the authorization code on native mobile applications using a local application-specific URI scheme. PKCE doesn’t make much sense outside of this narrow window, but it works wonderfully within that space. Likewise, the token revocation extension provides a way for clients to proactively throw away tokens. Why is this not a universal feature of OAuth? In some systems, the OAuth token is entirely self-contained and stateless, and there isn’t a reasonable way to propagate a “revocation” event through the distributed system of resource servers. In others, the clients are presumed to be completely naïve to the status of the token, and this kind of proactive measure would make little sense. However, for ecosystems in which the tokens are stateful and the clients are marginally smarter than they need to be, revocation provides an extra bit of security on top of everything else.

Comparably, OAuth can be used to build lots of different protocols. We saw in great detail in chapter 13 that although OAuth is not itself an authentication protocol, it can be used to build one. Furthermore, we saw how profiles and applications of OAuth such as HEART and iGov can bring together large communities for interoperability. These efforts lock down a set of OAuth’s choices and extensions in a way that provides a pattern and recipe that others can follow. OAuth can also be used to build complex protocols such as UMA that take the OAuth delegation pattern and extend it to multiple parties.

16.4. The community

OAuth has a thriving community on the internet, with lots of resources, discussions, and experts ready to help out. As you’ve seen in this book, there are a lot of decisions to be made when building an OAuth ecosystem, and chances are there’s somebody else on the internet that’s already made that decision in similar circumstances. You’ll find open source projects, large companies, nimble startups, waves of consultants, and (we hope) at least one decent book that will help you figure out what OAuth is all about. You’re far from alone in your choice of this security system, and when it comes to security, there is strength in many eyes and many hands on the problem space.

The OAuth working group is still working on the protocol and its extensions, and you (yes, you) can join the conversation. [ 1 ] Think you can do better than OAuth? Does your use case need some bit of special sauce on top of OAuth? Do you need a grant type with different assumptions and deployment characteristics? Then by all means bring the conversation to the working group.

1

https://tools.ietf.org/wg/oauth/

Since OAuth isn’t defined and owned by a company, or even a consortium like many open source projects, it doesn’t have official branding and marketing to make it recognizable. Instead, the community has once again stepped in. OAuth’s bus token logo was drawn by Chris Messina and submitted to the community, where it took off even though it’s technically not official. The OAuth protocol even has an unofficial-yet-awesome mascot: OAuth-tan ( figure 16.1 )! [ 2 ]

2

Used by permission from Yuki Goto.

Figure 16.1. OAuth-tan! We dare you to access the APIs she’s protecting without her permission.

This community has been able to grow naturally because of a few things. First and foremost, OAuth solves a real problem that people have. The API and mobile application economies were only getting started when OAuth 1.0 and 2.0 were developed, and OAuth stepped in to provide a much needed security layer. Second, and just as important, OAuth is an open protocol. It’s not owned or controlled by any one company, and anybody can build an implementation without paying royalties or licensing fees. This means that there’s grown up a large community of software, libraries, and demonstrations that support OAuth out of the box in its various forms. What if there isn’t something on your favorite platform? Chances are that there’s a similar implementation that you can copy from another language, all ready to go.

OAuth is relatively simple. Sure, you’ve gone through somewhat north of 300 pages of material on the topic, and there are a lot of things that can go quickly wrong with it if you’re not careful. But compared with the deep complexities of many of the systems that have come before (Kerberos, SAML, or WS-*), it’s downright trivial. This is especially true, we’ve seen, of clients, which make up the majority of the ecosystem. The balance of simplicity has allowed it to be adopted in ways and in places that have previously eschewed security protocols, bringing more developers into the fold.

16.5. The future

The OAuth Dance that we saw in chapter 2 is one of the most popular dances on the internet today, but today’s popularity is in no way guaranteed going forward. Although we do think that the power and relative simplicity of OAuth 2.0 mean that it will be around for a while yet, technology inevitably marches onward.

In the OAuth world itself, we’ve already seen some of this with the effort in standardizing PoP tokens. The PoP specifications have taken the JOSE technologies and applied them in a new way to OAuth, creating PoP tokens that will provide a higher level of security than bearer tokens, but at the cost of some added complexity. As such, they’ll likely be deployed as needed, and often alongside of bearer tokens. It’s possible we’ll see other forms of tokens in the future, such as ones bound to the TLS layer or using exotic new cryptographic mechanisms.

Enough extensions and components have been added to OAuth that it’s likely that we’ll see an OAuth 2.1 or OAuth 3.0 that combines all of these components into a single, cohesive suite of specifications that are easier to navigate than the organically grown documents we have today. Any such reorganization work is a long way in the future, if it’s to happen at all.

Finally, there will almost inevitably come a day when OAuth is itself entirely supplanted by something newer and better. OAuth is a child of its time, with direct dependencies on HTTP, web browsers, and JSON. Although their life spans may be long, these technologies won’t continue to exist in the same universality and form as they do today. In much the same way that OAuth has replaced Kerberos, WS-Trust, and SAML in many security architectures and fit into new places where those older protocols could not, there will be something new that will eventually take OAuth’s place as the security protocol to pay attention to.

Until then, OAuth is and will continue to be well worth understanding and building.

16.6. Summary

It was quite a journey. We started with the core definition of OAuth 2.0, wound our way up through the actors and components and interconnections, and built an entire ecosystem from scratch. Then we took a step back and looked at what could go wrong, and how to fix it. We then took a more in-depth look at the world of protocols surrounding OAuth, including OpenID Connect and UMA. Finally, we looked ahead to where OAuth might be going in the future with PoP tokens and token binding.

What’s next? Now, it’s time to build your system. Find good libraries. Contribute to open source. Engage in the standards community. After all, you’re not building OAuth capability for its own sake; you’re building OAuth capability that you’ll use to protect and secure some other piece of functionality that you and the rest of the world care about. Now that you’ve got a handle on how delegation, authorization, and many of the attendant security bits work using this OAuth thing, you can concentrate on what you’re really after: building your application, API, or ecosystem.

Thank you for joining us. We hope you have enjoyed the trip as much as we’ve enjoyed guiding it.