Building a React app, Part 2: OAuth information security
In this multipart series, I’m covering the steps needed to add the DocuSign API to a React app, including two patterns for integrated OAuth authentication.
See Part 1: Introduction for more information.
Authentication grant flow
The DocuSign eSignature REST API is sessionless: every API request must include an access token. Your application obtains an access token via one of the OAuth v2.0 grant flows supported by DocuSign. OAuth v2.0 is defined by multiple standards and recommendations documents. RFC 6749 is the OAuth 2.0 Core specification.
RFC 6819 recommends security practices for OAuth and should always be followed. The most common OAuth pattern is a web application in which the application runs on a secured web server. These types of web apps commonly use the OAuth Authorization Code Grant flow.
RFC 6749 § 2.1 defines public and confidential clients. Clients that are locally installed (downloaded to your computer or mobile) and web browser-based applications (including React apps) are public clients and cannot be used to store OAuth secrets or private keys; see RFC 6819 § 184.108.40.206. DocuSign supports the Implicit Grant flow for public clients.
DocuSign’s Authorization Code and JWT grant flows cannot be used with public clients, because they require the client to safeguard a secret key. Confidential clients include server-side authentication code, Platform as a Service code (such as AWS Lambda), and other secure cloud services. Authorization Code and JWT grant flows should be used with confidential clients.
Preventing CSRF attacks
The Identity Provider (IdP) is the server that issues access tokens and manages identities. For DocuSign, account-d.docusign.com is the IdP for the developer account (demo) system. RFC 6819 § 5.3.5 recommends that the OAuth grant flow’s state value should be used to prevent CSRF attacks. To do so, a random value is sent to the IdP as the state value in the first step of the OAuth grant flow. Later, the response from the IdP will also contain the state value, and the client checks that the two values match.
Preventing clickjacking attacks
To prevent clickjacking attacks, RFC 6819 § 220.127.116.11 recommends that the authentication dialog between the user and the IdP not be allowed in an iframe. DocuSign IdPs implement this restriction. Therefore, application developers have two options:
- The application opens a new browser tab, which is then used for DocuSign authentication. Since the application itself opened the new tab, it is also able to programmatically close the tab when it’s no longer needed.
- When the application starts the OAuth flow, it redirects the browser to the OAuth IdP. For a browser-based application, this means that the application is stopped and its code is discarded by the browser when the browser loads the OAuth URL from the IdP. Later, when the IdP redirects the browser back to the application, it will be restarted on the browser. Before the app redirects to the IdP, the app can store its state information in the browser using cookies or the Web Storage API.
Both patterns of opening a new tab for the IdP and redirecting to the IdP work well. The React example implements both techniques; see the ex\ample’s configuration setting
One of the many advantages of OAuth is that SSO (Single Sign-on) is automatically supported by the Authorization Code and Implicit grant flows. As a friend of mine says, it’s neat-o-matic! When someone authenticates, the IdP (account-d.docusign.com or account.docusign.com) enables the user to select Use Company Login. This prompts DocuSign’s IdP to look up the upstream IdP (the SSO server) associated with the claimed domain name of the user’s email address. The user then completes the authentication flow with the SSO server. No application changes or settings are needed to use the SSO flow.
To keep an OAuth implementation secure, RFC 6819 should be followed. It adds some restrictions to your application, but they are all minor.
In the next part of this series, I’ll discuss some of the software patterns used in the example React app itself.
- DocuSign Developer Center
- DocuSign for Developers on YouTube
- @DocuSignAPI on Twitter
- DocuSign on Twitch
- DocuSign for Developers on LinkedIn
- DocuSign Developer Newsletter