Security

OAuth: how to connect systems without sharing user passwords

Learn how OAuth works in API integrations, from consent with PKCE to managing scopes, tokens, and access revocation.

Matheus Alves

A company wants to connect its scheduling app to employees’ calendars. The integration needs to check availability and create confirmed meetings. Asking for each employee’s password would give the app access that is hard to limit. The same credential could allow other actions on the account, and the company would have another place to store and protect those passwords.

OAuth lets users grant an application access without sharing their password. Connecting a calendar still requires decisions about permissions, identity, token storage, and what happens when someone disconnects their account. We’ll follow the scheduling example through those decisions.

What is OAuth?

OAuth 2.0 defines how an application obtains limited access to a service on behalf of a user or on its own behalf. The application presents an access token to the service’s API, the interface through which systems exchange data and request operations. RFC 6749

In the calendar example, the scheduling system is the OAuth client. The authorization server issues tokens, and the calendar API handles requests to check availability or create meetings. One provider may operate both components, each with its own role.

The employee signs in with the calendar provider and approves the connection there. The scheduling app receives the authorization. The provider may also apply organizational policies or require an administrator’s approval.

Authorizing an integration and signing in

Calendar access and sign-in to the scheduling app serve different purposes. An access token issued for the calendar API belongs in requests to that API. To establish the user’s identity at sign-in, the app can use OpenID Connect, or OIDC, which adds an authentication layer to OAuth.

OIDC defines an ID token that conveys information about the authentication and the user to the client that requested sign-in. The client must verify the token’s authenticity, issuer, audience, and expiration. If the sign-in request included a nonce, the client must verify that value too. OpenID Connect Core

Element Role in the integration
Access token Authorizes calls to the API for which it was issued.
Refresh token Requests new access tokens when the provider allows it.
OIDC ID token Conveys authentication information to the client.
Application session Keeps the user signed in to the scheduling app according to its own rules.

The user’s local session can remain active after the app loses access to their calendar. Whether disconnecting the calendar also ends that session is a product decision.

How Authorization Code with PKCE works

Consider a web application with a server-side backend. The Authorization Code flow uses the browser to obtain approval. The backend then exchanges an authorization code for tokens.

PKCE, short for Proof Key for Code Exchange, ties the code exchange to a temporary secret generated at the start of the request. RFC 7636

  1. The employee signs in to the scheduling app and chooses to connect a calendar. The backend records a short-lived transaction tied to the session, the selected provider, and the local account.
  2. The app generates a temporary secret called the code_verifier. It keeps that value for the token exchange and sends the derived code_challenge in the authorization request using S256.
  3. The browser opens the provider’s authorization page with the app identifier, requested scopes, and registered redirect URL.
  4. The provider authenticates the employee, applies its policies, and sends a code back to the redirect URL if it grants access.
  5. The backend checks the transaction and exchanges the code for tokens, supplying the code_verifier and client authentication when required.
  6. The app calls the calendar API with the access token and operates within the permissions actually granted.

The token exchange requires the verifier even if the code is exposed. A compromised app can still use any tokens it can access.

Bind the callback to the session that started the connection. An unpredictable, single-use state value can identify the transaction. Check it before accepting the response and keep personal data and arbitrary URLs out of it. If the integration supports multiple calendar providers, verify which one returned the response before choosing the token endpoint. RFC 9700

Where credentials can live depends on the architecture

In the backend example, calendar tokens can stay on the server. The browser relies on the local session to request an operation. The backend checks whether the person can perform it before calling the API. Protect that session and prevent forged requests from performing actions on the employee’s behalf.

Browser-only and installed apps distribute their code to users’ devices. Credentials bundled with that code, including a client_secret, can be extracted. OAuth calls these apps public clients. A backend that can protect its credentials is an example of a confidential client.

Current OAuth security guidance requires PKCE for public clients and recommends it for confidential clients. It prohibits the grant that passes the user’s password to the app and advises against the implicit flow that returns tokens in the authorization response. Use maintained libraries and the provider’s documentation to implement and validate the chosen flow. RFC 9700

Match scopes to the work the integration does

A scope describes a requested permission. Checking availability and creating events may require different scopes. Their names and granularity depend on the provider.

If the app only needs to check availability, look for a permission limited to that operation before requesting access to calendar contents. If the app adds meeting creation later, explain why it needs write access and request it when the feature is enabled, if the provider supports incremental authorization.

Handle partial approvals. An employee might grant read access and decline event creation. Show which actions are available and offer a clear way to enable the remaining feature.

Every operation must also enforce the app’s own rules. Check the organization, the linked account, and the requester’s local permissions before using a calendar connection. Storing a token under the wrong organization can expose data across tenants even when the OAuth flow works correctly.

Protect tokens as credentials

Anyone holding a bearer token can use it within its permissions. Use HTTPS, keep tokens out of URLs, and prevent them from appearing in logs, analytics, error reports, or support tickets. RFC 6750

On the backend, restrict access to stored credentials, encrypt tokens at rest, and control access to the encryption keys separately. For troubleshooting, record the provider, linked account, scopes, and expiration while keeping token values out of those records.

If your team operates the API, validate tokens using the mechanism appropriate to their format. Opaque tokens are identifiers the application cannot interpret locally. A JWT carries structured data, and reading it only decodes that data. Verify its signature, allowed algorithms, issuer, audience, and expiration before accepting it. RFC 8725

Plan for renewal and disconnection

The provider sets the lifetime of the access token. A refresh token, when issued, lets the app renew access without repeating the approval flow. It can also expire, be revoked, or be replaced during renewal.

Consider two jobs refreshing the same connection at once. If the provider rotates refresh tokens, one job might reuse an old token or overwrite the new one. Coordinate refreshes so jobs use the current credential and preserve the latest result. If the provider indicates the grant is no longer valid, stop automatic retries and prompt the employee to reconnect.

On disconnect, block new API calls and suspend pending jobs for the connection. Request revocation while the credential is still available, then remove it from local storage. If revocation fails, keep the connection disabled and indicate that the user may still need to revoke access with the provider. The effect on other tokens and the time it takes to propagate depend on the provider. RFC 7009

Signing out ends the local session, deleting a token removes a local credential, and revocation changes what the provider accepts. Decide what to do with previously imported data. Imported events and meetings already created remain subject to their own retention and cancellation rules.

What to test before rollout

Use test accounts and cover failures that can affect scheduling.

Test case Expected behavior
User declines or cancels authorization Leave the calendar disconnected and allow another attempt.
Callback has no valid transaction or the wrong state Reject it without linking the account.
Read access is granted and write access is refused Offer only authorized operations.
A token expires during a job Coordinate renewal or ask the user to reconnect.
A user from another organization tries to use the connection Block the request before calling the API.
The provider revokes access while jobs are queued Suspend those jobs and communicate which operations are affected.
The API fails after a create request Check the outcome before retrying to avoid a duplicate meeting.

If the calendar API supports idempotency, follow its documentation to retry the same request without creating another meeting. Otherwise, decide how to verify whether the first request succeeded before submitting it again. Recovering from failures in system integrations

When to use OAuth and how to start

OAuth fits when the service supports it and the app needs permissions with a defined way to grant and end access. For the calendar integration, an employee can authorize the scheduling app and disconnect it later while keeping their password with the provider.

For work without a user, check which mechanism the provider supports. OAuth also defines the Client Credentials grant for an application acting on its own behalf. Give the workload permissions and approval appropriate to its role, so routine company operations can run independently of an employee’s personal account.

Start with one integration and list the actions it needs to perform. Identify the client type, available scopes, approval requirements, and who will operate it. Run a pilot with test accounts, minimal access, and failure logs that exclude credentials.

Test the full lifecycle from connecting and using the calendar through renewal, loss of permissions, and disconnection. Before expanding the rollout, make sure the team can explain who has access, how to end it, and how affected users learn about a failure.

How Fidalgo IT Solutions can help

Fidalgo IT Solutions can help design and implement OAuth and OpenID Connect integrations, covering authorization flows, account linking, credential storage, permissions, and failure handling.

Explore our APIs and integrations services or contact Fidalgo about the integration your team is building.