Web Development

OAuth

OAuth is an open authorisation standard that allows an application to access a user's resources stored in another service without knowing their password, through limited access tokens.

In this post

OAuth is a standard that lets you give an application permission to access part of your data in another service, without handing over your password. The name comes from Open Authorization. It is what happens when you click a button to sign in with your Google account, when you allow a tool to read your calendar or when you connect a photo app to your cloud storage.

The idea is an old one in the real world. If you leave your car with a valet, you do not give them the keys to your house. You give them a special key that only opens the car and does not open the boot. With this standard, an application receives a limited, temporary key to carry out a specific task, and your main key, the password, always stays safely in your hands.

OAuth works like the limited key you hand to a valet. It lets an application carry out a specific task on your behalf without giving it the key to your whole house.

What is OAuth?

Before OAuth existed, many applications asked directly for the password of your account on another service. A tool that wanted to read your email to sort it asked for your username and password. It was a serious problem. The application had full access, could store the password and, if it was attacked, all its users were exposed. On top of that, the only way to revoke access was to change the password.

The OAuth standard was born precisely to solve this problem. Instead of the password, the application receives a limited permission, issued by the service itself, that is only valid for what the user has accepted and that can be revoked without touching the password. OAuth is not a program or a service, but a set of published rules that any company can apply, and today it is the foundation of almost every secure connection between applications.

The journey of an authorisation

It all starts when an application asks for access, for example with a button to sign in with an account from another service. The user is taken to the provider’s page, where they identify themselves and see a consent screen with the permissions requested. If they accept, the provider returns a temporary code to the application. The application exchanges it for an access pass and with it can request the authorised data. What matters is what does not happen. The application never gets to see the user’s password, and the pass can expire or be revoked without changing it. That is the big improvement over the old systems in which passwords were handed to every application, a practice that multiplied the risks.

OAuth and OpenID Connect

OAuth solves authorisation, in other words what an application can do with a user’s data. It does not on its own solve authentication, that is, who that person is. For that there is an additional layer called OpenID Connect, which lets an application know reliably who has signed in. When you click a button to sign in with another account, both are usually involved.

Difference between OAuth and OpenID Connect

The confusion between the two concepts has led to design flaws, such as applications that accept an identity without verifying it properly. If you commission or develop sign-in through third parties, it is worth checking that the right authentication standard is used and not just authorisation.

Differences from SAML and single sign-on

SAML is an older standard, whose version 2.0 dates from 2005, based on XML documents and very widespread in companies. Its goal is authentication, telling an application who the user is, while OAuth deals with authorisation. When an employee gets into several corporate applications with a single account, SAML is often behind it.

Single sign-on, or SSO, is not a protocol but the result. It can be built with SAML or with OpenID Connect on top of OAuth, and many organisations combine the two or gradually replace SAML with OpenID Connect, which does the same with lighter technologies and adapts better to mobile apps.

OAuth scopes, tokens and roles

The permissions granted

Every authorisation has a scope, a list of things the application can do. It might be reading your name and email, viewing your calendar or sending messages on your behalf. The broader the scope, the greater the risk. An application that only needs your name to identify you should not ask for access to all your emails or your files.

That is why it is important to read the permissions screen before accepting. It looks like a formality, but it is the only real barrier between a legitimate tool and a malicious one. If a recipe app asks for access to read and delete your email, something does not add up. Serious services show these permissions in plain words, and it is worth spending a few seconds understanding them.

The temporary pass

What the application receives is called a token. It is like a visitor’s pass with an expiry date. The standard calls it an access token, and it is usually a bearer token, which means that whoever holds it can use it. It often follows the JWT format, a small signed document that the server can verify without querying any database.

While it is valid, the application can do what is allowed without asking you for anything else. When it expires, it can renew it if the permission is still in force. To do that it uses a second pass, the refresh token, which lasts longer and is only used to request new passes. If you revoke it, the pass stops working instantly, even if the application still keeps it on its servers.

This pass is an extremely valuable prize for attackers. If someone manages to steal it, they can act as if they were the authorised application, without needing a password. That is why serious developers protect it very carefully and give it short lifetimes. In recent incidents at large companies, the theft of these passes has been one of the most widely used ways in.

Who grants and who requests

Three different parties take part in every OAuth authorisation. You, the owner of the data. The service where it is stored, such as your email provider. And the application that wants access. In the standard’s jargon, you are the resource owner, the application is the client and the service is split into two roles, the authorisation server, which hands out the passes, and the resource server, which holds the data. The service acts as a trusted intermediary. It verifies who you are, shows you what is being requested and, only if you give your consent, hands the pass to the requesting application. This division of roles means that your credentials never leave your provider. It is a valuable protection, but it depends on the intermediary showing clearly what is being granted. If the information is confusing or hidden, the user may accept without understanding. That is why large services have tightened their review of applications that want to integrate over the years.

Delegated authorisation on websites and online shops

Many websites offer sign-in with a Google, Apple or Facebook account. For visitors it is convenient, because they do not have to create another password. For the business, it reduces abandonment at registration and avoids storing passwords, which are a risk. Behind it is this standard, with an extra layer added that confirms the identity of whoever is signing in.

In content management systems and online shops, there are extensions that make it easy to sign in with external accounts, and others that connect the website to services such as email, calendars or payment platforms. Platforms such as Shopify or Magento use OAuth to authorise the third-party apps that access the shop. The WordPress core does not include OAuth and, since version 5.6, offers application passwords for its REST interface, a simpler system, while WordPress.com uses OAuth 2.0 to connect external applications. Every connection is an authorisation. It is worth knowing which ones your website has and with which permissions, because they are open doors to your data. A website with ten forgotten connections multiplies its weak points.

A good habit is to review connected applications from time to time, both on your personal accounts and on the company’s. Remove the ones you no longer use and be wary of any you do not remember authorising. It is free and quick maintenance, the equivalent of changing the locks when a key is lost. Many security incidents start with a permission granted years ago and forgotten.

OAuth grant types and versions

Authorisation code flow with PKCE

OAuth 2.0 supports different kinds of journey, called flows or grant types, depending on the case. The most common is the authorisation code flow, used by websites and applications with a server. The user approves access on the provider’s page, the application receives a one-time code and exchanges it for the token in a direct request between servers. The PKCE extension adds a temporary key known only to whoever started the process, and today it is recommended for every application, including mobile and desktop ones, where secrets cannot be stored safely.

How PKCE protects an app's sign-in

Client credentials flow

The client credentials flow is used for connections between servers, in which no person is involved and the application acts on its own behalf. It is the one used, for example, by an invoicing program that synchronises a shop’s orders every night through its API, with a token limited to that task.

Device flow

The OAuth device flow is designed for televisions, games consoles and other devices without a convenient keyboard. The device shows a short code and a web address, and the user approves it from their phone or computer, without ever typing the password on the television screen.

Outdated flows that are discouraged

Current OAuth recommendations clearly discourage two of the older journeys. The implicit flow returned the pass directly in the address, where it was easy to intercept. The password flow forced the application to collect the username and password, exactly what OAuth wanted to avoid. An application that still uses them deserves a review.

OAuth 1.0, OAuth 2.0 and OAuth 2.1

OAuth 1.0 required every request to carry a cryptographic signature calculated with a shared secret. It was secure even without encrypting the connection, but very hard to program, and any mistake in the signature made the request fail.

OAuth 2.0 simplified the model of the earlier version. It entrusted protection to the TLS encryption of connections, separated the roles of whoever issues the passes and whoever holds the data and added flows for mobile apps and devices. It is not compatible with the previous version, and its flexibility also brought more ways to misconfigure it.

The OAuth 2.1 draft brings together the good practices accumulated since 2012. It makes PKCE mandatory, removes the implicit and password flows and requires redirect addresses to match the registered ones exactly.

Risks and good practices of token-based authorisation

Security risks of OAuth

The most widespread risk of all is known as consent phishing. The attacker does not steal the password, but creates an application with a believable name and persuades the victim to grant it permissions on the service’s genuine page. Since the user approves of their own free will, two-step verification is of no use.

The second major OAuth risk is the theft of tokens. A stolen pass works without a password or a second factor until it expires or is revoked. In April 2022, attackers used stolen tokens that GitHub had issued to the Heroku and Travis CI platforms to download private repositories from dozens of organisations.

Implementation flaws complete the list of OAuth risks. A poorly validated redirect address lets the authorisation code be diverted to an attacker’s server, and the absence of the state parameter opens the door to CSRF attacks that link the victim’s account with the attacker’s.

How to control the permissions granted to applications

The first step in controlling OAuth is to look at the list of authorised applications. Large services, such as Google or Microsoft, have a security section that shows the applications with access to your account and what they can do. Go through it calmly. Ask yourself, for each one, whether you use it and whether it needs those permissions. If there is one you do not recognise, the most prudent thing is to remove it immediately and change your password.

The second step is caution when granting new permissions. Before accepting, read what is being requested and who is requesting it. Check that the names of the application and the company are the expected ones. Be wary of emails that arrive with urgency asking you to authorise something. Attackers know that haste reduces attention, and they use it to get you to accept without thinking.

The third piece of advice mainly concerns companies. Setting a simple policy on which applications can connect to corporate accounts, and who approves them, greatly reduces the risk. Administrators of large services can block broad permissions for unknown applications. It is a measure that costs no money and that would have stopped cases such as the 2017 worm.

