Add-in Expert logo
  • About
  • Portfolio
  • Blog
  • FAQs
Book a CallGet in Touch
Add-in Expert logo
  • About
  • Portfolio
  • Blog
  • FAQs
Book a CallGet in Touch
Add-in Expert logo
  • About
  • Portfolio
  • Blog
  • FAQs
Book a CallGet in Touch
  1. Home
  2. Blog
  3. Best Practices
  4. Integrating Azure OpenAI into Office Add-ins Securely
Best Practices

Integrating Azure OpenAI into Office Add-ins Securely

How to add Azure OpenAI to your Office Add-in the right way — a secure backend architecture, SSO, protected credentials, and data practices that keep enterprise reviewers happy.

SHBy Sajjad Hussain
|July 27, 2026|9 min read
Share:
Integrating Azure OpenAI into Office Add-ins Securely

Introduction

Adding AI to an Office Add-in — summarising a document, drafting a reply, extracting data — is one of the most requested features right now. For enterprise clients, Azure OpenAI is usually the model of choice, because it runs inside their own Azure tenant with the compliance guarantees their security team expects.

But wiring an AI model into an add-in the wrong way is a fast route to a leaked API key or a failed security review. This guide covers how to integrate Azure OpenAI into an Office Add-in the secure way — the architecture, authentication, credential handling, and data practices that hold up under scrutiny.

The principles here apply to any hosted AI model — OpenAI, Anthropic, or your own — but we use Azure OpenAI throughout because it’s what enterprise clients most often require.

Why Azure OpenAI?

Azure OpenAI gives you the same models as OpenAI, but delivered through Azure’s enterprise controls — which is exactly what wins over a cautious IT department.

  • It runs in your Azure tenant and chosen region, supporting data-residency requirements.
  • Microsoft does not use your prompts or completions to train the models.
  • It plugs into Entra ID, Private Link, and Azure’s compliance certifications.
  • You get content filtering, quotas, and monitoring out of the box.
This enterprise posture is the whole reason clients pick Azure OpenAI over a public API — so it’s worth integrating it in a way that preserves those guarantees rather than undermining them.

The Golden Rule

Here is the single most important rule, and the one most often broken: your Office Add-in must never call Azure OpenAI directly. An add-in is a web page — anyone can open the browser dev tools, read your JavaScript, and lift the endpoint and key straight out of it. From there they can run up your bill or exfiltrate data.

The key never touches the client

If your Azure OpenAI key or endpoint appears anywhere in the add-in’s code or network calls, it is compromised. All model calls must go through a backend you control.

The Secure Architecture

The pattern is a thin, authenticated proxy. The add-in sends the user’s request and an identity token to your backend; the backend verifies the token, adds the Azure OpenAI credentials it alone holds, calls the model, and streams the result back. The add-in never sees a secret.

  1. Task pane collects the prompt/context and the user’s SSO token.
  2. Your backend validates the token and applies per-user authorization and rate limits.
  3. Backend calls Azure OpenAI using a key from Key Vault, or (better) a Managed Identity.
  4. Backend returns the completion — streamed — to the add-in for display.

Authenticate with SSO

Your backend needs to know who is calling — otherwise it’s an open AI proxy. Office Single Sign-On issues a token for the signed-in Microsoft 365 user without a separate login prompt. Send it with every request, and validate it on the server before doing anything.

taskpane.js
async function askAI(prompt) {
  const token = await Office.auth.getAccessToken({ allowSignInPrompt: true });

  const res = await fetch('https://your-backend.com/ai/complete', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${token}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ prompt }),
  });
  return res.json();
}

Validate on the server

Always verify the SSO token on your backend — check its signature, audience, and expiry — before calling Azure OpenAI. Never trust a token just because it arrived.

Protect Your Credentials

On the backend, keep the Azure OpenAI key out of source control — load it from Azure Key Vault or a secret store. Even better, skip the key entirely and authenticate with a Managed Identity via Entra ID, so there’s no long-lived secret to leak at all.

server.js (backend)
// Key lives in Key Vault / env — never in the add-in.
const endpoint = process.env.AZURE_OPENAI_ENDPOINT;
const apiKey = process.env.AZURE_OPENAI_KEY;

async function complete(prompt) {
  const res = await fetch(
    `${endpoint}/openai/deployments/gpt-4o/chat/completions?api-version=2024-06-01`,
    {
      method: 'POST',
      headers: { 'api-key': apiKey, 'Content-Type': 'application/json' },
      body: JSON.stringify({
        messages: [{ role: 'user', content: prompt }],
        max_tokens: 800,
      }),
    }
  );
  return res.json();
}

Prefer Managed Identity over keys

