Skip to content

feat: support MOG_TENANT_ID env var for single-tenant Azure AD apps#14

Open
MrtyMfly-85 wants to merge 1 commit into
visionik:mainfrom
MrtyMfly-85:feat/tenant-id-support
Open

feat: support MOG_TENANT_ID env var for single-tenant Azure AD apps#14
MrtyMfly-85 wants to merge 1 commit into
visionik:mainfrom
MrtyMfly-85:feat/tenant-id-support

Conversation

@MrtyMfly-85

Copy link
Copy Markdown

Problem

mogcli hardcodes the /common/ OAuth2 endpoint, which doesn't work with single-tenant Azure AD app registrations. Single-tenant apps require the tenant-specific endpoint (/\{tenant-id\}/oauth2/v2.0), otherwise Azure returns:

AADSTS900144: The request body must contain the following parameter: 'device_code'

This affects any M365 Business user whose admin registers a single-tenant app (a common security practice).

Solution

Adds an initAuthURL() function that reads the MOG_TENANT_ID environment variable. If set, it constructs the tenant-specific OAuth endpoint. If not set, it falls back to /common/ — so existing behavior is completely unchanged.

Usage

# Single-tenant app (new)
export MOG_TENANT_ID=your-tenant-id
mog auth login --client-id your-client-id

# Multi-tenant / personal accounts (unchanged)
mog auth login --client-id your-client-id

Changes

  • internal/graph/client.go: Replace hardcoded AuthURL with initAuthURL() that reads MOG_TENANT_ID env var (11 lines changed)

Fully backward compatible. No new dependencies.

Adds initAuthURL() that reads MOG_TENANT_ID environment variable to
construct the OAuth2 endpoint URL. Falls back to /common/ when not set,
maintaining backward compatibility.

This enables mogcli to work with single-tenant Azure AD app registrations,
which require tenant-specific OAuth endpoints instead of the /common/
multi-tenant endpoint.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant