Dev.to Security ๐Ÿ” Cybersecurity ๐Ÿ‘ 2 ๐Ÿ“– 3 min read

Letting AI agents act on a customer's own accounts, safely: remote OAuth credential linking

At Studio98 we build a multi-tenant platform of "AI employees": named agents that work across web chat, SMS, voice and email for businesses. Our team built the agent engine, the tenant-isolated knowledge search and the i

At Studio98 we build a multi-tenant platform of "AI employees": named agents that work across web chat, SMS, voice and email for businesses. Our team built the agent engine, the tenant-isolated knowledge search and the integrations together.

An agent that can only talk isn't very useful. To actually do the work, an agent has to act inside the customer's own tools: read and send email from their mailbox, check their calendar, look things up in their CRM. That means using the customer's own credentials, safely.

My part of the platform was the layer that makes this possible: remote credential linking, identity labels, and a Microsoft 365 / Outlook tool. Here's how it works and why each piece exists.

The problem: the person setting up the agent isn't the account owner

In practice, an agency's staff configure the agent, but the mailbox belongs to the business owner. You can't ask the owner for their password, and you don't want staff logging in as them.

The answer is OAuth, but with a twist: staff start the connection, the owner finishes it.

The flow

  1. Staff request a connection for a specific agent and provider, for example "connect Microsoft 365 for the Sales agent".
  2. The account owner gets a tokenised link for that one connection.
  3. The owner opens the link and completes the normal OAuth consent screen with their own account.
  4. The callback attaches the resulting credential to the right agent in the right tenant.

No passwords are shared, the owner sees exactly what access they're granting, and they can revoke it from their provider at any time.

The checks that make it safe

The happy path is the easy part. These are the checks that matter:

  • Token validation. The link token is checked against the connection request it was created for, so a credential can only ever be attached to the agent and tenant that asked for it.
  • Origin checks on the callback, so the OAuth result is only accepted from the expected flow.
  • A database lock against duplicates. Owners double-click, browsers retry, providers call back twice. A lock around the attach step means you get exactly one credential, not two half-configured ones.

Showing who the agent is acting as

Once agents hold real credentials, staff need to know exactly which account an agent is using. "Connected to Microsoft" isn't enough when a business has five mailboxes.

I added credential identity labels across the UI: wherever a credential appears, it shows the actual mailbox or account identity. It's a small feature that prevents a very real mistake: an agent emailing customers from the wrong address.

The Outlook tool

With credentials in place, I built a Microsoft OAuth provider and an Outlook email tool on Microsoft Graph, so agents can read and send mail from the connected mailbox. Because the tool always goes through the linked credential, its permissions are exactly what the owner approved, and nothing more.

Lessons for anyone building agent tools

  • Separate who configures the agent from who owns the account, and design the OAuth flow around that.
  • Treat link tokens like keys: scoped to one request and validated on every callback.
  • Assume callbacks will arrive twice, and lock accordingly.
  • Always show which identity an agent is using. Silent identity is how agents send the wrong email.

I'm Rizwan Ali, a SaaS & AI agent developer at Studio98, working with Laravel, React and AI integrations. I build agent tools and integrations that act safely inside real business systems. Find me on LinkedIn or GitHub.

๐Ÿ“ฐ Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes โ€” full credit and traffic to the original publisher.