---
id: change/bcapps/10481
type: change
title: "#10481 [Bug Fix] #251: Handle GetUserName TryFunction failure during OAuth validation"
summary: Fixed OAuth2 SMTP authentication to properly handle token parsing failures by consuming the TryFunction return value, preventing raw errors from being shown to users instead of the authentication-failed message.
tier: official
language: en
tags:
  - fix
  - main
  - bc30
  - codeunit oauth2 smtp authentication
system: platform
review:
  state: reviewed
  by: opus
  at: "2026-10-16T01:17:19.363Z"
  flags: []
generated:
  at: "2026-11-16T00:19:27.268Z"
  pipeline: 0.2.0
  prompts:
    extract-change: 1
  input_hash: 22c2b4f2e0dede1ad0adfd40c2e8ecf0bb8f9421
evidence:
  - kind: code
    url: https://github.com/microsoft/BCApps/pull/10481
    title: "microsoft/BCApps#10481: [Bug Fix] #251: Handle GetUserName TryFunction failure during OAuth validation"
    date: "2026-10-14"
    commit: 22c2b4f2e0dede1ad0adfd40c2e8ecf0bb8f9421
    t: null
    quote: null
links:
  learn: []
  objects:
    - object/codeunit/4516
  features: []
  topics: []
  localizations: []
  videos: []
  posts: []
  guidelines: []
  changes: []
  related:
    - to: https://learn.microsoft.com/dynamics365/business-central/dev-itpro/developer/devenv-handling-errors-using-try-methods
      title: Handling errors using try methods
      label: possibly related
      why: Documents try methods and error handling during code execution, core to handling GetUserName TryFunction failure.
      by: model
number: 10481
repo: microsoft/BCApps
source_id: bcapps-prs
url: https://github.com/microsoft/BCApps/pull/10481
kind: pr
base_branch: main
major: "30"
merged_at: "2026-10-14T09:38:51Z"
author: ventselartur
author_type: User
community_contribution: false
labels:
  - "AL: Apps (W1)"
  - "Team: Integrations"
change_class: code
change_kind: fix
behavior_change: true
breaking: false
files:
  count: 2
  additions: 37
  deletions: 3
  al: 1
apps:
  - Email - SMTP Connector
objects_touched:
  - key: codeunit/4516
    page: codeunit/4516
    type: codeunit
    id: 4516
    name: OAuth2 SMTP Authentication
    app: Email - SMTP Connector
    status: modified
objects_unjoined: []
obsoletions: []
backports: []
fixes_issues: []
work_items:
  - 646834
systems:
  - platform
quote: null
joined_against:
  major: "30"
  commit: f18567dc08e2bd162bf192e1da4d714b57eb099f
---

# #10481 [Bug Fix] #251: Handle GetUserName TryFunction failure during OAuth validation

> Fixed OAuth2 SMTP authentication to properly handle token parsing failures by consuming the TryFunction return value, preventing raw errors from being shown to users instead of the authentication-failed message.

[Pull request](https://github.com/microsoft/BCApps/pull/10481) · merged into `main` (BC30) on 2026-10-14 by ventselartur · 2 files (+37 -3), 1 AL · fix · tier official · reviewed (checked by Opus)

## What changed

- CheckOAuth2Authentication now uses the GetUserName TryFunction result and shows AuthenticationFailedMsg when token parsing fails
- GetOAuth2Credentials now raises CouldNotAuthenticateErr when parsing fails, instead of continuing with an empty user name
- Raw runtime parse errors are no longer shown to users
- Adds a regression test for an unparseable token in SMTP Account Auth Tests
- Behaviour changes for users or extensions.

## AL objects touched

- [Codeunit 4516 "OAuth2 SMTP Authentication"](../../objects/codeunit/4516.md), Email - SMTP Connector: modified

## Context

- Work items: AB#646834
- Labels: AL: Apps (W1), Team: Integrations
- Systems: platform

## Possibly related

No source states these links: they share an object, a model read them, or a person found the same subject.

- [Handling errors using try methods](https://learn.microsoft.com/dynamics365/business-central/dev-itpro/developer/devenv-handling-errors-using-try-methods) — possibly related: Documents try methods and error handling during code execution, core to handling GetUserName TryFunction failure. (model-linked)

Source: metadata of a merged pull request in microsoft/BCApps (bcapps): title, labels, changed paths and counts, with a summary in our words. No source text and no description beyond one short quote (D10, D61).
