---
id: object/codeunit/4507
type: object
title: Codeunit 4507 "Email - OAuth Client"
summary: Codeunit 4507 "Email - OAuth Client" in Email - Outlook REST API (System.Email). 5 public procedures, 1 events. Introduced in BC29, still in BC30, changed in BC30.
tier: official
language: en
tags:
  - codeunit
  - email - outlook rest api
versions:
  introduced: "29"
  last_changed: "30"
  deprecated: null
review:
  state: derived
  by: null
  at: null
  flags: []
generated:
  at: "2026-10-11T00:31:51.816Z"
  pipeline: 0.2.0
  prompts: {}
  input_hash: 087e43f5a383e7e8741ff423708dee94a35832386b21c17a7587e89095e25393
evidence:
  - kind: code
    url: https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/Apps/W1/Email%20-%20Outlook%20REST%20API/app/src/EmailOAuthClient.Codeunit.al
    title: src/Apps/W1/Email - Outlook REST API/app/src/EmailOAuthClient.Codeunit.al (releases/29.x)
    date: null
    commit: ea08af5ef2d6a9b5c5af4a029288abbe2c883220
    t: null
    quote: null
links:
  learn: []
  objects: []
  features: []
  topics: []
  localizations: []
  videos: []
  posts: []
  guidelines: []
  changes:
    - change/bcapps/11016
object_type: codeunit
object_id: 4507
name: Email - OAuth Client
namespace: System.Email
app: Email - Outlook REST API
extends: null
first_version: "29"
last_version: "30"
present_in:
  - "29"
  - "30"
changed_in:
  - "30"
source_major: "29"
obsolete: null
countries: []
ms_search_form_ids: []
counts:
  fields: 0
  procedures: 10
  events: 1
  subscribers: 0
relations:
  out: 0
  referenced_by: 0
  pages: 0
  extended_by: 0
  event_subscribers: 0
  calls: 5
  called_by: 1
  implements: 1
---

# Codeunit 4507 "Email - OAuth Client"

> Codeunit 4507 "Email - OAuth Client" in Email - Outlook REST API (System.Email). 5 public procedures, 1 events. Introduced in BC29, still in BC30, changed in BC30.

Email - Outlook REST API · System.Email · BC29-30 · [source at ea08af5e](https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/Apps/W1/Email%20-%20Outlook%20REST%20API/app/src/EmailOAuthClient.Codeunit.al) · facts from BC29

## Events published

- `OnBeforeGetToken(var IsHandled: Boolean)` (internal)

## Procedures

- `GetAccessToken(var AccessToken: SecretText)`
- `TryGetAccessToken(var AccessToken: SecretText): Boolean`
- `GetLastAuthorizationErrorMessage(): Text` (internal)
- `AuthorizationCodeTokenCacheExists(): Boolean` (internal)
- `SignInUsingAuthorizationCode(): Boolean` (internal)

Plus 4 local procedures.

## Calls

From the extracted call graph of BC29 (graphify-al on the snapshot checkout): calls whose target is known from a declared type or an `Object::"Name"` argument. Interface dispatch and calls through events are not counted, so the list is not complete.

- [Codeunit 501 "OAuth2"](../codeunit/501.md) (7 calls: `AuthorizationCodeTokenCacheExists → AcquireAuthorizationCodeTokenFromCache`, `GetLastAuthorizationErrorMessage → GetLastErrorMessage`, `Initialize → GetDefaultRedirectURL`, …)
- [Codeunit 457 "Environment Information"](../codeunit/457.md) (3 calls: `CheckIfThirdParty → IsSaaSInfrastructure`, `Initialize → IsSaaSInfrastructure`, `TryGetAccessTokenInternal → IsSaaSInfrastructure`)
- [Codeunit 4509 "Email - Outlook API Helper"](../codeunit/4509.md) (2 calls: `Initialize → GetClientIDAndSecret`, `Initialize → GetRedirectURL`)
- [Codeunit 6300 "Azure AD Mgt."](../codeunit/6300.md) (2 calls: `TryGetAccessTokenInternal → GetAccessTokenAsSecretText`, `TryGetAccessTokenInternal → GetLastErrorMessage`)
- [Codeunit 9005 "Url Helper"](../codeunit/9005.md) (2 calls: `GetOAuthAuthorityUrl → GetAzureADAuthEndpoint`, `TryGetAccessTokenInternal → GetGraphUrl`)

## Called by

- [Page 4509 "Email - Outlook API Setup"](../page/4509.md) (3 calls: `OnOpenPage → AuthorizationCodeTokenCacheExists`, `TestSetup → GetLastAuthorizationErrorMessage`, `TestSetup → TryGetAccessToken`)

## Implements

- [Interface "Email - OAuth Client v2"](../interface/email-oauth-client-v2.md)

## Recent changes

- 2026-09-10 [#11016 [AI Business Solutions] Enforce allow-listed Redirect URIs, token audiences and authorities for OAuth2 integrations](../../changes/bcapps/11016.md) (main, BC30, fix)

## Across versions

- Present in: BC29-30
- Changed (declaration) in: BC30

Source: AL metadata extracted from the code (names, ids, signatures, properties); no code bodies (D10).

## Ask your agent

Procedure bodies are not stored here (D10). The call sections above are our own, per object, from the BC29 call graph. For a procedure body or the calls of one procedure, ask bc-code-atlas (external, by Stefan Maron, MIT; default corpus w1-28), which the bc-observatory plugin connects: `bcatlas_resolve_node(object_type: "codeunit", object_name: "Email - OAuth Client")`, then `bcatlas_get_procedure_body` or `bcatlas_get_neighbors` on the returned id.