A Managed Identity with the Cognitive Services OpenAI User role removes the API key from the equation entirely — nothing to rotate, nothing to steal. Use it wherever your backend runs on Azure.

Send Only What You Need

Just because you can send the whole document to the model doesn’t mean you should. Send the smallest slice of content the task actually needs, and give users control over the most sensitive material.

  • Send only the selected text or relevant section, not the entire file, when that’s enough.
  • Offer a redaction step for regulated data, and make it easy to review before sending.
  • Log requests for audit, but avoid storing prompt content unless you truly need to.
  • Lean on Azure OpenAI’s content filtering, and handle blocked responses gracefully.

Responses & Streaming

AI responses can take several seconds, and a frozen task pane feels broken. Stream the completion so text appears token by token — the same effect you see in ChatGPT. Your backend proxies Azure OpenAI’s streaming response straight through to the add-in.

Stream, and always handle failure

Set stream: true on the Azure OpenAI call and forward the chunks to the client. Wrap everything in retry and timeout handling too — rate limits and transient errors are normal, so show a graceful message rather than a spinner that never ends.

Security Checklist

  • All Azure OpenAI calls go through your backend — never the add-in.
  • Credentials live in Key Vault or, better, a Managed Identity — never in client code.
  • Every request carries a validated SSO token; the backend enforces authorization.
  • Per-user rate limiting and quotas protect against abuse and runaway cost.
  • Only the minimum necessary content is sent, with redaction for sensitive data.
  • HTTPS everywhere, content filtering on, and audit logging in place.

Conclusion

Done well, Azure OpenAI turns your Office Add-in into a genuinely intelligent assistant without ever compromising security: a backend that owns the credentials, SSO that proves who’s calling, least-privilege data handling, and Azure’s own compliance posture behind it. Get the architecture right first, and the AI features become the easy part. If you’d like a secure, production-ready AI add-in built and reviewed for your organisation, we’d be glad to help.

#Azure OpenAI#AI#Office Add-ins#Security#Office.js#Best Practices
Next Integrate Zoho CRM with Outlook: A Custom Add-in for Contacts, Deals & Email Sync

Related Articles

Security Best Practices for Office Add-ins DevelopmentBest PracticesSecurity Best Practices for Office Add-ins DevelopmentFebruary 10, 2025 · 6 min readOffice.js Add-ins vs VSTO Add-ins: Which Should You Choose?Best PracticesOffice.js Add-ins vs VSTO Add-ins: Which Should You Choose?May 22, 2025 · 9 min readCentralized Deployment of Office Add-ins: A Complete GuideBest PracticesCentralized Deployment of Office Add-ins: A Complete GuideFebruary 9, 2026 · 6 min read

Table of Contents

  1. 1.Why Azure OpenAI?
  2. 2.The Golden Rule
  3. 3.The Secure Architecture
  4. 4.Authenticate with SSO
  5. 5.Protect Your Credentials
  6. 6.Send Only What You Need
  7. 7.Responses & Streaming
  8. 8.Security Checklist
  9. 9.Conclusion

Need Help Building Custom Office Add-ins?

We build secure, scalable, and user-friendly Office solutions that drive real business impact.

Contact Our Experts

Categories

  • Excel Add-ins3
  • Outlook Add-ins4
  • Word Add-ins2
  • PowerPoint Add-ins1
  • Google Workspace5
  • Best Practices6
View all categories

Popular Posts

  • How to Build an Excel Add-in That Stands OutHow to Build an Excel Add-in That Stands OutApr 10, 2024
  • Top 10 Outlook Add-ins Use Cases for BusinessesTop 10 Outlook Add-ins Use Cases for BusinessesMar 28, 2024
  • Google Workspace Add-ons vs Macros: What to Choose?Google Workspace Add-ons vs Macros: What to Choose?Mar 15, 2024
View all posts

Stay Updated

Subscribe to get the latest tutorials, insights, and product updates.

No spam. Unsubscribe anytime.

Add-in Expert logo
Addin Expert specializes in developing custom Office add-ins and Google add-ons, empowering businesses to enhance productivity and streamline workflows with tailored, innovative solutions

Office 365 Add-ins

  • Outlook add-ins
  • Word add-ins
  • Excel add-ins
  • Powerpoint add-ins

Google addons

  • Gmail Addon
  • Google Docs Addon
  • Google Sheets Addon
  • Google forms Addon

More Services

  • VSTO Add-ins
  • VSTO Migration
  • Cross-Platform
  • Deployment

Company

  • About Us
  • Portfolio
  • Blog
  • Privacy Policy
Copyright © 2026. All rights reserved by Addin Expert.