Eyebrow Text
BLOG
Title
Securely Using the OIDC Authorization Code Flow and a Public Client with Single Page Applications
Subtitle
Explore the architecture, security implications, and key safeguards for using the OIDC Authorization Code Flow with a Public Client for Single Page Applications.
title
Table of Contents
theme
default

The traditional approach to using OAuth2 or OpenID Connect (OIDC) with Single Page Applications (SPAs) is the OAuth2 Implicit Grant or OIDC Implicit Flow, and many developers still use this approach. More recently, however, the use of the OAuth2 Authorization Code Grant (or OIDC Authorization Code Flow) with a Public Client has been on the rise. Identity Provider (IdP) vendors and bloggers have expressed varying opinions over using the OIDC Authorization Code Flow with a Public Client for SPAs, but this approach—with the proper safeguards—is viable and brings several benefits to the table, including:

I've explored these benefits in much greater detail in my previous blog posts. Going forward, the industry is moving toward using the OAuth2 Authorization Code Grant (or OIDC Authorization Code Flow) with a Public Client. In this blog post, we will explore how to best ensure this approach is used with SPAs in a secure manner.

OIDC Authorization Code Flow (with a Public Client) Architecture

To make sure we are all talking about the same thing, let's assume an architecture and interaction that looks similar to the following diagram.

image
/content/dam/picr/img/bl/2018/images/spa-oidc-auth-diagram-blog.jpg
alt-text
Diagram of OIDC authorization code flow
caption
width
auto
height
568px
alignment
left
id
link-url
disable-lazy-load

Furthermore, let's spell out these assumptions (some, but probably not all, will be true for your use case):

Note: This blog post is not looking at the interaction between the SPA and the API Gateway. If you are interested in that topic, check out previous posts "How To Submit Your Security Tokens to an API Provider Pt. 1" and "How To Submit Your Security Tokens to an API Provider Pt. 2".

Security Implications

Now, I am coming at this from a specification-centric vision of the world. This means I am really asking the question, "How do we solve X within the confines of the relevant specs A, B, C, etc.?" Most IdPs provide mechanisms for having control over the length of authenticated sessions, obtaining new tokens without the user being prompted to re-authenticate through a security session tracked with a cookie, and additional functionality that is useful, but proprietary.

So what are the security implications here? The OAuth2, OIDC, and JWT (and supporting) specs provide several mitigating controls to help ensure the integrity of an OIDC login flow, including:

Things to Keep in Mind

Now that we've looked at some of the security implications of using the OIDC Authorization Code Flow (with a Public Client) for a SPA, here are some things to keep in mind to ensure a better protected system:

Also, keep in mind that all of this assumes that the browser and underlying OS/device have not been compromised in any way. If these are compromised, most of what I've mentioned here isn't going to matter very much.

Summary

Historically, the industry has used the OAuth2 Implicit Grant (or OIDC Implicit Flow) with SPAs. There are no security requirements calling for its continued use. The OAuth2 Authorization Code Grant (or OIDC Authorization Code Flow) should be used with SPAs going forward.

To learn more and for further discussion on these types of topics, check out my blog on API Management, Integration, and Identity on medium.com or read OAuth 2 for SPAs: Recommended Practices from Ping Identity.

title
See How Ping Identity Secures Modern Applications
body
Ping Identity helps organizations implement the OIDC Authorization Code Flow and other modern authentication standards securely across SPAs, native apps, and beyond.
Supporting text
primary-link
https://www.pingidentity.com/en/company/contact-sales.html
primary-link-text
Request a Demo
primary-link-title
Request a Demo
use-tertiary-arrow-button-style
secondary-link
secondary-link-text
secondary-link-title
use-tertiary-arrow-button-style-2