README Who Am I (Current User)

VBAuth — Who Am I #

Overview #

Calls the Microsoft Graph /me endpoint to retrieve the authenticated user’s profile details, including display name, job title, email address, phone numbers, office location, and account GUID.

This is the simplest possible VBAuth call: a single authenticated GET request with no URL parameters, no paging, and no complex response parsing. It is used in the VBAuth demo database as the connection test during the Setup Wizard, and serves as the reference example of the standard VBAuth call pattern.

Porting note: WhoAmI is a setup verification and demonstration function. In a production application you are unlikely to need the full profile block it returns. However, individual fields — particularly mail, displayName, and id — are useful in many real-world scenarios, and the call pattern demonstrated here is identical to any other VBAuth GET request.

Azure permission required: User.Read


VBAuth Admin Table Configuration #

Column NameRequired Value / ExampleNotes
AppID1Identifies this feature’s configuration record
ActionNameVBAuth – Who Am IDisplay name — any value acceptable
ClientID(your App Client ID)GUID from Azure App Registration Overview blade
TenantID(your Tenant ID)GUID from Azure App Registration Overview blade
ObjectID(your Object ID)Set by PopulateMissingObjectIDs
ScopeClaimsUser.ReadComma-separated Graph scopes
VerbGETHTTP method
URLPart1https://graph.microsoft.com/v1.0/meFull endpoint — no parameters required
URLParameter1NO VALUE REQUIREDNot used
URLPart2NO VALUE REQUIREDNot used
URLParameter2NO VALUE REQUIREDNot used
URLPart3NO VALUE REQUIREDNot used
WaitForLogin60Seconds — NB MSXML2 timeout parameters are in milliseconds

Azure setup reminder: After creating the App Registration, copy the App (Client) ID and Directory (Tenant) ID from the Overview blade before navigating away.


Azure App Registration #

Create a new App Registration in Azure Entra ID (portal.azure.com):

  1. Go to Microsoft Entra ID → App registrations → New registration
  2. Name: e.g. VBAuth - Who Am I
  3. Supported account types: Single tenant
  4. Redirect URI: Platform = Public client/native, URI = http://localhost
  5. Click Register
  6. Copy the Application (Client) ID and Directory (Tenant) ID from the Overview blade
  7. Go to API permissions → Add a permission → Microsoft Graph → Delegated permissions
  8. Add: User.Read
  9. Click Grant admin consent

How It Works #

WhoAmI follows the standard VBAuth call pattern:

  1. Sets intAppID = 1 and calls SetEntraAPPIdValues. Because this endpoint requires no URL
    parameters, both the strParam1 and strParam2 arguments to SetEntraAPPIdValues are passed as empty
    strings.
  2. Calls AcquireBearerToken to obtain a delegated OAuth2 token for the signed-in user.
  3. Sends a GET request to https://graph.microsoft.com/v1.0/me.
  4. On HTTP 200, parses the JSON response and assembles a formatted multi-line string containing
    the user’s key profile fields.
  5. Returns True and the formatted string via strResult. On failure, returns False and an
    error description.

Fields Returned #

The /me endpoint returns the full user profile. WhoAmI extracts and formats the following fields:

FieldGraph API property
First and last namegivenName, surname
Display namedisplayName
Job titlejobTitle
Primary emailmail
Business phone(s)businessPhones (array)
Mobile phonemobilePhone
Office locationofficeLocation
Preferred languagepreferredLanguage
User Principal NameuserPrincipalName
Account GUIDid

Fields that have no value in the user’s profile are returned as empty by the Graph API and will appear blank in the output. This is normal and not an error.


Module: modCurrentUser.bas #

Public functions #

Public Function WhoAmI(ByRef strResult As String) As Boolean
Code language: JavaScript (javascript)

Sets intAppID = 1, acquires a bearer token for User.Read, calls GET /me, and formats the response into a multi-line display string. Returns True on HTTP 200. Returns False on any other status or error, with strResult containing the error description. On success, strResult contains the formatted user profile.


Behaviour Notes #

  • The call is delegated — it returns the profile of whoever is currently signed in via VBAuth,
    not a fixed service account.
  • User.Read is the least privileged scope available and does not grant access to any other
    user’s data.
  • The id field (Account GUID) is a stable, tenant-scoped identifier for the user and is
    useful as a key in applications that store per-user data.
  • mail and userPrincipalName are usually the same address, but may differ in organisations
    that use separate UPNs and mailbox addresses.

Dependencies #

ModulePurpose
modVBAuthGlobalConstants.basGlobals, SetEntraAPPIdValues, AcquireBearerToken
JSONConverter.basTim Hall VBA-JSON — JSON parsing

Calling Example #

Dim strResult As String

If WhoAmI(strResult) Then
    MsgBox strResult, vbInformation, "Current User"
Else
    MsgBox "Could not retrieve user details." & vbCrLf & vbCrLf & strResult, _
           vbCritical, "Current User"
End If
Code language: PHP (php)

VBAuth, developed and maintained by Andrew Richards (The IT Service Ltd) and Peter Bryant (Corylus Business Systems), © 2025–2026. All rights reserved. https://vbauth.com

Updated on April 3, 2026