Good implementation practices

For anyone developing an integration, the standard’s security recommendations boil down to a few ideas. Always use encrypted connections, apply PKCE even on websites with a server, include the state parameter and register exact redirect addresses, without wildcards. If you need to apply this in a project, an experienced web developer can help you get it right from the start.

Access tokens should be short-lived and stored where browser code cannot read them. Client secrets live on the server and never inside a mobile or desktop application, which anyone can take apart. And every integration should request the minimum scope it needs, because a permission that is never requested cannot be stolen.

A permissions worm disguised as a shared document

On 3 May 2017, millions of people received an email from a known contact saying they had shared a Google Docs document. Clicking the link opened a legitimate Google page asking for permission for an application called Google Docs to read, send and delete emails. Many people accepted, thinking it was a normal feature of the service.

The application was fake and controlled by the attackers. Once it received the permission, it accessed the victim’s contact list and sent the same email to all of them, so the scam spread on its own, like a worm. Google estimated that it affected fewer than 0.1 per cent of its Gmail users, who at the time numbered more than a billion, in other words around a million accounts.

The most unsettling part was that no passwords were stolen. The page was genuinely Google’s and the user granted the permission of their own free will. Experts spoke of an authorisation worm, not classic phishing. Google reacted within about an hour, removing the fake application and the accounts involved, and has since tightened its review of applications that request broad permissions.

The case teaches that distrusting fake pages is not enough. You also have to be wary of what you authorise on genuine pages. If an unexpected email leads you to grant permissions over your email or your files, it is worth stopping and checking with the person who supposedly sent it. A minute of doubt can stop your contacts from receiving a fraudulent message in your name.

How the OAuth standard was born

OAuth was born in November 2006, when Blaine Cook, then at Twitter, was working on a system to let other applications use the social network’s interface without asking for passwords. Together with Chris Messina, David Recordon and other developers, he found that there was no open standard for delegating that access, and in April 2007 they set up a working group to write one.

The first version, OAuth Core 1.0, was published in December 2007. In 2009 a session fixation flaw was discovered that forced the publication of revision 1.0a, and in 2010 the text became RFC 5849 of the IETF, the body that defines internet standards.

OAuth 2.0 was published in October 2012 as RFC 6749, accompanied by RFC 6750 on bearer tokens. The process was controversial, and its editor, Eran Hammer, left the group months earlier criticising the complexity of the result. Even so, the standard prevailed, OpenID Connect arrived in 2014 to handle identity and since 2020 work has been under way on OAuth 2.1 to simplify it.

Frequently asked questions

Frequently asked questions about OAuth

What is OAuth?

It is a standard that lets you give an application permission to access part of your data in another service, without handing over your password. It is what happens when you click a button to sign in with your Google account or when you allow a tool to read your calendar.

What does OAuth stand for?

It stands for Open Authorization. The key lies in the word authorisation. It is not used to prove who you are, but to decide what an application can do on your behalf and within which limits. It is a permission granted, not a master key.

Why is OAuth better than giving out your password?

Because the application never knows it. It receives a limited permission, for example to read your contacts, and not to delete your email. In addition, you can revoke it at any time without changing your password. If the application is attacked, the damage is limited to the permission granted.

What is a token in OAuth?

It is a kind of temporary pass that the service gives the application when you authorise it. With it, the application can only do what the permission allows. If someone steals that pass, they can use it until it expires or is revoked, so it must be stored very carefully.

Is OAuth the same as signing in with Google?

They are closely related. The button for signing in with an external account uses OAuth as its foundation and adds a layer to confirm identity. That is why they are sometimes confused. OAuth deals with what the application can do, and the identity layer deals with who you are.

What risks does OAuth have?

That an attacker tricks someone into authorising a malicious application. Since the permissions page is legitimate, the victim suspects nothing. In 2017 a worm took advantage of this with a fake application called Google Docs. It is wise to always read which permissions each application asks for.

How do I know which applications have access to my account through OAuth?

Large services have a security section that lists connected applications and the permissions granted. It is worth reviewing it from time to time and removing any you no longer use or do not recognise. It is one of the quickest and most useful checks for protecting your accounts.

Is OAuth used in content management systems and online shops?

Yes, in several ways. Many extensions for WordPress, Joomla, Drupal or PrestaShop let visitors sign in with their Google account or another platform, and others connect the website to external services through this standard. Shopify and Magento use it to authorise the third-party apps that connect to the shop.

I audit your website's OAuth integrations and the scopes they have been granted

I review scopes, redirect URLs and active tokens to minimise the impact of any compromised external integration.

About the author

Javier Afán

WordPress developer specialised in security, WooCommerce, and hacked website recovery.

I work on WordPress from a technical angle focused on security, architecture, and the decisions that really affect a project's continuity.